From 89649edbad4d1ccebb4b93c78acaa99af4722aab Mon Sep 17 00:00:00 2001 From: li-tiangang4 Date: Tue, 27 May 2025 15:05:11 +0800 Subject: [PATCH] =?UTF-8?q?ram=20=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: li-tiangang4 --- common/utils/include/constants.h | 30 +-- .../include/distributed_hardware_errno.h | 14 +- .../inner_kits/src/ipc/dhfwk_sa_manager.cpp | 5 +- .../src/ipc/publisher_listener_stub.cpp | 2 + .../componentloader/component_loader.h | 4 +- .../componentmanager/component_manager.h | 9 +- .../componentmanager/component_privacy.h | 7 +- .../include/resourcemanager/db_adapter.h | 4 +- .../include/transport/dh_comm_tool.h | 7 +- .../include/versionmanager/version_manager.h | 3 +- .../src/componentloader/component_loader.cpp | 97 ++++----- .../componentmanager/component_manager.cpp | 198 +++++++++++------- .../componentmanager/component_monitor.cpp | 4 +- .../componentmanager/component_privacy.cpp | 22 +- .../local_hardware_manager.cpp | 3 +- .../src/lowlatency/low_latency.cpp | 5 +- .../src/lowlatency/low_latency_timer.cpp | 6 +- .../capability_info_manager.cpp | 3 +- .../src/resourcemanager/db_adapter.cpp | 27 ++- .../local_capability_info_manager.cpp | 4 +- .../src/resourcemanager/meta_info_manager.cpp | 4 +- .../resourcemanager/version_info_manager.cpp | 4 +- .../src/task/enable_task.cpp | 15 +- .../src/task/online_task.cpp | 2 +- .../src/task/task.cpp | 2 +- .../src/transport/dh_comm_tool.cpp | 5 + .../src/transport/dh_transport.cpp | 5 +- .../src/utils/dh_timer.cpp | 3 +- .../src/versionmanager/version_manager.cpp | 3 + .../src/component_loader_test.cpp | 48 ++--- .../include/mock_component_loader.h | 4 +- .../src/component_manager_test.cpp | 43 ++-- .../src/component_manager_test_ext.cpp | 50 ++--- .../src/mock_component_loader.cpp | 4 +- .../component_privacy_test.cpp | 26 ++- .../common/dbadapter/src/db_adapter_test.cpp | 3 +- .../task/include/mock_component_manager.h | 2 + .../common/task/src/enable_task_test.cpp | 7 +- .../task/src/mock_component_manager.cpp | 5 + .../common/transport/dh_comm_tool_test.cpp | 4 + .../include/version_info_manager_test.h | 4 +- .../src/version_info_manager_test.cpp | 9 +- .../src/version_manager_test.cpp | 1 + utils/src/device_param_mgr.cpp | 4 +- utils/src/dh_utils_tool.cpp | 11 +- utils/src/histreamer_ability_parser.cpp | 88 ++++---- utils/src/histreamer_query_tool.cpp | 29 ++- 47 files changed, 453 insertions(+), 386 deletions(-) diff --git a/common/utils/include/constants.h b/common/utils/include/constants.h index a0fd24b8..f70890c8 100644 --- a/common/utils/include/constants.h +++ b/common/utils/include/constants.h @@ -21,38 +21,18 @@ namespace OHOS { namespace DistributedHardware { - constexpr int32_t LOG_MAX_LEN = 4096; - constexpr uint32_t MAX_MESSAGE_LEN = 40 * 1024 * 1024; - constexpr uint32_t MIN_MESSAGE_LEN = 0; - constexpr uint32_t MAX_ID_LEN = 256; - constexpr uint32_t MAX_TOPIC_SIZE = 128; - constexpr uint32_t MAX_LISTENER_SIZE = 256; - constexpr uint32_t MAX_COMP_SIZE = 128; - constexpr uint32_t MAX_ARR_SIZE = 10000; constexpr uint32_t MAX_DB_RECORD_SIZE = 10000; constexpr uint32_t MAX_ONLINE_DEVICE_SIZE = 10000; - constexpr int32_t MODE_ENABLE = 0; - constexpr int32_t MODE_DISABLE = 1; - constexpr uint32_t MAX_SWITCH_SIZE = 256; - constexpr uint32_t MAX_ROUND_SIZE = 1000; - constexpr uint32_t MAX_JSON_SIZE = 40 * 1024 * 1024; - constexpr uint32_t MAX_HASH_SIZE = 64; - constexpr uint32_t MAX_KEY_SIZE = 256; constexpr uint32_t MAX_DH_DESCRIPTOR_ARRAY_SIZE = 4096; - const uint32_t EVENT_VERSION_INFO_DB_RECOVER = 101; - const uint32_t EVENT_CAPABILITY_INFO_DB_RECOVER = 201; - const uint32_t EVENT_DATA_SYNC_MANUAL = 301; - const uint32_t EVENT_META_INFO_DB_RECOVER = 401; + constexpr uint32_t EVENT_VERSION_INFO_DB_RECOVER = 101; + constexpr uint32_t EVENT_CAPABILITY_INFO_DB_RECOVER = 201; + constexpr uint32_t EVENT_DATA_SYNC_MANUAL = 301; + constexpr uint32_t EVENT_META_INFO_DB_RECOVER = 401; - const std::string LOW_LATENCY_KEY = "identity"; - const std::string APP_ID = "dtbhardware_manager_service"; - const std::string GLOBAL_CAPABILITY_ID = "global_capability_info"; - const std::string GLOBAL_VERSION_ID = "global_version_info"; - const std::string LOCAL_CAPABILITY_ID = "local_capability_info"; - const std::string GLOBAL_META_INFO = "global_meta_info"; const std::string RESOURCE_SEPARATOR = "###"; const std::string DH_FWK_PKG_NAME = "ohos.dhardware"; + constexpr const char *APP_ID = "dtbhardware_manager_service"; constexpr const char *DH_ID = "dh_id"; constexpr const char *DEV_ID = "dev_id"; constexpr const char *DEV_NAME = "dev_name"; diff --git a/common/utils/include/distributed_hardware_errno.h b/common/utils/include/distributed_hardware_errno.h index 530bb79b..c3c8d475 100644 --- a/common/utils/include/distributed_hardware_errno.h +++ b/common/utils/include/distributed_hardware_errno.h @@ -26,8 +26,6 @@ namespace DistributedHardware { */ constexpr int32_t DH_FWK_SUCCESS = 0; constexpr int32_t ERR_DH_FWK_PARA_INVALID = -10000; - constexpr int32_t ERR_DH_FWK_REMOTE_NETWORK_ID_IS_EMPTY = -10001; - constexpr int32_t ERR_DH_FWK_REMOTE_DEVICE_ID_IS_EMPTY = -10002; constexpr int32_t ERR_DH_FWK_TYPE_NOT_EXIST = -10003; constexpr int32_t ERR_DH_FWK_JSON_PARSE_FAILED = -10004; constexpr int32_t ERR_DH_FWK_POINTER_IS_NULL = -10005; @@ -43,15 +41,15 @@ namespace DistributedHardware { constexpr int32_t ERR_DH_FWK_COMPONENT_DISABLE_TIMEOUT = -10305; constexpr int32_t ERR_DH_FWK_COMPONENT_REGISTER_FAILED = -10306; constexpr int32_t ERR_DH_FWK_COMPONENT_UNREGISTER_FAILED = -10007; - constexpr int32_t ERR_DH_FWK_COMPONENT_GET_REMOTE_SA_FAILED = -10008; constexpr int32_t ERR_DH_FWK_COMPONENT_GET_SINK_VERSION_FAILED = -10009; constexpr int32_t ERR_DH_FWK_COMPONENT_DHTYPE_NOT_FOUND = -10010; constexpr int32_t ERR_DH_FWK_COMPONENT_MONITOR_NULL = -10011; constexpr int32_t ERR_DH_FWK_COMPONENT_TRANSPORT_OPT_FAILED = -10012; constexpr int32_t ERR_DH_FWK_COMPONENT_GET_ENABLE_PARAM_FAILED = -10013; - constexpr int32_t ERR_DH_FWK_COMPONENT_LIMIT_DEMAND_START = -10014; + constexpr int32_t ERR_DH_FWK_COMPONENT_NO_NEED_ENABLE = -10014; constexpr int32_t ERR_DH_FWK_COMPONENT_REPEAT_CALL = -10015; constexpr int32_t ERR_DH_FWK_COMPONENT_COMPVERSION_NOT_FOUND = -10016; + constexpr int32_t ERR_DH_FWK_SA_HANDLER_IS_NULL = -10017; /* ResourceManager errno, range: [-10400, -10499] */ constexpr int32_t ERR_DH_FWK_RESOURCE_DB_ADAPTER_POINTER_NULL = -10400; @@ -59,16 +57,12 @@ namespace DistributedHardware { constexpr int32_t ERR_DH_FWK_RESOURCE_DB_ADAPTER_OPERATION_FAIL = -10402; constexpr int32_t ERR_DH_FWK_RESOURCE_KV_STORAGE_OPERATION_FAIL = -10403; constexpr int32_t ERR_DH_FWK_RESOURCE_CAPABILITY_MAP_NOT_FOUND = -10404; - constexpr int32_t ERR_DH_FWK_RESOURCE_DB_MANUAL_SYNC_FAIL = -10405; constexpr int32_t ERR_DH_FWK_RESOURCE_INIT_DB_FAILED = -10406; constexpr int32_t ERR_DH_FWK_RESOURCE_UNINIT_DB_FAILED = -10407; constexpr int32_t ERR_DH_FWK_RESOURCE_REGISTER_DB_FAILED = -10408; constexpr int32_t ERR_DH_FWK_RESOURCE_UNREGISTER_DB_FAILED = -10409; constexpr int32_t ERR_DH_FWK_RESOURCE_KEY_IS_EMPTY = -10410; - constexpr int32_t ERR_DH_FWK_RESOURCE_SYNC_VERSIONINFO_FAIL = -10411; - constexpr int32_t ERR_DH_FWK_RESOURCE_DEVICE_ID_NOT_EXIST = -10412; constexpr int32_t ERR_DH_FWK_RESOURCE_UUID_NOT_FOUND = -10413; - constexpr int32_t ERR_DH_FWK_RESOURCE_CAPINFO_POINTER_NULL = -10414; constexpr int32_t ERR_DH_FWK_RESOURCE_RES_DB_DATA_INVALID = -10415; /* DistributedHardwareManager errno, range: [-10500, -10599] */ @@ -93,11 +87,7 @@ namespace DistributedHardware { constexpr int32_t ERR_DH_FWK_TASK_TIMEOUT = -10700; /* DistributedHardwareService errno, range: [-10800, -10899] */ - constexpr int32_t ERR_DH_FWK_SERVICE_IPC_WRITE_PARA_FAIL = -10800; constexpr int32_t ERR_DH_FWK_SERVICE_IPC_SEND_REQUEST_FAIL = -10801; - constexpr int32_t ERR_DH_FWK_SERVICE_IPC_READ_PARA_FAIL = -10802; - constexpr int32_t ERR_DH_FWK_SERVICE_STRING_IS_EMPTY = -10803; - constexpr int32_t ERR_DH_FWK_SERVICE_LOCAL_VERSION_NOT_EXIST = -10804; constexpr int32_t ERR_DH_FWK_SERVICE_WRITE_TOKEN_FAIL = -10805; constexpr int32_t ERR_DH_FWK_SERVICE_REMOTE_IS_NULL = -10806; constexpr int32_t ERR_DH_FWK_SERVICE_WRITE_INFO_FAIL = -10807; diff --git a/interfaces/inner_kits/src/ipc/dhfwk_sa_manager.cpp b/interfaces/inner_kits/src/ipc/dhfwk_sa_manager.cpp index 29c30e52..d8077a9f 100644 --- a/interfaces/inner_kits/src/ipc/dhfwk_sa_manager.cpp +++ b/interfaces/inner_kits/src/ipc/dhfwk_sa_manager.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 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 @@ -27,6 +27,9 @@ namespace OHOS { namespace DistributedHardware { +constexpr uint32_t MAX_TOPIC_SIZE = 128; +constexpr uint32_t MAX_LISTENER_SIZE = 256; + IMPLEMENT_SINGLE_INSTANCE(DHFWKSAManager); DHFWKSAManager::DHFWKSAManager() : dhfwkOnLine_(false), isSubscribeDHFWKSAChangeListener_(false), dhfwkProxy_(nullptr), diff --git a/interfaces/inner_kits/src/ipc/publisher_listener_stub.cpp b/interfaces/inner_kits/src/ipc/publisher_listener_stub.cpp index e56e56f7..eddcec6e 100644 --- a/interfaces/inner_kits/src/ipc/publisher_listener_stub.cpp +++ b/interfaces/inner_kits/src/ipc/publisher_listener_stub.cpp @@ -21,6 +21,8 @@ namespace OHOS { namespace DistributedHardware { +constexpr uint32_t MAX_MESSAGE_LEN = 40 * 1024 * 1024; + PublisherListenerStub::PublisherListenerStub() { } diff --git a/services/distributedhardwarefwkservice/include/componentloader/component_loader.h b/services/distributedhardwarefwkservice/include/componentloader/component_loader.h index ff3efe86..28f7336f 100644 --- a/services/distributedhardwarefwkservice/include/componentloader/component_loader.h +++ b/services/distributedhardwarefwkservice/include/componentloader/component_loader.h @@ -79,7 +79,7 @@ public: int32_t GetSource(const DHType dhType, IDistributedHardwareSource *&sourcePtr); int32_t GetSink(const DHType dhType, IDistributedHardwareSink *&sinkPtr); int32_t UnInit(); - std::vector GetAllCompTypes(); + void GetAllCompTypes(std::vector &dhTypeVec); int32_t GetLocalDHVersion(DHVersion &dhVersion); int32_t GetSourceSaId(const DHType dhType); DHType GetDHTypeBySrcSaId(const int32_t saId); @@ -98,7 +98,7 @@ private: void GetAllHandler(std::map &dhtypeMap); int32_t ReleaseHandler(void *&handler); int32_t GetCompPathAndVersion(const std::string &jsonStr, std::map &dhtypeMap); - CompVersion GetCompVersionFromComConfig(const CompConfig& cCfg); + void GetCompVersionFromComConfig(const CompConfig &comCfg, CompVersion &compVersion); int32_t ParseConfig(); void StoreLocalDHVersionInDB(); bool IsDHTypeExist(DHType dhType); diff --git a/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h b/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h index d49d33a3..63b5162f 100644 --- a/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h +++ b/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h @@ -80,6 +80,7 @@ public: */ bool FetchNeedRefreshTask(const std::pair &taskKey, TaskParam &taskParam); + int32_t CheckSinkConfigStart(const DHType dhType, bool &enableSink); int32_t CheckDemandStart(const std::string &uuid, const DHType dhType, bool &enableSource); int32_t RegisterDHStatusListener(sptr listener, int32_t callingUid, int32_t callingPid); int32_t UnregisterDHStatusListener(sptr listener, int32_t callingUid, int32_t callingPid); @@ -202,10 +203,10 @@ private: int32_t UninitCompSource(DHType dhType); int32_t InitCompSink(DHType dhType); int32_t UninitCompSink(DHType dhType); - ActionResult StartSource(DHType dhType); - ActionResult StopSource(DHType dhType); - ActionResult StartSink(DHType dhType); - ActionResult StopSink(DHType dhType); + int32_t StartSource(DHType dhType, ActionResult &sourceResult); + int32_t StopSource(DHType dhType, ActionResult &sourceResult); + int32_t StartSink(DHType dhType, ActionResult &sinkResult); + int32_t StopSink(DHType dhType, ActionResult &sinkResult); bool WaitForResult(const Action &action, ActionResult result); int32_t GetEnableParam(const std::string &networkId, const std::string &uuid, const std::string &dhId, DHType dhType, EnableParam ¶m); diff --git a/services/distributedhardwarefwkservice/include/componentmanager/component_privacy.h b/services/distributedhardwarefwkservice/include/componentmanager/component_privacy.h index 09d33143..347054b8 100644 --- a/services/distributedhardwarefwkservice/include/componentmanager/component_privacy.h +++ b/services/distributedhardwarefwkservice/include/componentmanager/component_privacy.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Copyright (c) 2023-2025 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 @@ -21,11 +21,6 @@ namespace OHOS { namespace DistributedHardware { -const std::string PRIVACY_SUBTYPE = "subtype"; -const std::string PRIVACY_NETWORKID = "networkId"; -constexpr uint32_t COMP_START_PAGE = 1; -constexpr uint32_t COMP_STOP_PAGE = 2; -constexpr uint32_t COMP_PRIVACY_DELAY_TIME = 1000; // million seconds class ComponentPrivacy : public PrivacyResourcesListener { public: ComponentPrivacy(); diff --git a/services/distributedhardwarefwkservice/include/resourcemanager/db_adapter.h b/services/distributedhardwarefwkservice/include/resourcemanager/db_adapter.h index 9f3c7e68..2d949ee2 100644 --- a/services/distributedhardwarefwkservice/include/resourcemanager/db_adapter.h +++ b/services/distributedhardwarefwkservice/include/resourcemanager/db_adapter.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Copyright (c) 2021-2025 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 @@ -33,7 +33,7 @@ namespace DistributedHardware { class DBAdapter : public std::enable_shared_from_this, public DistributedKv::KvStoreDeathRecipient { public: - DBAdapter(const std::string &appId, const std::string &storeId, + DBAdapter(const char *appId, const char *storeId, const std::shared_ptr changeListener); virtual ~DBAdapter(); diff --git a/services/distributedhardwarefwkservice/include/transport/dh_comm_tool.h b/services/distributedhardwarefwkservice/include/transport/dh_comm_tool.h index ecb07a0b..9d396c38 100644 --- a/services/distributedhardwarefwkservice/include/transport/dh_comm_tool.h +++ b/services/distributedhardwarefwkservice/include/transport/dh_comm_tool.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-2025 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 @@ -27,11 +27,6 @@ namespace OHOS { namespace DistributedHardware { -// request remote dh send back full dh capabilities -constexpr int32_t DH_COMM_REQ_FULL_CAPS = 1; -// send back full dh attributes to the requester -constexpr int32_t DH_COMM_RSP_FULL_CAPS = 2; - class DHCommTool : public std::enable_shared_from_this { public: DHCommTool(); diff --git a/services/distributedhardwarefwkservice/include/versionmanager/version_manager.h b/services/distributedhardwarefwkservice/include/versionmanager/version_manager.h index 3d36bd1f..bdb5bb83 100644 --- a/services/distributedhardwarefwkservice/include/versionmanager/version_manager.h +++ b/services/distributedhardwarefwkservice/include/versionmanager/version_manager.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-2025 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 @@ -27,7 +27,6 @@ namespace OHOS { namespace DistributedHardware { -const std::string DH_LOCAL_VERSION = "1.0"; class VersionManager { DECLARE_SINGLE_INSTANCE_BASE(VersionManager); diff --git a/services/distributedhardwarefwkservice/src/componentloader/component_loader.cpp b/services/distributedhardwarefwkservice/src/componentloader/component_loader.cpp index 7e21a229..785822ef 100644 --- a/services/distributedhardwarefwkservice/src/componentloader/component_loader.cpp +++ b/services/distributedhardwarefwkservice/src/componentloader/component_loader.cpp @@ -44,27 +44,23 @@ using GetHardwareClass = IHardwareHandler *(*)(); using GetSourceHardwareClass = IDistributedHardwareSource *(*)(); using GetSinkHardwareClass = IDistributedHardwareSink *(*)(); namespace { -const std::string COMP_NAME = "name"; -const std::string COMP_TYPE = "type"; -const std::string COMP_HANDLER_LOC = "comp_handler_loc"; -const std::string COMP_HANDLER_VERSION = "comp_handler_version"; -const std::string COMP_SOURCE_LOC = "comp_source_loc"; -const std::string COMP_SOURCE_VERSION = "comp_source_version"; -const std::string COMP_SOURCE_SA_ID = "comp_source_sa_id"; -const std::string COMP_SINK_LOC = "comp_sink_loc"; -const std::string COMP_SINK_VERSION = "comp_sink_version"; -const std::string COMP_SINK_SA_ID = "comp_sink_sa_id"; -const std::string COMP_RESOURCE_DESC = "comp_resource_desc"; -const std::string COMP_SUBTYPE = "subtype"; -const std::string COMP_SENSITIVE = "sensitive"; - -const std::string COMPONENTSLOAD_DISTRIBUTED_COMPONENTS = "distributed_components"; - -const std::string DEFAULT_NAME = ""; -const std::string DEFAULT_TYPE = "UNKNOWN"; -const std::string DEFAULT_LOC = ""; -const int32_t DEFAULT_SA_ID = -1; -const std::string DEFAULT_VERSION = "1.0"; +constexpr const char *COMP_NAME = "name"; +constexpr const char *COMP_TYPE = "type"; +constexpr const char *COMP_HANDLER_LOC = "comp_handler_loc"; +constexpr const char *COMP_HANDLER_VERSION = "comp_handler_version"; +constexpr const char *COMP_SOURCE_LOC = "comp_source_loc"; +constexpr const char *COMP_SOURCE_VERSION = "comp_source_version"; +constexpr const char *COMP_SOURCE_SA_ID = "comp_source_sa_id"; +constexpr const char *COMP_SINK_LOC = "comp_sink_loc"; +constexpr const char *COMP_SINK_VERSION = "comp_sink_version"; +constexpr const char *COMP_SINK_SA_ID = "comp_sink_sa_id"; +constexpr const char *COMP_RESOURCE_DESC = "comp_resource_desc"; +constexpr const char *COMP_SUBTYPE = "subtype"; +constexpr const char *COMP_SENSITIVE = "sensitive"; +constexpr const char *COMPONENTSLOAD_DISTRIBUTED_COMPONENTS = "distributed_components"; + +constexpr int32_t DEFAULT_SA_ID = -1; +constexpr uint32_t MAX_COMP_SIZE = 128; std::map g_mapDhTypeName = { { "UNKNOWN", DHType::UNKNOWN }, @@ -98,28 +94,24 @@ int32_t ComponentLoader::Init() return ret; } -std::vector ComponentLoader::GetAllCompTypes() +void ComponentLoader::GetAllCompTypes(std::vector &dhTypeVec) { std::lock_guard lock(compHandlerMapMutex_); - std::vector DHTypeALL; for (std::map::iterator it = compHandlerMap_.begin(); it != compHandlerMap_.end(); ++it) { - DHTypeALL.push_back(it->first); + dhTypeVec.push_back(it->first); } - return DHTypeALL; } -CompVersion ComponentLoader::GetCompVersionFromComConfig(const CompConfig& cCfg) +void ComponentLoader::GetCompVersionFromComConfig(const CompConfig &comCfg, CompVersion &compVersion) { - CompVersion compVersions; - compVersions.dhType = cCfg.type; - compVersions.name = cCfg.name; - compVersions.handlerVersion = cCfg.compHandlerVersion; - compVersions.sinkVersion = cCfg.compSinkVersion; - compVersions.sourceVersion = cCfg.compSourceVersion; - compVersions.haveFeature = cCfg.haveFeature; - compVersions.sourceFeatureFilters = cCfg.sourceFeatureFilters; - compVersions.sinkSupportedFeatures = cCfg.sinkSupportedFeatures; - return compVersions; + compVersion.dhType = comCfg.type; + compVersion.name = comCfg.name; + compVersion.handlerVersion = comCfg.compHandlerVersion; + compVersion.sinkVersion = comCfg.compSinkVersion; + compVersion.sourceVersion = comCfg.compSourceVersion; + compVersion.haveFeature = comCfg.haveFeature; + compVersion.sourceFeatureFilters = comCfg.sourceFeatureFilters; + compVersion.sinkSupportedFeatures = comCfg.sinkSupportedFeatures; } bool ComponentLoader::CheckComponentEnable(const CompConfig &config) @@ -148,7 +140,7 @@ int32_t ComponentLoader::GetCompPathAndVersion(const std::string &jsonStr, std:: DHLOGE("jsonStr parse failed"); return ERR_DH_FWK_JSON_PARSE_FAILED; } - cJSON *components = cJSON_GetObjectItem(root, COMPONENTSLOAD_DISTRIBUTED_COMPONENTS.c_str()); + cJSON *components = cJSON_GetObjectItem(root, COMPONENTSLOAD_DISTRIBUTED_COMPONENTS); if (!IsArray(components)) { DHLOGE("distributed_components is not an array"); cJSON_Delete(root); @@ -166,8 +158,9 @@ int32_t ComponentLoader::GetCompPathAndVersion(const std::string &jsonStr, std:: CompConfig config; ParseCompConfigFromJson(component, config); dhtypeMap.insert(std::pair(config.type, config)); - localDHVersion_.compVersions.insert( - std::pair(config.type, GetCompVersionFromComConfig(config))); + CompVersion compVersion; + GetCompVersionFromComConfig(config, compVersion); + localDHVersion_.compVersions.insert(std::pair(config.type, compVersion)); } cJSON_Delete(root); isLocalVersionInit_.store(true); @@ -176,47 +169,47 @@ int32_t ComponentLoader::GetCompPathAndVersion(const std::string &jsonStr, std:: void ComponentLoader::ParseCompConfigFromJson(cJSON *component, CompConfig &config) { - cJSON *nameJson = cJSON_GetObjectItem(component, COMP_NAME.c_str()); + cJSON *nameJson = cJSON_GetObjectItem(component, COMP_NAME); if (IsString(nameJson)) { config.name = nameJson->valuestring; } - cJSON *typeJson = cJSON_GetObjectItem(component, COMP_TYPE.c_str()); + cJSON *typeJson = cJSON_GetObjectItem(component, COMP_TYPE); if (IsString(typeJson)) { config.type = g_mapDhTypeName[typeJson->valuestring]; } - cJSON *handlerLocJson = cJSON_GetObjectItem(component, COMP_HANDLER_LOC.c_str()); + cJSON *handlerLocJson = cJSON_GetObjectItem(component, COMP_HANDLER_LOC); if (IsString(handlerLocJson)) { config.compHandlerLoc = handlerLocJson->valuestring; } - cJSON *handlerVerJson = cJSON_GetObjectItem(component, COMP_HANDLER_VERSION.c_str()); + cJSON *handlerVerJson = cJSON_GetObjectItem(component, COMP_HANDLER_VERSION); if (IsString(handlerVerJson)) { config.compHandlerVersion = handlerVerJson->valuestring; } - cJSON *sourceLocJson = cJSON_GetObjectItem(component, COMP_SOURCE_LOC.c_str()); + cJSON *sourceLocJson = cJSON_GetObjectItem(component, COMP_SOURCE_LOC); if (IsString(sourceLocJson)) { config.compSourceLoc = sourceLocJson->valuestring; } - cJSON *sourceVerJson = cJSON_GetObjectItem(component, COMP_SOURCE_VERSION.c_str()); + cJSON *sourceVerJson = cJSON_GetObjectItem(component, COMP_SOURCE_VERSION); if (IsString(sourceVerJson)) { config.compSourceVersion = sourceVerJson->valuestring; } - cJSON *sourceSaIdJson = cJSON_GetObjectItem(component, COMP_SOURCE_SA_ID.c_str()); + cJSON *sourceSaIdJson = cJSON_GetObjectItem(component, COMP_SOURCE_SA_ID); if (IsInt32(sourceSaIdJson)) { config.compSourceSaId = static_cast(sourceSaIdJson->valueint); } - cJSON *sinkLocJson = cJSON_GetObjectItem(component, COMP_SINK_LOC.c_str()); + cJSON *sinkLocJson = cJSON_GetObjectItem(component, COMP_SINK_LOC); if (IsString(sinkLocJson)) { config.compSinkLoc = sinkLocJson->valuestring; } - cJSON *sinkVerJson = cJSON_GetObjectItem(component, COMP_SINK_VERSION.c_str()); + cJSON *sinkVerJson = cJSON_GetObjectItem(component, COMP_SINK_VERSION); if (IsString(sinkVerJson)) { config.compSinkVersion = sinkVerJson->valuestring; } - cJSON *sinkSaIdJson = cJSON_GetObjectItem(component, COMP_SINK_SA_ID.c_str()); + cJSON *sinkSaIdJson = cJSON_GetObjectItem(component, COMP_SINK_SA_ID); if (IsInt32(sinkSaIdJson)) { config.compSinkSaId = static_cast(sinkSaIdJson->valueint); } - cJSON *resourceDescs = cJSON_GetObjectItem(component, COMP_RESOURCE_DESC.c_str()); + cJSON *resourceDescs = cJSON_GetObjectItem(component, COMP_RESOURCE_DESC); if (IsArray(resourceDescs)) { ParseResourceDescFromJson(resourceDescs, config); } @@ -228,7 +221,7 @@ void ComponentLoader::ParseResourceDescFromJson(cJSON *resourceDescs, CompConfig cJSON *resourceDesc = nullptr; cJSON_ArrayForEach(resourceDesc, resourceDescs) { bool sensitiveValue; - cJSON *sensitive = cJSON_GetObjectItem(resourceDesc, COMP_SENSITIVE.c_str()); + cJSON *sensitive = cJSON_GetObjectItem(resourceDesc, COMP_SENSITIVE); if (!IsBool(sensitive)) { DHLOGE("COMP_SUBTYPE is invalid!"); return; @@ -239,7 +232,7 @@ void ComponentLoader::ParseResourceDescFromJson(cJSON *resourceDescs, CompConfig sensitiveValue = false; } ResourceDesc resource; - cJSON *subtypeJson = cJSON_GetObjectItem(resourceDesc, COMP_SUBTYPE.c_str()); + cJSON *subtypeJson = cJSON_GetObjectItem(resourceDesc, COMP_SUBTYPE); if (!IsString(subtypeJson)) { DHLOGE("COMP_SUBTYPE is invalid!"); return; diff --git a/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp b/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp index 35b43d0a..96b0f785 100644 --- a/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp +++ b/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp @@ -64,9 +64,6 @@ namespace { constexpr int32_t ENABLE_PARAM_RETRY_TIME = 500 * 1000; constexpr int32_t INVALID_SA_ID = -1; constexpr int32_t UNINIT_COMPONENT_TIMEOUT_SECONDS = 2; - constexpr int32_t SYNC_DEVICE_INFO_TIMEOUT_MILLISECONDS = 2000; - constexpr int32_t SYNC_DEVICE_INFO_INTERVAL_MILLISECONDS = 200; - const std::string MONITOR_TASK_TIMER_ID = "monitor_task_timer_id"; } ComponentManager::ComponentManager() : compSource_({}), compSink_({}), compSrcSaId_({}), @@ -129,18 +126,17 @@ void ComponentManager::StopPrivacy() } } -ActionResult ComponentManager::StartSource(DHType dhType) +int32_t ComponentManager::StartSource(DHType dhType, ActionResult &sourceResult) { DHLOGI("Start Source, dhType: %{public}" PRIu32, (uint32_t)dhType); std::unique_lock lock(compSourceMutex_); - std::unordered_map> futures; if (compSource_.find(dhType) == compSource_.end()) { DHLOGE("Component for DHType: %{public}" PRIu32 " not init source handler", (uint32_t)dhType); - return futures; + return ERR_DH_FWK_TYPE_NOT_EXIST; } if (compSource_[dhType] == nullptr) { DHLOGE("comp source ptr is null"); - return futures; + return ERR_DH_FWK_SA_HANDLER_IS_NULL; } std::string uuid = DHContext::GetInstance().GetDeviceInfo().uuid; CompVersion compVersion; @@ -151,23 +147,23 @@ ActionResult ComponentManager::StartSource(DHType dhType) std::thread([p = std::move(p), this, dhType, params] () mutable { p.set_value(compSource_[dhType]->InitSource(params)); }).detach(); - futures.emplace(dhType, f.share()); + sourceResult.emplace(dhType, f.share()); - return futures; + return DH_FWK_SUCCESS; } -ActionResult ComponentManager::StartSink(DHType dhType) +int32_t ComponentManager::StartSink(DHType dhType, ActionResult &sinkResult) { DHLOGI("Start Sink, dhType: %{public}" PRIu32, (uint32_t)dhType); std::unique_lock lock(compSinkMutex_); std::unordered_map> futures; if (compSink_.find(dhType) == compSink_.end()) { DHLOGE("Component for DHType: %{public}" PRIu32 " not init sink handler", (uint32_t)dhType); - return futures; + return ERR_DH_FWK_TYPE_NOT_EXIST; } if (compSink_[dhType] == nullptr) { DHLOGE("comp sink ptr is null"); - return futures; + return ERR_DH_FWK_SA_HANDLER_IS_NULL; } std::string uuid = DHContext::GetInstance().GetDeviceInfo().uuid; CompVersion compVersion; @@ -178,7 +174,7 @@ ActionResult ComponentManager::StartSink(DHType dhType) std::thread([p = std::move(p), this, dhType, params] () mutable { p.set_value(compSink_[dhType]->InitSink(params)); }).detach(); - futures.emplace(dhType, f.share()); + sinkResult.emplace(dhType, f.share()); if (cameraCompPrivacy_ == nullptr && dhType == DHType::CAMERA) { cameraCompPrivacy_ = std::make_shared(); compSink_[dhType]->RegisterPrivacyResources(cameraCompPrivacy_); @@ -187,8 +183,7 @@ ActionResult ComponentManager::StartSink(DHType dhType) audioCompPrivacy_ = std::make_shared(); compSink_[dhType]->RegisterPrivacyResources(audioCompPrivacy_); } - - return futures; + return DH_FWK_SUCCESS; } bool ComponentManager::WaitForResult(const Action &action, ActionResult actionsResult) @@ -782,24 +777,48 @@ std::shared_ptr ComponentManager return this->eventHandler_; } +int32_t ComponentManager::CheckSinkConfigStart(const DHType dhType, bool &enableSink) +{ + DHLOGI("CheckSinkConfigStart the dhType: %{public}#X configuration start.", dhType); + DHVersion localDhVersion; + auto ret = ComponentLoader::GetInstance().GetLocalDHVersion(localDhVersion); + if (ret != DH_FWK_SUCCESS) { + DHLOGE("GetLocalDHVersion fail."); + return ret; + } + auto iterLocal = localDhVersion.compVersions.find(dhType); + if (iterLocal == localDhVersion.compVersions.end()) { + DHLOGE("Not find dhType: %{public}#X in local!", dhType); + return ERR_DH_FWK_TYPE_NOT_EXIST; + } + if (!iterLocal->second.haveFeature) { + enableSink = true; + DHLOGI("Local DhType: %{public}#X is old configuration, need enable sink.", dhType); + return DH_FWK_SUCCESS; + } + + if (iterLocal->second.sinkSupportedFeatures.size() > 0) { + enableSink = true; + } + return DH_FWK_SUCCESS; +} + int32_t ComponentManager::CheckDemandStart(const std::string &uuid, const DHType dhType, bool &enableSource) { - // Initialize output parameters + DHLOGI("CheckDemandStart the dhType: %{public}#X configuration start.", dhType); enableSource = false; - // Get remote config CompVersion compVersion; auto ret = GetRemoteVerInfo(compVersion, uuid, dhType); if (ret != DH_FWK_SUCCESS) { - DHLOGE("GetRemoteVerInfo fail, errCode = %{public}d!", ret); + DHLOGE("GetRemoteVerInfo fail."); return ret; } - // Get local config DHVersion dhVersion; ret = ComponentLoader::GetInstance().GetLocalDHVersion(dhVersion); if (ret != DH_FWK_SUCCESS) { - DHLOGE("GetLocalDHVersion fail, errCode = %{public}d!", ret); + DHLOGE("GetLocalDHVersion fail."); return ret; } @@ -808,19 +827,17 @@ int32_t ComponentManager::CheckDemandStart(const std::string &uuid, const DHType DHLOGE("Not find dhType in local: %{public}#X!", dhType); return ERR_DH_FWK_TYPE_NOT_EXIST; } - // Check local config + if (!iterLocal->second.haveFeature) { + DHLOGI("Local dhType: %{public}#X is old configuration, need enable source", dhType); enableSource = true; return DH_FWK_SUCCESS; } - if (iterLocal->second.sourceFeatureFilters.size() == 0) { return DH_FWK_SUCCESS; } - // Check if the configurations on both ends match enableSource = IsFeatureMatched(iterLocal->second.sourceFeatureFilters, compVersion.sinkSupportedFeatures); - return DH_FWK_SUCCESS; } @@ -828,8 +845,8 @@ int32_t ComponentManager::RegisterDHStatusListener( sptr listener, int32_t callingUid, int32_t callingPid) { std::lock_guard lock(dhSinkStatusMtx_); - - auto compTypes = ComponentLoader::GetInstance().GetAllCompTypes(); + std::vector compTypes; + ComponentLoader::GetInstance().GetAllCompTypes(compTypes); for (const auto &type : compTypes) { auto &status = dhSinkStatus_[type]; DHStatusCtrlKey ctrlKey { @@ -852,8 +869,8 @@ int32_t ComponentManager::UnregisterDHStatusListener( sptr listener, int32_t callingUid, int32_t callingPid) { std::lock_guard lock(dhSinkStatusMtx_); - - auto compTypes = ComponentLoader::GetInstance().GetAllCompTypes(); + std::vector compTypes; + ComponentLoader::GetInstance().GetAllCompTypes(compTypes); for (const auto &type : compTypes) { auto &status = dhSinkStatus_[type]; DHStatusCtrlKey ctrlKey { @@ -877,8 +894,8 @@ int32_t ComponentManager::RegisterDHStatusListener( const std::string &networkId, sptr listener, int32_t callingUid, int32_t callingPid) { std::lock_guard lock(dhSourceStatusMtx_); - - auto compTypes = ComponentLoader::GetInstance().GetAllCompTypes(); + std::vector compTypes; + ComponentLoader::GetInstance().GetAllCompTypes(compTypes); for (const auto &type : compTypes) { auto &status = dhSourceStatus_[type]; DHStatusCtrlKey ctrlKey { @@ -901,8 +918,8 @@ int32_t ComponentManager::UnregisterDHStatusListener( const std::string &networkId, sptr listener, int32_t callingUid, int32_t callingPid) { std::lock_guard lock(dhSourceStatusMtx_); - - auto compTypes = ComponentLoader::GetInstance().GetAllCompTypes(); + std::vector compTypes; + ComponentLoader::GetInstance().GetAllCompTypes(compTypes); for (const auto &type : compTypes) { auto &status = dhSourceStatus_[type]; DHStatusCtrlKey ctrlKey { @@ -991,6 +1008,10 @@ int32_t ComponentManager::ForceDisableSink(const DHDescriptor &dhDescriptor) int32_t ComponentManager::ForceDisableSource(const std::string &networkId, const DHDescriptor &dhDescriptor) { + if (!ComponentLoader::GetInstance().IsDHTypeSupport(dhDescriptor.dhType)) { + DHLOGE("Not support dhType: %{public}#X!", dhDescriptor.dhType); + return ERR_DH_FWK_TYPE_NOT_EXIST; + } std::vector> listeners; int32_t ret = ForceDisableSourceInternal(networkId, dhDescriptor, listeners); if (ret == DH_FWK_SUCCESS) { @@ -1026,12 +1047,7 @@ int32_t ComponentManager::CheckIdenticalAccount(const std::string &networkId, int32_t ComponentManager::GetRemoteVerInfo(CompVersion &compVersion, const std::string &uuid, DHType dhType) { MetaCapInfoMap metaInfoMap; - auto ret = MetaInfoManager::GetInstance()->GetMetaDataByDHType(dhType, metaInfoMap); - if (ret != DH_FWK_SUCCESS) { - DHLOGE("GetMetaDataByDHType failed, uuid =%{public}s, dhType = %{public}#X, errCode = %{public}d.", - GetAnonyString(uuid).c_str(), dhType, ret); - return ret; - } + MetaInfoManager::GetInstance()->GetMetaDataByDHType(dhType, metaInfoMap); for (const auto &metaInfo : metaInfoMap) { if (DHContext::GetInstance().GetUUIDByDeviceId(metaInfo.second->GetDeviceId()) == uuid) { compVersion = metaInfo.second->GetCompVersion(); @@ -1053,6 +1069,7 @@ bool ComponentManager::IsFeatureMatched(const std::vector &sourceFe } } } + DHLOGE("The sourcefeature and the sinkfeature do not match."); return false; } @@ -1102,7 +1119,12 @@ int32_t ComponentManager::EnableSinkInternal(const DHDescriptor &dhDescriptor, DHLOGE("InitCompSink failed, ret = %{public}d.", ret); return ret; } - auto sinkResult = StartSink(dhDescriptor.dhType); + std::unordered_map> sinkResult; + ret = StartSink(dhDescriptor.dhType, sinkResult); + if (ret != DH_FWK_SUCCESS) { + DHLOGE("StartSink failed"); + return ret; + } if (!WaitForResult(Action::START_SINK, sinkResult)) { DHLOGE("StartSink failed, some virtual components maybe cannot work, but want to continue!"); HiSysEventWriteMsg(DHFWK_INIT_FAIL, OHOS::HiviewDFX::HiSysEvent::EventType::FAULT, @@ -1158,12 +1180,17 @@ int32_t ComponentManager::DisableSinkInternal(const DHDescriptor &dhDescriptor, } // Start disabling hardware sink - auto sinkResult = StopSink(dhDescriptor.dhType); + std::unordered_map> sinkResult; + auto ret = StopSink(dhDescriptor.dhType, sinkResult); + if (ret != DH_FWK_SUCCESS) { + DHLOGE("StopSink failed!"); + return ret; + } if (!WaitForResult(Action::STOP_SINK, sinkResult)) { DHLOGE("StopSink failed, but want to continue!"); return ERR_DH_FWK_COMPONENT_DISABLE_TIMEOUT; } - auto ret = UninitCompSink(dhDescriptor.dhType); + ret = UninitCompSink(dhDescriptor.dhType); if (ret != DH_FWK_SUCCESS) { DHLOGE("UninitCompSink failed, ret = %{public}d.", ret); return ret; @@ -1346,12 +1373,17 @@ int32_t ComponentManager::ForceDisableSinkInternal( } // Unload component - auto sinkResult = StopSink(dhDescriptor.dhType); + std::unordered_map> sinkResult; + auto ret = StopSink(dhDescriptor.dhType, sinkResult); + if (ret != DH_FWK_SUCCESS) { + DHLOGE("StopSink failed!"); + return ret; + } if (!WaitForResult(Action::STOP_SINK, sinkResult)) { DHLOGE("StopSink failed, but want to continue!"); return ERR_DH_FWK_COMPONENT_DISABLE_TIMEOUT; } - auto ret = UninitCompSink(dhDescriptor.dhType); + ret = UninitCompSink(dhDescriptor.dhType); if (ret != DH_FWK_SUCCESS) { DHLOGE("UninitCompSink failed, ret = %{public}d.", ret); return ret; @@ -1363,17 +1395,7 @@ int32_t ComponentManager::ForceDisableSourceInternal(const std::string &networkI const DHDescriptor &dhDescriptor, std::vector> &listeners) { std::lock_guard lock(dhSourceStatusMtx_); - - // Check if the input parameters and device type support it - if (!ComponentLoader::GetInstance().IsDHTypeSupport(dhDescriptor.dhType)) { - DHLOGE("Not support dhType: %{public}#X!", dhDescriptor.dhType); - return ERR_DH_FWK_TYPE_NOT_EXIST; - } - - DHStatusSourceEnableInfoKey enableInfoKey { - .networkId = networkId, - .dhId = dhDescriptor.id - }; + DHStatusSourceEnableInfoKey enableInfoKey { networkId, dhDescriptor.id }; auto &status = dhSourceStatus_[dhDescriptor.dhType]; auto itEnableInfo = status.enableInfos.find(enableInfoKey); if (itEnableInfo == status.enableInfos.end()) { @@ -1396,8 +1418,7 @@ int32_t ComponentManager::ForceDisableSourceInternal(const std::string &networkI if (item.second.enableState != EnableState::DISABLED) { auto it = status.listeners.find(item.first); if (it != status.listeners.end()) { - auto listener = it->second; - listeners.push_back(listener); + listeners.push_back(it->second); } } } @@ -1408,7 +1429,12 @@ int32_t ComponentManager::ForceDisableSourceInternal(const std::string &networkI } // Unload component - auto sourceResult = StopSource(dhDescriptor.dhType); + std::unordered_map> sourceResult; + ret = StopSource(dhDescriptor.dhType, sourceResult); + if (ret != DH_FWK_SUCCESS) { + DHLOGE("StopSource failed"); + return ret; + } if (!WaitForResult(Action::STOP_SOURCE, sourceResult)) { DHLOGE("StopSource timeout!"); return ERR_DH_FWK_COMPONENT_DISABLE_TIMEOUT; @@ -1430,7 +1456,12 @@ int32_t ComponentManager::RealEnableSource(const std::string &networkId, const s DHLOGE("InitCompSource failed, ret = %{public}d.", ret); return ret; } - auto sourceResult = StartSource(dhDescriptor.dhType); + std::unordered_map> sourceResult; + ret = StartSource(dhDescriptor.dhType, sourceResult); + if (ret != DH_FWK_SUCCESS) { + DHLOGE("StartSource failed"); + return ret; + } if (!WaitForResult(Action::START_SOURCE, sourceResult)) { DHLOGE("StartSource failed, some virtual components maybe cannot work, but want to continue!"); HiSysEventWriteMsg(DHFWK_INIT_FAIL, OHOS::HiviewDFX::HiSysEvent::EventType::FAULT, @@ -1441,7 +1472,8 @@ int32_t ComponentManager::RealEnableSource(const std::string &networkId, const s ret = Enable(networkId, uuid, dhDescriptor.id, dhDescriptor.dhType, isActive); if (ret != DH_FWK_SUCCESS) { DHLOGE("Enable failed, ret = %{public}d.", ret); - StopSource(dhDescriptor.dhType); + std::unordered_map> futureResult; + StopSource(dhDescriptor.dhType, futureResult); UninitCompSource(dhDescriptor.dhType); return ret; } @@ -1461,7 +1493,12 @@ int32_t ComponentManager::RealDisableSource(const std::string &networkId, const DHLOGE("Disable failed, ret = %{public}d.", ret); return ret; } - auto sourceResult = StopSource(dhDescriptor.dhType); + std::unordered_map> sourceResult; + ret = StopSource(dhDescriptor.dhType, sourceResult); + if (ret != DH_FWK_SUCCESS) { + DHLOGE("StopSource failed"); + return ret; + } if (!WaitForResult(Action::STOP_SOURCE, sourceResult)) { DHLOGE("StopSource timeout!"); return ERR_DH_FWK_COMPONENT_DISABLE_TIMEOUT; @@ -1773,40 +1810,40 @@ int32_t ComponentManager::UninitCompSink(DHType dhType) return DH_FWK_SUCCESS; } -ActionResult ComponentManager::StopSource(DHType dhType) +int32_t ComponentManager::StopSource(DHType dhType, ActionResult &sourceResult) { + DHLOGI("StopSource, dhType: %{public}#X", dhType); std::shared_lock lock(compSourceMutex_); - std::unordered_map> futures; if (compSource_.find(dhType) == compSource_.end()) { DHLOGE("Component for DHType: %{public}" PRIu32 " not init source handler.", (uint32_t)dhType); - return futures; + return ERR_DH_FWK_TYPE_NOT_EXIST; } auto sourcePtr = compSource_[dhType]; if (sourcePtr == nullptr) { DHLOGE("comp source ptr is null."); - return futures; + return ERR_DH_FWK_SA_HANDLER_IS_NULL; } std::promise p; std::future f = p.get_future(); std::thread([p = std::move(p), sourcePtr] () mutable { p.set_value(sourcePtr->ReleaseSource()); }).detach(); - futures.emplace(dhType, f.share()); - return futures; + sourceResult.emplace(dhType, f.share()); + return DH_FWK_SUCCESS; } -ActionResult ComponentManager::StopSink(DHType dhType) +int32_t ComponentManager::StopSink(DHType dhType, ActionResult &sinkResult) { + DHLOGI("StopSink, dhType: %{public}#X", dhType); std::shared_lock lock(compSinkMutex_); - std::unordered_map> futures; if (compSink_.find(dhType) == compSink_.end()) { DHLOGE("Component for DHType: %{public}" PRIu32 " not init sink handler.", (uint32_t)dhType); - return futures; + return ERR_DH_FWK_TYPE_NOT_EXIST; } auto sinkPtr = compSink_[dhType]; if (sinkPtr == nullptr) { DHLOGE("comp sink ptr is null."); - return futures; + return ERR_DH_FWK_SA_HANDLER_IS_NULL; } std::promise p; std::future f = p.get_future(); @@ -1821,8 +1858,8 @@ ActionResult ComponentManager::StopSink(DHType dhType) hardwareHandler->UnRegisterPluginListener(); return status; }).detach(); - futures.emplace(dhType, f.share()); - return futures; + sinkResult.emplace(dhType, f.share()); + return DH_FWK_SUCCESS; } int32_t ComponentManager::DisableMetaSource(const std::string &networkId, const DHDescriptor &dhDescriptor, @@ -1888,7 +1925,12 @@ int32_t ComponentManager::DisableMetaSourceInternal(const std::string &networkId if (ret != DH_FWK_SUCCESS) { DHLOGE("Meta disable source failed, ret = %{public}d.", ret); } - auto sourceResult = StopSource(dhDescriptor.dhType); + std::unordered_map> sourceResult; + ret = StopSource(dhDescriptor.dhType, sourceResult); + if (ret != DH_FWK_SUCCESS) { + DHLOGE("StopSource failed"); + return ret; + } if (!WaitForResult(Action::STOP_SOURCE, sourceResult)) { DHLOGE("StopSource timeout!"); return ERR_DH_FWK_COMPONENT_DISABLE_TIMEOUT; @@ -1963,7 +2005,12 @@ int32_t ComponentManager::EnableMetaSourceInternal(const std::string &networkId, DHLOGE("InitCompSource failed, ret = %{public}d.", ret); return ret; } - auto sourceResult = StartSource(dhDescriptor.dhType); + std::unordered_map> sourceResult; + ret = StartSource(dhDescriptor.dhType, sourceResult); + if (ret != DH_FWK_SUCCESS) { + DHLOGE("StartSource failed"); + return ret; + } if (!WaitForResult(Action::START_SOURCE, sourceResult)) { DHLOGE("StartSource failed, some virtual components maybe cannot work, but want to continue!"); HiSysEventWriteMsg(DHFWK_INIT_FAIL, OHOS::HiviewDFX::HiSysEvent::EventType::FAULT, @@ -1974,7 +2021,8 @@ int32_t ComponentManager::EnableMetaSourceInternal(const std::string &networkId, ret = dhModemExt->Enable(networkId, sourcePtr); if (ret != DH_FWK_SUCCESS) { DHLOGE("EnableMeta failed, ret = %{public}d.", ret); - StopSource(dhDescriptor.dhType); + std::unordered_map> futureResult; + StopSource(dhDescriptor.dhType, futureResult); UninitCompSource(dhDescriptor.dhType); return ret; } diff --git a/services/distributedhardwarefwkservice/src/componentmanager/component_monitor.cpp b/services/distributedhardwarefwkservice/src/componentmanager/component_monitor.cpp index fdcd7026..ade84587 100644 --- a/services/distributedhardwarefwkservice/src/componentmanager/component_monitor.cpp +++ b/services/distributedhardwarefwkservice/src/componentmanager/component_monitor.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 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 @@ -31,7 +31,7 @@ namespace OHOS { namespace DistributedHardware { -const int32_t WAIT_SERVICE_STATUS_TIMEOUT = 1; +constexpr int32_t WAIT_SERVICE_STATUS_TIMEOUT = 1; ComponentMonitor::ComponentMonitor() : saListeners_({}) { diff --git a/services/distributedhardwarefwkservice/src/componentmanager/component_privacy.cpp b/services/distributedhardwarefwkservice/src/componentmanager/component_privacy.cpp index 2d7c08da..91b2dbc0 100644 --- a/services/distributedhardwarefwkservice/src/componentmanager/component_privacy.cpp +++ b/services/distributedhardwarefwkservice/src/componentmanager/component_privacy.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Copyright (c) 2023-2025 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 @@ -32,6 +32,14 @@ namespace DistributedHardware { #undef DH_LOG_TAG #define DH_LOG_TAG "ComponentPrivacy" +namespace { + constexpr const char *PRIVACY_SUBTYPE = "subtype"; + constexpr const char *PRIVACY_NETWORKID = "networkId"; + constexpr uint32_t COMP_START_PAGE = 1; + constexpr uint32_t COMP_STOP_PAGE = 2; + constexpr uint32_t COMP_PRIVACY_DELAY_TIME = 1000; // million seconds +} + ComponentPrivacy::ComponentPrivacy() { DHLOGI("ComponentPrivacy ctor."); @@ -78,8 +86,8 @@ void ComponentPrivacy::HandlePullUpPage(const std::string &subtype, const std::s } if (eventHandler_ != nullptr) { DHLOGI("SendEvent COMP_START_PAGE"); - cJSON_AddStringToObject(tmpJson, PRIVACY_SUBTYPE.c_str(), subtype.c_str()); - cJSON_AddStringToObject(tmpJson, PRIVACY_NETWORKID.c_str(), networkId.c_str()); + cJSON_AddStringToObject(tmpJson, PRIVACY_SUBTYPE, subtype.c_str()); + cJSON_AddStringToObject(tmpJson, PRIVACY_NETWORKID, networkId.c_str()); cJSON_AddItemToArray(jsonArrayMsg, tmpJson); AppExecFwk::InnerEvent::Pointer msgEvent = AppExecFwk::InnerEvent::Get(COMP_START_PAGE, @@ -107,7 +115,7 @@ void ComponentPrivacy::HandleClosePage(const std::string &subtype) } if (eventHandler_ != nullptr) { DHLOGI("SendEvent COMP_STOP_PAGE"); - cJSON_AddStringToObject(tmpJson, PRIVACY_SUBTYPE.c_str(), subtype.c_str()); + cJSON_AddStringToObject(tmpJson, PRIVACY_SUBTYPE, subtype.c_str()); cJSON_AddItemToArray(jsonArrayMsg, tmpJson); AppExecFwk::InnerEvent::Pointer msgEvent = AppExecFwk::InnerEvent::Get(COMP_STOP_PAGE, @@ -297,13 +305,13 @@ void ComponentPrivacy::ComponentEventHandler::ProcessStartPage(const AppExecFwk: DHLOGI("ProcessStartPage enter."); std::shared_ptr dataMsg = event->GetSharedObject(); cJSON *innerMsg = cJSON_GetArrayItem(dataMsg.get(), 0); - cJSON *subtypeJson = cJSON_GetObjectItem(innerMsg, PRIVACY_SUBTYPE.c_str()); + cJSON *subtypeJson = cJSON_GetObjectItem(innerMsg, PRIVACY_SUBTYPE); if (!IsString(subtypeJson)) { DHLOGE("PRIVACY_SUBTYPE is invalid!"); return; } std::string subtype = subtypeJson->valuestring; - cJSON *networkIdJson = cJSON_GetObjectItem(innerMsg, PRIVACY_NETWORKID.c_str()); + cJSON *networkIdJson = cJSON_GetObjectItem(innerMsg, PRIVACY_NETWORKID); if (!IsString(networkIdJson)) { DHLOGE("PRIVACY_NETWORKID is invalid!"); return; @@ -325,7 +333,7 @@ void ComponentPrivacy::ComponentEventHandler::ProcessStopPage(const AppExecFwk:: DHLOGE("innerMsg is nullptr"); return; } - cJSON *subtypeJson = cJSON_GetObjectItem(innerMsg, PRIVACY_SUBTYPE.c_str()); + cJSON *subtypeJson = cJSON_GetObjectItem(innerMsg, PRIVACY_SUBTYPE); if (!IsString(subtypeJson)) { DHLOGE("PRIVACY_SUBTYPE is invalid!"); return; diff --git a/services/distributedhardwarefwkservice/src/localhardwaremanager/local_hardware_manager.cpp b/services/distributedhardwarefwkservice/src/localhardwaremanager/local_hardware_manager.cpp index ff9acef0..18d5801b 100644 --- a/services/distributedhardwarefwkservice/src/localhardwaremanager/local_hardware_manager.cpp +++ b/services/distributedhardwarefwkservice/src/localhardwaremanager/local_hardware_manager.cpp @@ -49,7 +49,8 @@ void LocalHardwareManager::Init() { DHLOGI("start"); std::lock_guard lock(localHardwareMgrMutex_); - std::vector allCompTypes = ComponentLoader::GetInstance().GetAllCompTypes(); + std::vector allCompTypes; + ComponentLoader::GetInstance().GetAllCompTypes(allCompTypes); int64_t allQueryStartTime = GetCurrentTime(); for (auto dhType : allCompTypes) { int64_t singleQueryStartTime = GetCurrentTime(); diff --git a/services/distributedhardwarefwkservice/src/lowlatency/low_latency.cpp b/services/distributedhardwarefwkservice/src/lowlatency/low_latency.cpp index f6fd7d6d..c4bdd189 100644 --- a/services/distributedhardwarefwkservice/src/lowlatency/low_latency.cpp +++ b/services/distributedhardwarefwkservice/src/lowlatency/low_latency.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 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 @@ -31,7 +31,10 @@ namespace DistributedHardware { IMPLEMENT_SINGLE_INSTANCE(LowLatency); namespace { const std::string LOW_LATENCY_TIMER_ID = "low_latency_timer_id"; + const std::string LOW_LATENCY_KEY = "identity"; constexpr int32_t LOW_LATENCY_DELAY_MS = 50 * 1000; + constexpr int32_t MODE_DISABLE = 1; + constexpr uint32_t MAX_SWITCH_SIZE = 256; } LowLatency::LowLatency() : lowLatencyTimer_(std::make_shared(LOW_LATENCY_TIMER_ID, diff --git a/services/distributedhardwarefwkservice/src/lowlatency/low_latency_timer.cpp b/services/distributedhardwarefwkservice/src/lowlatency/low_latency_timer.cpp index c924d611..b293f095 100644 --- a/services/distributedhardwarefwkservice/src/lowlatency/low_latency_timer.cpp +++ b/services/distributedhardwarefwkservice/src/lowlatency/low_latency_timer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 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 @@ -26,6 +26,10 @@ namespace DistributedHardware { #undef DH_LOG_TAG #define DH_LOG_TAG "LowLatencyTimer" +constexpr int32_t MODE_ENABLE = 0; +constexpr int32_t MODE_DISABLE = 1; +const std::string LOW_LATENCY_KEY = "identity"; + LowLatencyTimer::LowLatencyTimer(std::string timerId, int32_t delayTimeMs) : DHTimer(timerId, delayTimeMs) { DHLOGI("LowLatencyTimer ctor!"); diff --git a/services/distributedhardwarefwkservice/src/resourcemanager/capability_info_manager.cpp b/services/distributedhardwarefwkservice/src/resourcemanager/capability_info_manager.cpp index 6dc0ef0b..3960f25f 100644 --- a/services/distributedhardwarefwkservice/src/resourcemanager/capability_info_manager.cpp +++ b/services/distributedhardwarefwkservice/src/resourcemanager/capability_info_manager.cpp @@ -34,6 +34,7 @@ namespace DistributedHardware { #define DH_LOG_TAG "CapabilityInfoManager" constexpr int32_t SYNC_DATA_TIMEOUT_MS = 1000 * 10; +constexpr const char *GLOBAL_CAPABILITY_INFO_KEY = "global_capability_info"; CapabilityInfoManager::CapabilityInfoManager() : dbAdapterPtr_(nullptr) { @@ -92,7 +93,7 @@ int32_t CapabilityInfoManager::Init() { DHLOGI("CapabilityInfoManager instance init!"); std::lock_guard lock(capInfoMgrMutex_); - dbAdapterPtr_ = std::make_shared(APP_ID, GLOBAL_CAPABILITY_ID, shared_from_this()); + dbAdapterPtr_ = std::make_shared(APP_ID, GLOBAL_CAPABILITY_INFO_KEY, shared_from_this()); if (dbAdapterPtr_ == nullptr) { DHLOGE("dbAdapterPtr_ is null"); return ERR_DH_FWK_RESOURCE_DB_ADAPTER_POINTER_NULL; diff --git a/services/distributedhardwarefwkservice/src/resourcemanager/db_adapter.cpp b/services/distributedhardwarefwkservice/src/resourcemanager/db_adapter.cpp index 8760ecd5..1e3247ec 100644 --- a/services/distributedhardwarefwkservice/src/resourcemanager/db_adapter.cpp +++ b/services/distributedhardwarefwkservice/src/resourcemanager/db_adapter.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Copyright (c) 2021-2025 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 @@ -41,15 +41,18 @@ namespace { constexpr int32_t DIED_CHECK_MAX_TIMES = 300; constexpr int32_t DIED_CHECK_INTERVAL = 100 * 1000; // 100ms const std::string DATABASE_DIR = "/data/service/el1/public/database/"; + constexpr const char *GLOBAL_META_INFO_KEY = "global_meta_info"; + constexpr const char *GLOBAL_VERSION_INFO_KEY = "global_version_info"; + constexpr const char *GLOBAL_CAPABILITY_INFO_KEY = "global_capability_info"; } -DBAdapter::DBAdapter(const std::string &appId, const std::string &storeId, - const std::shared_ptr changeListener) +DBAdapter::DBAdapter(const char *appId, const char *storeId, + const std::shared_ptr changeListener) { - this->appId_.appId = appId; - this->storeId_.storeId = storeId; + this->appId_.appId = std::string(appId); + this->storeId_.storeId = std::string(storeId); this->dataChangeListener_ = changeListener; - DHLOGI("DBAdapter Constructor Success, appId: %{public}s, storeId: %{public}s", appId.c_str(), storeId.c_str()); + DHLOGI("DBAdapter Constructor Success, appId: %{public}s, storeId: %{public}s", appId, storeId); } DBAdapter::~DBAdapter() @@ -257,7 +260,8 @@ int32_t DBAdapter::GetDataByKey(const std::string &key, std::string &data) SyncByNotFound(key); } #ifdef DHARDWARE_OPEN_SOURCE - if (this->dataType_ == DistributedKv::DataType::TYPE_STATICS && this->storeId_.storeId == GLOBAL_META_INFO) { + if (this->dataType_ == DistributedKv::DataType::TYPE_STATICS && + this->storeId_.storeId == std::string(GLOBAL_META_INFO_KEY)) { SyncByNotFound(key); } #endif @@ -288,7 +292,8 @@ int32_t DBAdapter::GetDataByKeyPrefix(const std::string &keyPrefix, std::vector< SyncByNotFound(keyPrefix); } #ifdef DHARDWARE_OPEN_SOURCE - if (this->dataType_ == DistributedKv::DataType::TYPE_STATICS && this->storeId_.storeId == GLOBAL_META_INFO) { + if (this->dataType_ == DistributedKv::DataType::TYPE_STATICS && + this->storeId_.storeId == std::string(GLOBAL_META_INFO_KEY)) { SyncByNotFound(keyPrefix); } #endif @@ -360,19 +365,19 @@ int32_t DBAdapter::PutDataBatch(const std::vector &keys, const std: void DBAdapter::SyncDBForRecover() { DHLOGI("Sync store id: %{public}s after db recover", storeId_.storeId.c_str()); - if (storeId_.storeId == GLOBAL_CAPABILITY_ID) { + if (storeId_.storeId == std::string(GLOBAL_CAPABILITY_INFO_KEY)) { AppExecFwk::InnerEvent::Pointer msgEvent = AppExecFwk::InnerEvent::Get(EVENT_CAPABILITY_INFO_DB_RECOVER); CapabilityInfoManager::GetInstance()->GetEventHandler()->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE); } - if (storeId_.storeId == GLOBAL_VERSION_ID) { + if (storeId_.storeId == std::string(GLOBAL_VERSION_INFO_KEY)) { AppExecFwk::InnerEvent::Pointer msgEvent = AppExecFwk::InnerEvent::Get(EVENT_VERSION_INFO_DB_RECOVER); VersionInfoManager::GetInstance()->GetEventHandler()->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE); } - if (storeId_.storeId == GLOBAL_META_INFO) { + if (storeId_.storeId == std::string(GLOBAL_META_INFO_KEY)) { AppExecFwk::InnerEvent::Pointer msgEvent = AppExecFwk::InnerEvent::Get(EVENT_META_INFO_DB_RECOVER); MetaInfoManager::GetInstance()->GetEventHandler()->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE); diff --git a/services/distributedhardwarefwkservice/src/resourcemanager/local_capability_info_manager.cpp b/services/distributedhardwarefwkservice/src/resourcemanager/local_capability_info_manager.cpp index b97c3f9d..e9004549 100644 --- a/services/distributedhardwarefwkservice/src/resourcemanager/local_capability_info_manager.cpp +++ b/services/distributedhardwarefwkservice/src/resourcemanager/local_capability_info_manager.cpp @@ -31,6 +31,8 @@ namespace DistributedHardware { #undef DH_LOG_TAG #define DH_LOG_TAG "LocalCapabilityInfoManager" +constexpr const char *LOCAL_CAPABILITY_INFO_KEY = "local_capability_info"; + LocalCapabilityInfoManager::LocalCapabilityInfoManager() : dbAdapterPtr_(nullptr) { DHLOGI("LocalCapabilityInfoManager construction!"); @@ -51,7 +53,7 @@ int32_t LocalCapabilityInfoManager::Init() { DHLOGI("LocalCapabilityInfoManager instance init!"); std::lock_guard lock(capInfoMgrMutex_); - dbAdapterPtr_ = std::make_shared(APP_ID, LOCAL_CAPABILITY_ID, shared_from_this()); + dbAdapterPtr_ = std::make_shared(APP_ID, LOCAL_CAPABILITY_INFO_KEY, shared_from_this()); if (dbAdapterPtr_ == nullptr) { DHLOGE("dbAdapterPtr_ is null"); return ERR_DH_FWK_RESOURCE_DB_ADAPTER_POINTER_NULL; diff --git a/services/distributedhardwarefwkservice/src/resourcemanager/meta_info_manager.cpp b/services/distributedhardwarefwkservice/src/resourcemanager/meta_info_manager.cpp index 7930e162..7999f32f 100644 --- a/services/distributedhardwarefwkservice/src/resourcemanager/meta_info_manager.cpp +++ b/services/distributedhardwarefwkservice/src/resourcemanager/meta_info_manager.cpp @@ -33,6 +33,8 @@ namespace DistributedHardware { #undef DH_LOG_TAG #define DH_LOG_TAG "MetaInfoManager" +constexpr const char *GLOBAL_META_INFO_KEY = "global_meta_info"; + MetaInfoManager::MetaInfoManager() : dbAdapterPtr_(nullptr) { DHLOGI("MetaInfoManager construction!"); @@ -87,7 +89,7 @@ int32_t MetaInfoManager::Init() { DHLOGI("MetaInfoManager instance init!"); std::lock_guard lock(metaInfoMgrMutex_); - dbAdapterPtr_ = std::make_shared(APP_ID, GLOBAL_META_INFO, shared_from_this()); + dbAdapterPtr_ = std::make_shared(APP_ID, GLOBAL_META_INFO_KEY, shared_from_this()); if (dbAdapterPtr_ == nullptr) { DHLOGE("dbAdapterPtr_ is null"); return ERR_DH_FWK_RESOURCE_DB_ADAPTER_POINTER_NULL; diff --git a/services/distributedhardwarefwkservice/src/resourcemanager/version_info_manager.cpp b/services/distributedhardwarefwkservice/src/resourcemanager/version_info_manager.cpp index b4dfeb61..88350853 100644 --- a/services/distributedhardwarefwkservice/src/resourcemanager/version_info_manager.cpp +++ b/services/distributedhardwarefwkservice/src/resourcemanager/version_info_manager.cpp @@ -31,6 +31,8 @@ namespace DistributedHardware { #undef DH_LOG_TAG #define DH_LOG_TAG "VersionInfoManager" +constexpr const char *GLOBAL_VERSION_INFO_KEY = "global_version_info"; + VersionInfoManager::VersionInfoManager() : dbAdapterPtr_(nullptr) {} @@ -84,7 +86,7 @@ int32_t VersionInfoManager::Init() { DHLOGI("VersionInfoManager instance init!"); std::lock_guard lock(verInfoMgrMutex_); - dbAdapterPtr_ = std::make_shared(APP_ID, GLOBAL_VERSION_ID, shared_from_this()); + dbAdapterPtr_ = std::make_shared(APP_ID, GLOBAL_VERSION_INFO_KEY, shared_from_this()); if (dbAdapterPtr_->Init(false, DistributedKv::DataType::TYPE_DYNAMICAL) != DH_FWK_SUCCESS) { DHLOGE("Init dbAdapterPtr_ failed"); return ERR_DH_FWK_RESOURCE_INIT_DB_FAILED; diff --git a/services/distributedhardwarefwkservice/src/task/enable_task.cpp b/services/distributedhardwarefwkservice/src/task/enable_task.cpp index c61baa76..84574b23 100644 --- a/services/distributedhardwarefwkservice/src/task/enable_task.cpp +++ b/services/distributedhardwarefwkservice/src/task/enable_task.cpp @@ -148,12 +148,21 @@ int32_t EnableTask::DoAutoEnable() { std::string localUdid = GetLocalUdid(); if (localUdid == GetUDID()) { + bool enableSink = false; + auto ret = ComponentManager::GetInstance().CheckSinkConfigStart(GetDhType(), enableSink); + if (ret != DH_FWK_SUCCESS) { + DHLOGE("CheckSinkConfigStart failed!"); + return ret; + } + if (!enableSink) { + DHLOGE("No need Enablesink."); + return ERR_DH_FWK_COMPONENT_NO_NEED_ENABLE; + } DHDescriptor dhDescriptor { .id = GetDhId(), .dhType = GetDhType() }; - DHLOGI("EnableSink DhType = %{public}#X", GetDhType()); - auto ret = ComponentManager::GetInstance().EnableSink(dhDescriptor, GetCallingUid(), GetCallingPid()); + ret = ComponentManager::GetInstance().EnableSink(dhDescriptor, GetCallingUid(), GetCallingPid()); if (ret != DH_FWK_SUCCESS) { DHLOGE("EnableSink DhType = %{public}#X, failed!", GetDhType()); } @@ -168,7 +177,7 @@ int32_t EnableTask::DoAutoEnable() } if (!enableSource) { DHLOGE("No need Enablesource."); - return ERR_DH_FWK_COMPONENT_LIMIT_DEMAND_START; + return ERR_DH_FWK_COMPONENT_NO_NEED_ENABLE; } DHDescriptor dhDescriptor { .id = GetDhId(), diff --git a/services/distributedhardwarefwkservice/src/task/online_task.cpp b/services/distributedhardwarefwkservice/src/task/online_task.cpp index f3f2e05d..3bf08b54 100644 --- a/services/distributedhardwarefwkservice/src/task/online_task.cpp +++ b/services/distributedhardwarefwkservice/src/task/online_task.cpp @@ -159,8 +159,8 @@ void OnLineTask::CreateEnableTask() void OnLineTask::CreateEnableSinkTask() { - DHLOGI("CreateEnableSinkTask start"); DeviceInfo localDeviceInfo = GetLocalDeviceInfo(); + DHLOGI("CreateEnableSinkTask, uuid: %{public}s", GetAnonyString(localDeviceInfo.uuid).c_str()); std::vector> localMetaInfos; std::vector> metaCapInfos; MetaInfoManager::GetInstance()->GetMetaCapInfosByUdidHash(localDeviceInfo.udidHash, metaCapInfos); diff --git a/services/distributedhardwarefwkservice/src/task/task.cpp b/services/distributedhardwarefwkservice/src/task/task.cpp index 6d9d4b3f..e66b9828 100644 --- a/services/distributedhardwarefwkservice/src/task/task.cpp +++ b/services/distributedhardwarefwkservice/src/task/task.cpp @@ -30,7 +30,7 @@ Task::Task(const std::string &networkId, const std::string &uuid, const std::str Task::~Task() { - this->childrenTasks_.clear(); + std::vector>().swap(this->childrenTasks_); } std::string Task::GetId() diff --git a/services/distributedhardwarefwkservice/src/transport/dh_comm_tool.cpp b/services/distributedhardwarefwkservice/src/transport/dh_comm_tool.cpp index 5d1fbde4..fe6cf560 100644 --- a/services/distributedhardwarefwkservice/src/transport/dh_comm_tool.cpp +++ b/services/distributedhardwarefwkservice/src/transport/dh_comm_tool.cpp @@ -33,6 +33,11 @@ namespace DistributedHardware { #undef DH_LOG_TAG #define DH_LOG_TAG "DHCommTool" +// request remote dh send back full dh capabilities +constexpr int32_t DH_COMM_REQ_FULL_CAPS = 1; +// send back full dh attributes to the requester +constexpr int32_t DH_COMM_RSP_FULL_CAPS = 2; + DHCommTool::DHCommTool() : dhTransportPtr_(nullptr) { DHLOGI("Ctor DHCommTool"); diff --git a/services/distributedhardwarefwkservice/src/transport/dh_transport.cpp b/services/distributedhardwarefwkservice/src/transport/dh_transport.cpp index 832cf913..0c052f86 100644 --- a/services/distributedhardwarefwkservice/src/transport/dh_transport.cpp +++ b/services/distributedhardwarefwkservice/src/transport/dh_transport.cpp @@ -35,8 +35,9 @@ namespace DistributedHardware { #define DH_LOG_TAG "DHTransport" namespace { // Dsoftbus sendBytes max message length: 4MB -const uint32_t MAX_SEND_MSG_LENGTH = 4 * 1024 * 1024; -const uint32_t INTERCEPT_STRING_LENGTH = 20; +constexpr uint32_t MAX_SEND_MSG_LENGTH = 4 * 1024 * 1024; +constexpr uint32_t INTERCEPT_STRING_LENGTH = 20; +constexpr uint32_t MAX_ROUND_SIZE = 1000; const std::string DH_FWK_SESSION_NAME = "ohos.dhardware.session_"; static QosTV g_qosInfo[] = { { .qos = QOS_TYPE_MIN_BW, .value = 256 * 1024}, diff --git a/services/distributedhardwarefwkservice/src/utils/dh_timer.cpp b/services/distributedhardwarefwkservice/src/utils/dh_timer.cpp index 1f64626e..59a55b9b 100644 --- a/services/distributedhardwarefwkservice/src/utils/dh_timer.cpp +++ b/services/distributedhardwarefwkservice/src/utils/dh_timer.cpp @@ -120,8 +120,7 @@ void DHTimer::Execute() DHLOGE("eventHandler is nullptr!"); return; } - ExecuteInner(); - auto executeInnerFunc = [this] { Execute(); }; + auto executeInnerFunc = [this] { ExecuteInner(); }; eventHandler_->PostTask(executeInnerFunc, timerId_, delayTimeMs_); } } // namespace DistributedHardware diff --git a/services/distributedhardwarefwkservice/src/versionmanager/version_manager.cpp b/services/distributedhardwarefwkservice/src/versionmanager/version_manager.cpp index 4c6b9bfb..63a7b438 100644 --- a/services/distributedhardwarefwkservice/src/versionmanager/version_manager.cpp +++ b/services/distributedhardwarefwkservice/src/versionmanager/version_manager.cpp @@ -25,6 +25,9 @@ namespace OHOS { namespace DistributedHardware { #undef DH_LOG_TAG #define DH_LOG_TAG "VersionManager" + +const std::string DH_LOCAL_VERSION = "1.0"; + IMPLEMENT_SINGLE_INSTANCE(VersionManager); int32_t VersionManager::Init() diff --git a/services/distributedhardwarefwkservice/test/unittest/common/componentloader/src/component_loader_test.cpp b/services/distributedhardwarefwkservice/test/unittest/common/componentloader/src/component_loader_test.cpp index 4aaecdad..8c89ca08 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/componentloader/src/component_loader_test.cpp +++ b/services/distributedhardwarefwkservice/test/unittest/common/componentloader/src/component_loader_test.cpp @@ -450,17 +450,17 @@ HWTEST_F(ComponentLoaderTest, ParseResourceDesc_001, TestSize.Level1) CompConfig config; cJSON *component = cJSON_CreateObject(); ASSERT_TRUE(component != nullptr); - cJSON_AddNumberToObject(component, COMP_NAME.c_str(), 1); - cJSON_AddNumberToObject(component, COMP_TYPE.c_str(), 1); - cJSON_AddNumberToObject(component, COMP_HANDLER_LOC.c_str(), 1); - cJSON_AddNumberToObject(component, COMP_HANDLER_VERSION.c_str(), 1.0); - cJSON_AddNumberToObject(component, COMP_SOURCE_LOC.c_str(), 1); - cJSON_AddNumberToObject(component, COMP_SOURCE_VERSION.c_str(), 1.0); - cJSON_AddStringToObject(component, COMP_SOURCE_SA_ID.c_str(), "4801"); - cJSON_AddNumberToObject(component, COMP_SINK_LOC.c_str(), 1); - cJSON_AddNumberToObject(component, COMP_SINK_VERSION.c_str(), 1.0); - cJSON_AddStringToObject(component, COMP_SINK_SA_ID.c_str(), "4802"); - cJSON_AddStringToObject(component, COMP_RESOURCE_DESC.c_str(), "comp_resource_desc"); + cJSON_AddNumberToObject(component, COMP_NAME, 1); + cJSON_AddNumberToObject(component, COMP_TYPE, 1); + cJSON_AddNumberToObject(component, COMP_HANDLER_LOC, 1); + cJSON_AddNumberToObject(component, COMP_HANDLER_VERSION, 1.0); + cJSON_AddNumberToObject(component, COMP_SOURCE_LOC, 1); + cJSON_AddNumberToObject(component, COMP_SOURCE_VERSION, 1.0); + cJSON_AddStringToObject(component, COMP_SOURCE_SA_ID, "4801"); + cJSON_AddNumberToObject(component, COMP_SINK_LOC, 1); + cJSON_AddNumberToObject(component, COMP_SINK_VERSION, 1.0); + cJSON_AddStringToObject(component, COMP_SINK_SA_ID, "4802"); + cJSON_AddStringToObject(component, COMP_RESOURCE_DESC, "comp_resource_desc"); ComponentLoader::GetInstance().ParseCompConfigFromJson(component, config); cJSON_Delete(component); } @@ -470,17 +470,17 @@ HWTEST_F(ComponentLoaderTest, ParseResourceDesc_002, TestSize.Level1) CompConfig config1; cJSON *component1 = cJSON_CreateObject(); ASSERT_TRUE(component1 != nullptr); - cJSON_AddStringToObject(component1, COMP_NAME.c_str(), "comp_name_test"); - cJSON_AddStringToObject(component1, COMP_TYPE.c_str(), "comp_type_test"); - cJSON_AddStringToObject(component1, COMP_HANDLER_LOC.c_str(), "comp_handler_loc_test"); - cJSON_AddStringToObject(component1, COMP_HANDLER_VERSION.c_str(), "comp_handler_version_test"); - cJSON_AddStringToObject(component1, COMP_SOURCE_LOC.c_str(), "comp_source_loc_test"); - cJSON_AddStringToObject(component1, COMP_SOURCE_VERSION.c_str(), "comp_source_verison_test"); - cJSON_AddNumberToObject(component1, COMP_SOURCE_SA_ID.c_str(), 4801); - cJSON_AddStringToObject(component1, COMP_SINK_LOC.c_str(), "comp_sink_loc_test"); - cJSON_AddStringToObject(component1, COMP_SINK_VERSION.c_str(), "com_sink_version_test"); - cJSON_AddNumberToObject(component1, COMP_SINK_SA_ID.c_str(), 4802); - cJSON_AddStringToObject(component1, COMP_RESOURCE_DESC.c_str(), "comp_resource_desc"); + cJSON_AddStringToObject(component1, COMP_NAME, "comp_name_test"); + cJSON_AddStringToObject(component1, COMP_TYPE, "comp_type_test"); + cJSON_AddStringToObject(component1, COMP_HANDLER_LOC, "comp_handler_loc_test"); + cJSON_AddStringToObject(component1, COMP_HANDLER_VERSION, "comp_handler_version_test"); + cJSON_AddStringToObject(component1, COMP_SOURCE_LOC, "comp_source_loc_test"); + cJSON_AddStringToObject(component1, COMP_SOURCE_VERSION, "comp_source_verison_test"); + cJSON_AddNumberToObject(component1, COMP_SOURCE_SA_ID, 4801); + cJSON_AddStringToObject(component1, COMP_SINK_LOC, "comp_sink_loc_test"); + cJSON_AddStringToObject(component1, COMP_SINK_VERSION, "com_sink_version_test"); + cJSON_AddNumberToObject(component1, COMP_SINK_SA_ID, 4802); + cJSON_AddStringToObject(component1, COMP_RESOURCE_DESC, "comp_resource_desc"); ASSERT_NO_FATAL_FAILURE(ComponentLoader::GetInstance().ParseCompConfigFromJson(component1, config1)); cJSON_Delete(component1); } @@ -495,14 +495,14 @@ HWTEST_F(ComponentLoaderTest, ParseResourceDescFromJson_003, TestSize.Level1) cJSON_Delete(resourceDescs); return; } - cJSON_AddBoolToObject(sensitive, COMP_SENSITIVE.c_str(), true); + cJSON_AddBoolToObject(sensitive, COMP_SENSITIVE, true); cJSON_AddItemToArray(resourceDescs, sensitive); cJSON *subtype = cJSON_CreateObject(); if (subtype == nullptr) { cJSON_Delete(resourceDescs); return; } - cJSON_AddBoolToObject(subtype, COMP_SUBTYPE.c_str(), true); + cJSON_AddBoolToObject(subtype, COMP_SUBTYPE, true); cJSON_AddItemToArray(resourceDescs, subtype); ComponentLoader::GetInstance().ParseResourceDescFromJson(resourceDescs, config); cJSON_Delete(resourceDescs); diff --git a/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/include/mock_component_loader.h b/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/include/mock_component_loader.h index ff51be04..71b1a4d2 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/include/mock_component_loader.h +++ b/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/include/mock_component_loader.h @@ -30,7 +30,7 @@ public: virtual int32_t GetSink(const DHType dhType, IDistributedHardwareSink *&sinkPtr) = 0; virtual int32_t GetHardwareHandler(const DHType dhType, IHardwareHandler *&hardwareHandlerPtr) = 0; virtual int32_t ReleaseSink(const DHType dhType) = 0; - virtual std::vector GetAllCompTypes() = 0; + virtual void GetAllCompTypes(std::vector &dhTypeVec) = 0; virtual int32_t GetSource(const DHType dhType, IDistributedHardwareSource *&sourcePtr) = 0; virtual int32_t GetSourceSaId(const DHType dhType) = 0; virtual int32_t ReleaseSource(const DHType dhType) = 0; @@ -49,7 +49,7 @@ public: MOCK_METHOD(int32_t, GetSink, (const DHType, IDistributedHardwareSink *&)); MOCK_METHOD(int32_t, GetHardwareHandler, (const DHType, IHardwareHandler *&)); MOCK_METHOD(int32_t, ReleaseSink, (const DHType)); - MOCK_METHOD((std::vector), GetAllCompTypes, ()); + MOCK_METHOD(void, GetAllCompTypes, (std::vector &)); MOCK_METHOD(int32_t, GetSource, (const DHType, IDistributedHardwareSource *&)); MOCK_METHOD(int32_t, GetSourceSaId, (const DHType)); MOCK_METHOD(int32_t, ReleaseSource, (const DHType)); diff --git a/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/src/component_manager_test.cpp b/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/src/component_manager_test.cpp index ff606ed9..58f156c2 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/src/component_manager_test.cpp +++ b/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/src/component_manager_test.cpp @@ -348,8 +348,9 @@ HWTEST_F(ComponentManagerTest, StartSource_001, TestSize.Level1) DHType dhType = DHType::CAMERA; IDistributedHardwareSource *sourcePtr = nullptr; ComponentManager::GetInstance().compSource_.insert(std::make_pair(dhType, sourcePtr)); - auto ret = ComponentManager::GetInstance().StartSource(dhType); - EXPECT_EQ(true, ret.empty()); + std::unordered_map> sourceResult; + auto ret = ComponentManager::GetInstance().StartSource(dhType, sourceResult); + EXPECT_EQ(ERR_DH_FWK_SA_HANDLER_IS_NULL, ret); ComponentManager::GetInstance().compSource_.clear(); } @@ -364,11 +365,12 @@ HWTEST_F(ComponentManagerTest, StartSource_002, TestSize.Level1) DHType dhType = DHType::CAMERA; IDistributedHardwareSource *sourcePtr = nullptr; ComponentManager::GetInstance().compSource_.insert(std::make_pair(dhType, sourcePtr)); - auto ret = ComponentManager::GetInstance().StartSource(DHType::AUDIO); - EXPECT_EQ(true, ret.empty()); + std::unordered_map> sourceResult; + auto ret = ComponentManager::GetInstance().StartSource(DHType::AUDIO, sourceResult); + EXPECT_EQ(ERR_DH_FWK_TYPE_NOT_EXIST, ret); - ret = ComponentManager::GetInstance().StartSource(dhType); - EXPECT_EQ(true, ret.empty()); + ret = ComponentManager::GetInstance().StartSource(dhType, sourceResult); + EXPECT_EQ(ERR_DH_FWK_SA_HANDLER_IS_NULL, ret); ComponentManager::GetInstance().compSource_.clear(); } @@ -383,8 +385,9 @@ HWTEST_F(ComponentManagerTest, StartSink_001, TestSize.Level1) DHType dhType = DHType::CAMERA; IDistributedHardwareSink *sinkPtr = nullptr; ComponentManager::GetInstance().compSink_.insert(std::make_pair(dhType, sinkPtr)); - auto ret = ComponentManager::GetInstance().StartSink(dhType); - EXPECT_EQ(true, ret.empty()); + std::unordered_map> sinkResult; + auto ret = ComponentManager::GetInstance().StartSink(dhType, sinkResult); + EXPECT_EQ(ERR_DH_FWK_SA_HANDLER_IS_NULL, ret); ComponentManager::GetInstance().compSink_.clear(); } @@ -399,11 +402,11 @@ HWTEST_F(ComponentManagerTest, StopSource_001, TestSize.Level1) DHType dhType = DHType::CAMERA; IDistributedHardwareSource *sourcePtr = nullptr; ComponentManager::GetInstance().compSource_.insert(std::make_pair(dhType, sourcePtr)); - auto ret = ComponentManager::GetInstance().StopSource(dhType); - EXPECT_EQ(true, ret.empty()); + std::unordered_map> sourceResult; + auto ret = ComponentManager::GetInstance().StopSource(dhType, sourceResult); + EXPECT_EQ(ERR_DH_FWK_SA_HANDLER_IS_NULL, ret); ComponentManager::GetInstance().compSource_.clear(); } - /** * @tc.name: StopSink_001 * @tc.desc: Verify the StopSink function @@ -415,8 +418,9 @@ HWTEST_F(ComponentManagerTest, StopSink_001, TestSize.Level1) DHType dhType = DHType::CAMERA; IDistributedHardwareSink *sinkPtr = nullptr; ComponentManager::GetInstance().compSink_.insert(std::make_pair(dhType, sinkPtr)); - auto ret = ComponentManager::GetInstance().StopSink(dhType); - EXPECT_EQ(true, ret.empty()); + std::unordered_map> sinkResult; + auto ret = ComponentManager::GetInstance().StopSink(dhType, sinkResult); + EXPECT_EQ(ERR_DH_FWK_SA_HANDLER_IS_NULL, ret); ComponentManager::GetInstance().compSink_.clear(); } @@ -1142,10 +1146,10 @@ HWTEST_F(ComponentManagerTest, DisableSink_001, TestSize.Level1) .dhType = DHType::AUDIO }; auto ret = ComponentManager::GetInstance().DisableSink(dhDescriptor, 0, 0); - EXPECT_EQ(ret, DH_FWK_SUCCESS); + EXPECT_EQ(ret, ERR_DH_FWK_TYPE_NOT_EXIST); ret = ComponentManager::GetInstance().DisableSink(dhDescriptor, 0, 0); SetDownComponentLoaderConfig(); - EXPECT_EQ(ret, ERR_DH_FWK_COMPONENT_REPEAT_CALL); + EXPECT_EQ(ret, ERR_DH_FWK_TYPE_NOT_EXIST); } HWTEST_F(ComponentManagerTest, EnableSource_001, TestSize.Level1) @@ -1181,7 +1185,7 @@ HWTEST_F(ComponentManagerTest, ForceDisableSink_001, TestSize.Level1) SetUpComponentLoaderConfig(); auto ret = ComponentManager::GetInstance().ForceDisableSink(dhDescriptor); SetDownComponentLoaderConfig(); - EXPECT_EQ(ret, ERR_DH_FWK_LOADER_SINK_UNLOAD); + EXPECT_EQ(ret, ERR_DH_FWK_TYPE_NOT_EXIST); } HWTEST_F(ComponentManagerTest, ForceDisableSource_001, TestSize.Level1) @@ -1233,5 +1237,12 @@ HWTEST_F(ComponentManagerTest, OnStateChanged_001, testing::ext::TestSize.Level1 networkId = "networkId_test"; ASSERT_NO_FATAL_FAILURE(dhStateListenenr.OnStateChanged(networkId, dhId, state)); } + +HWTEST_F(ComponentManagerTest, CheckSinkConfigStart_001, TestSize.Level1) +{ + bool enableSink = false; + auto ret = ComponentManager::GetInstance().CheckSinkConfigStart(DHType::GPS, enableSink); + EXPECT_EQ(ret, ERR_DH_FWK_TYPE_NOT_EXIST); +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/src/component_manager_test_ext.cpp b/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/src/component_manager_test_ext.cpp index 227475c6..f6157c9c 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/src/component_manager_test_ext.cpp +++ b/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/src/component_manager_test_ext.cpp @@ -122,12 +122,9 @@ HWTEST_F(ComponentManagerTestExt, EnableSinkAndDisableSink_001, testing::ext::Te EXPECT_CALL(*dhContext_, GetDeviceInfo()).WillRepeatedly(ReturnRef(emptyInfo)); EXPECT_CALL(*versionManager_, GetCompVersion(_, _, _)).Times(AtLeast(1)); - std::vector types = { DHType::CAMERA }; auto sinkListener = sptr(new (std::nothrow) MockHDSinkStatusListenerStub()); - EXPECT_CALL(*sinkListener, OnEnable(_)).Times(AtLeast(1)); - EXPECT_CALL(*sinkListener, OnDisable(_)).Times(AtLeast(1)); - - EXPECT_CALL(*componentLoader_, GetAllCompTypes()).WillRepeatedly(Return(types)); + std::vector dhTypeVec; + EXPECT_CALL(*componentLoader_, GetAllCompTypes(dhTypeVec)).WillRepeatedly(Return()); ComponentManager::GetInstance().RegisterDHStatusListener(sinkListener, CAMERA_UID, CAMERA_PID); auto ret = ComponentManager::GetInstance().EnableSink(CAMERA_DESCRIPTOR, CAMERA_UID, CAMERA_PID); @@ -222,11 +219,9 @@ HWTEST_F(ComponentManagerTestExt, EnableSourceAndDisableSource_001, testing::ext ASSERT_TRUE(versionManager_ != nullptr); ASSERT_TRUE(utilTool_ != nullptr); - std::vector types = { DHType::CAMERA }; auto sourceListener = sptr(new (std::nothrow) MockHDSourceStatusListenerStub()); - EXPECT_CALL(*sourceListener, OnEnable(_, _)).Times(AtLeast(1)); - EXPECT_CALL(*sourceListener, OnDisable(_, _)).Times(AtLeast(1)); - EXPECT_CALL(*componentLoader_, GetAllCompTypes()).WillRepeatedly(Return(types)); + std::vector dhTypeVec; + EXPECT_CALL(*componentLoader_, GetAllCompTypes(dhTypeVec)).WillRepeatedly(Return()); ComponentManager::GetInstance().RegisterDHStatusListener(VALUABLE_DEVICE_INFO.networkId, sourceListener, CAMERA_UID, CAMERA_PID); @@ -524,12 +519,9 @@ HWTEST_F(ComponentManagerTestExt, EnableSinkAndForceDisableSink_001, testing::ex EXPECT_CALL(*dhContext_, GetDeviceInfo()).WillRepeatedly(ReturnRef(emptyInfo)); EXPECT_CALL(*versionManager_, GetCompVersion(_, _, _)).Times(AtLeast(1)); - std::vector types = { DHType::AUDIO }; auto sinkListener = sptr(new (std::nothrow) MockHDSinkStatusListenerStub()); - EXPECT_CALL(*sinkListener, OnEnable(_)).Times(AtLeast(1)); - EXPECT_CALL(*sinkListener, OnDisable(_)).Times(AtLeast(1)); - - EXPECT_CALL(*componentLoader_, GetAllCompTypes()).WillRepeatedly(Return(types)); + std::vector dhTypeVec; + EXPECT_CALL(*componentLoader_, GetAllCompTypes(dhTypeVec)).WillRepeatedly(Return()); ComponentManager::GetInstance().RegisterDHStatusListener(sinkListener, AUDIO_UID, AUDIO_PID); ComponentManager::GetInstance().EnableSink(AUDIO_DESCRIPTOR, AUDIO_UID, AUDIO_PID); @@ -567,11 +559,9 @@ HWTEST_F(ComponentManagerTestExt, EnableSourceAndForceDisableSource_001, testing ASSERT_TRUE(versionManager_ != nullptr); ASSERT_TRUE(utilTool_ != nullptr); - std::vector types = { DHType::AUDIO }; auto sourceListener = sptr(new (std::nothrow) MockHDSourceStatusListenerStub()); - EXPECT_CALL(*sourceListener, OnEnable(_, _)).Times(AtLeast(1)); - EXPECT_CALL(*sourceListener, OnDisable(_, _)).Times(AtLeast(1)); - EXPECT_CALL(*componentLoader_, GetAllCompTypes()).WillRepeatedly(Return(types)); + std::vector dhTypeVec; + EXPECT_CALL(*componentLoader_, GetAllCompTypes(dhTypeVec)).WillRepeatedly(Return()); ComponentManager::GetInstance().RegisterDHStatusListener(VALUABLE_DEVICE_INFO.networkId, sourceListener, AUDIO_UID, AUDIO_PID); @@ -810,48 +800,40 @@ HWTEST_F(ComponentManagerTestExt, CheckDemandStart_007, testing::ext::TestSize.L HWTEST_F(ComponentManagerTestExt, RegisterDHStatusListener_001, testing::ext::TestSize.Level1) { - std::vector types = { DHType::CAMERA }; sptr listener = nullptr; - EXPECT_CALL(*componentLoader_, GetAllCompTypes()).WillRepeatedly(Return(types)); + std::vector dhTypeVec; + EXPECT_CALL(*componentLoader_, GetAllCompTypes(dhTypeVec)).WillRepeatedly(Return()); auto ret = ComponentManager::GetInstance().RegisterDHStatusListener(listener, 0, 0); EXPECT_EQ(ret, DH_FWK_SUCCESS); - ret = ComponentManager::GetInstance().RegisterDHStatusListener(listener, 0, 0); - EXPECT_EQ(ret, ERR_DH_FWK_COMPONENT_REPEAT_CALL); } HWTEST_F(ComponentManagerTestExt, RegisterDHStatusListener_002, testing::ext::TestSize.Level1) { - std::vector types = { DHType::CAMERA }; sptr listener = nullptr; - EXPECT_CALL(*componentLoader_, GetAllCompTypes()).WillRepeatedly(Return(types)); + std::vector dhTypeVec; + EXPECT_CALL(*componentLoader_, GetAllCompTypes(dhTypeVec)).WillRepeatedly(Return()); auto ret = ComponentManager::GetInstance().RegisterDHStatusListener( VALUABLE_DEVICE_INFO.networkId, listener, 0, 0); EXPECT_EQ(ret, DH_FWK_SUCCESS); - ret = ComponentManager::GetInstance().RegisterDHStatusListener(VALUABLE_DEVICE_INFO.networkId, listener, 0, 0); - EXPECT_EQ(ret, ERR_DH_FWK_COMPONENT_REPEAT_CALL); } HWTEST_F(ComponentManagerTestExt, UnregisterDHStatusListener_001, testing::ext::TestSize.Level1) { - std::vector types = { DHType::CAMERA }; sptr listener = nullptr; - EXPECT_CALL(*componentLoader_, GetAllCompTypes()).WillRepeatedly(Return(types)); + std::vector dhTypeVec; + EXPECT_CALL(*componentLoader_, GetAllCompTypes(dhTypeVec)).WillRepeatedly(Return()); auto ret = ComponentManager::GetInstance().UnregisterDHStatusListener(listener, 0, 0); EXPECT_EQ(ret, DH_FWK_SUCCESS); - ret = ComponentManager::GetInstance().UnregisterDHStatusListener(listener, 0, 0); - EXPECT_EQ(ret, ERR_DH_FWK_COMPONENT_REPEAT_CALL); } HWTEST_F(ComponentManagerTestExt, UnregisterDHStatusListener_002, testing::ext::TestSize.Level1) { - std::vector types = { DHType::CAMERA }; sptr listener = nullptr; - EXPECT_CALL(*componentLoader_, GetAllCompTypes()).WillRepeatedly(Return(types)); + std::vector dhTypeVec; + EXPECT_CALL(*componentLoader_, GetAllCompTypes(dhTypeVec)).WillRepeatedly(Return()); auto ret = ComponentManager::GetInstance().UnregisterDHStatusListener( VALUABLE_DEVICE_INFO.networkId, listener, 0, 0); EXPECT_EQ(ret, DH_FWK_SUCCESS); - ret = ComponentManager::GetInstance().UnregisterDHStatusListener(VALUABLE_DEVICE_INFO.networkId, listener, 0, 0); - EXPECT_EQ(ret, ERR_DH_FWK_COMPONENT_REPEAT_CALL); } HWTEST_F(ComponentManagerTestExt, RealEnableSource_001, testing::ext::TestSize.Level1) diff --git a/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/src/mock_component_loader.cpp b/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/src/mock_component_loader.cpp index 12f8a0aa..b1142a09 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/src/mock_component_loader.cpp +++ b/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/src/mock_component_loader.cpp @@ -53,9 +53,9 @@ int32_t ComponentLoader::ReleaseSink(const DHType dhType) return IComponentLoader::GetOrCtreateInstance()->ReleaseSink(dhType); } -std::vector ComponentLoader::GetAllCompTypes() +void GetAllCompTypes(std::vector &dhTypeVec) { - return IComponentLoader::GetOrCtreateInstance()->GetAllCompTypes(); + IComponentLoader::GetOrCtreateInstance()->GetAllCompTypes(dhTypeVec); } int32_t ComponentLoader::GetSource(const DHType dhType, IDistributedHardwareSource *&sourcePtr) diff --git a/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_privacy/component_privacy_test.cpp b/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_privacy/component_privacy_test.cpp index 5ae63ba7..e23e86d0 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_privacy/component_privacy_test.cpp +++ b/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_privacy/component_privacy_test.cpp @@ -30,6 +30,10 @@ namespace { const std::string SUBTYPE_MIC = "mic"; const std::string SUBTYPE_CAMERA = "camera"; const std::string NETWORK_ID = "123456789"; + constexpr const char *PRIVACY_SUBTYPE = "subtype"; + constexpr const char *PRIVACY_NETWORKID = "networkId"; + constexpr uint32_t COMP_START_PAGE = 1; + constexpr uint32_t COMP_STOP_PAGE = 2; constexpr uint16_t DEVICE_TYPE_WIFI_CAMERA = 0x08; constexpr uint16_t DEVICE_TYPE_AUDIO = 0x0A; constexpr uint16_t DEVICE_TYPE_PC = 0x0C; @@ -163,8 +167,8 @@ HWTEST_F(ComponentPrivacyTest, ProcessEvent_001, TestSize.Level1) cJSON_Delete(jsonArrayMsg); return; } - cJSON_AddNumberToObject(tmpJson, PRIVACY_SUBTYPE.c_str(), 1); - cJSON_AddStringToObject(tmpJson, PRIVACY_NETWORKID.c_str(), NETWORK_ID.c_str()); + cJSON_AddNumberToObject(tmpJson, PRIVACY_SUBTYPE, 1); + cJSON_AddStringToObject(tmpJson, PRIVACY_NETWORKID, NETWORK_ID.c_str()); cJSON_AddItemToArray(jsonArrayMsg, tmpJson); AppExecFwk::InnerEvent::Pointer msgEvent = AppExecFwk::InnerEvent::Get(COMP_START_PAGE, std::shared_ptr(jsonArrayMsg, cJSON_Delete), 0); @@ -182,8 +186,8 @@ HWTEST_F(ComponentPrivacyTest, ProcessEvent_002, TestSize.Level1) cJSON_Delete(jsonArrayMsg); return; } - cJSON_AddStringToObject(tmpJson, PRIVACY_SUBTYPE.c_str(), SUBTYPE_MIC.c_str()); - cJSON_AddNumberToObject(tmpJson, PRIVACY_NETWORKID.c_str(), 1); + cJSON_AddStringToObject(tmpJson, PRIVACY_SUBTYPE, SUBTYPE_MIC.c_str()); + cJSON_AddNumberToObject(tmpJson, PRIVACY_NETWORKID, 1); cJSON_AddItemToArray(jsonArrayMsg, tmpJson); AppExecFwk::InnerEvent::Pointer msgEvent = AppExecFwk::InnerEvent::Get(COMP_START_PAGE, std::shared_ptr(jsonArrayMsg, cJSON_Delete), 0); @@ -201,8 +205,8 @@ HWTEST_F(ComponentPrivacyTest, ProcessEvent_003, TestSize.Level1) cJSON_Delete(jsonArrayMsg); return; } - cJSON_AddStringToObject(tmpJson, PRIVACY_SUBTYPE.c_str(), SUBTYPE_MIC.c_str()); - cJSON_AddStringToObject(tmpJson, PRIVACY_NETWORKID.c_str(), NETWORK_ID.c_str()); + cJSON_AddStringToObject(tmpJson, PRIVACY_SUBTYPE, SUBTYPE_MIC.c_str()); + cJSON_AddStringToObject(tmpJson, PRIVACY_NETWORKID, NETWORK_ID.c_str()); cJSON_AddItemToArray(jsonArrayMsg, tmpJson); AppExecFwk::InnerEvent::Pointer msgEvent = AppExecFwk::InnerEvent::Get(COMP_START_PAGE, std::shared_ptr(jsonArrayMsg, cJSON_Delete), 0); @@ -220,8 +224,8 @@ HWTEST_F(ComponentPrivacyTest, ProcessEvent_004, TestSize.Level1) cJSON_Delete(jsonArrayMsg); return; } - cJSON_AddStringToObject(tmpJson, PRIVACY_SUBTYPE.c_str(), SUBTYPE_CAMERA.c_str()); - cJSON_AddStringToObject(tmpJson, PRIVACY_NETWORKID.c_str(), NETWORK_ID.c_str()); + cJSON_AddStringToObject(tmpJson, PRIVACY_SUBTYPE, SUBTYPE_CAMERA.c_str()); + cJSON_AddStringToObject(tmpJson, PRIVACY_NETWORKID, NETWORK_ID.c_str()); cJSON_AddItemToArray(jsonArrayMsg, tmpJson); AppExecFwk::InnerEvent::Pointer msgEvent = AppExecFwk::InnerEvent::Get(COMP_START_PAGE, std::shared_ptr(jsonArrayMsg, cJSON_Delete), 0); @@ -239,7 +243,7 @@ HWTEST_F(ComponentPrivacyTest, ProcessEvent_005, TestSize.Level1) cJSON_Delete(jsonArrayMsg); return; } - cJSON_AddNumberToObject(tmpJson, PRIVACY_SUBTYPE.c_str(), 1); + cJSON_AddNumberToObject(tmpJson, PRIVACY_SUBTYPE, 1); cJSON_AddItemToArray(jsonArrayMsg, tmpJson); AppExecFwk::InnerEvent::Pointer msgEvent = AppExecFwk::InnerEvent::Get(COMP_STOP_PAGE, std::shared_ptr(jsonArrayMsg, cJSON_Delete), 0); @@ -257,7 +261,7 @@ HWTEST_F(ComponentPrivacyTest, ProcessEvent_006, TestSize.Level1) cJSON_Delete(jsonArrayMsg); return; } - cJSON_AddStringToObject(tmpJson, PRIVACY_SUBTYPE.c_str(), SUBTYPE_CAMERA.c_str()); + cJSON_AddStringToObject(tmpJson, PRIVACY_SUBTYPE, SUBTYPE_CAMERA.c_str()); cJSON_AddItemToArray(jsonArrayMsg, tmpJson); AppExecFwk::InnerEvent::Pointer msgEvent = AppExecFwk::InnerEvent::Get(COMP_STOP_PAGE, std::shared_ptr(jsonArrayMsg, cJSON_Delete), 0); @@ -275,7 +279,7 @@ HWTEST_F(ComponentPrivacyTest, ProcessEvent_007, TestSize.Level1) cJSON_Delete(jsonArrayMsg); return; } - cJSON_AddStringToObject(tmpJson, PRIVACY_SUBTYPE.c_str(), SUBTYPE_MIC.c_str()); + cJSON_AddStringToObject(tmpJson, PRIVACY_SUBTYPE, SUBTYPE_MIC.c_str()); cJSON_AddItemToArray(jsonArrayMsg, tmpJson); AppExecFwk::InnerEvent::Pointer msgEvent = AppExecFwk::InnerEvent::Get(COMP_STOP_PAGE, std::shared_ptr(jsonArrayMsg, cJSON_Delete), 0); diff --git a/services/distributedhardwarefwkservice/test/unittest/common/dbadapter/src/db_adapter_test.cpp b/services/distributedhardwarefwkservice/test/unittest/common/dbadapter/src/db_adapter_test.cpp index c9e5184d..eb770bbe 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/dbadapter/src/db_adapter_test.cpp +++ b/services/distributedhardwarefwkservice/test/unittest/common/dbadapter/src/db_adapter_test.cpp @@ -39,6 +39,7 @@ namespace DistributedHardware { #define DH_LOG_TAG "DbAdapterTest" namespace { +constexpr const char *GLOBAL_CAPABILITY_INFO_KEY = "global_capability_info"; const string DATABASE_DIR = "/data/service/el1/public/database/dtbhardware_manager_service/"; const std::string DEV_NETWORK_ID_1 = "nt36a637105409e904d4da83790a4a9"; const string TEST_DEV_ID_0 = "bb536a637105409e904d4da83791aa11"; @@ -101,7 +102,7 @@ void DbAdapterTest::SetUpTestCase(void) DHLOGE("mkdir failed, path: %{public}s, errno : %{public}d", DATABASE_DIR.c_str(), errno); } std::shared_ptr changeListener = std::make_shared(); - g_dbAdapterPtr = std::make_shared(APP_ID, GLOBAL_CAPABILITY_ID, changeListener); + g_dbAdapterPtr = std::make_shared(APP_ID, GLOBAL_CAPABILITY_INFO_KEY, changeListener); if (g_dbAdapterPtr != nullptr) { g_dbAdapterPtr->Init(true, DistributedKv::DataType::TYPE_DYNAMICAL); } diff --git a/services/distributedhardwarefwkservice/test/unittest/common/task/include/mock_component_manager.h b/services/distributedhardwarefwkservice/test/unittest/common/task/include/mock_component_manager.h index dc95fa36..b4427578 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/task/include/mock_component_manager.h +++ b/services/distributedhardwarefwkservice/test/unittest/common/task/include/mock_component_manager.h @@ -34,6 +34,7 @@ public: virtual int32_t DisableSink(const DHDescriptor &dhDescriptor, int32_t callingUid, int32_t callingPid) = 0; virtual int32_t DisableSource(const std::string &networkId, const DHDescriptor &dhDescriptor, int32_t callingUid, int32_t callingPid) = 0; + virtual int32_t CheckSinkConfigStart(const DHType dhType, bool &enableSink) = 0; static std::shared_ptr GetOrCtreateInstance(); static void ReleaseInstance(); @@ -51,6 +52,7 @@ public: MOCK_METHOD(int32_t, EnableSource, (const std::string&, const DHDescriptor&, int32_t, int32_t)); MOCK_METHOD(int32_t, DisableSink, (const DHDescriptor&, int32_t, int32_t)); MOCK_METHOD(int32_t, DisableSource, (const std::string&, const DHDescriptor&, int32_t, int32_t)); + MOCK_METHOD(int32_t, CheckSinkConfigStart, (const DHType, bool&)); }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/distributedhardwarefwkservice/test/unittest/common/task/src/enable_task_test.cpp b/services/distributedhardwarefwkservice/test/unittest/common/task/src/enable_task_test.cpp index 6b36e6db..b6c71181 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/task/src/enable_task_test.cpp +++ b/services/distributedhardwarefwkservice/test/unittest/common/task/src/enable_task_test.cpp @@ -71,7 +71,7 @@ HWTEST_F(EnableTaskTest, RegisterHardware_001, TestSize.Level0) TASK_PARAM_1.dhId, TASK_PARAM_1.dhType); EXPECT_CALL(*componentManager_, CheckDemandStart(_, _, _)).Times(1).WillRepeatedly( DoAll(SetArgReferee<2>(false), Return(0))); - ASSERT_EQ(enableTask->RegisterHardware(), ERR_DH_FWK_COMPONENT_LIMIT_DEMAND_START); + ASSERT_EQ(enableTask->RegisterHardware(), ERR_DH_FWK_COMPONENT_NO_NEED_ENABLE); } /** @@ -130,8 +130,8 @@ HWTEST_F(EnableTaskTest, RegisterHardware_005, TestSize.Level0) { auto enableTask = std::make_shared(TASK_PARAM_1.networkId, TASK_PARAM_1.uuid, GetLocalUdid(), TASK_PARAM_1.dhId, TASK_PARAM_1.dhType); - EXPECT_CALL(*componentManager_, EnableSink(_, _, _)).Times(1).WillRepeatedly(Return(0)); - ASSERT_EQ(enableTask->RegisterHardware(), 0); + EXPECT_CALL(*componentManager_, CheckSinkConfigStart(_, _)).Times(1).WillRepeatedly(Return(0)); + ASSERT_EQ(enableTask->RegisterHardware(), ERR_DH_FWK_COMPONENT_NO_NEED_ENABLE); } /** @@ -144,6 +144,7 @@ HWTEST_F(EnableTaskTest, RegisterHardware_006, TestSize.Level0) { auto enableTask = std::make_shared(TASK_PARAM_1.networkId, TASK_PARAM_1.uuid, GetLocalUdid(), TASK_PARAM_1.dhId, TASK_PARAM_1.dhType); + EXPECT_CALL(*componentManager_, CheckSinkConfigStart(_, _)).WillOnce(DoAll(SetArgReferee<1>(true), Return(0))); EXPECT_CALL(*componentManager_, EnableSink(_, _, _)).Times(1).WillRepeatedly(Return(1)); ASSERT_EQ(enableTask->RegisterHardware(), 1); } diff --git a/services/distributedhardwarefwkservice/test/unittest/common/task/src/mock_component_manager.cpp b/services/distributedhardwarefwkservice/test/unittest/common/task/src/mock_component_manager.cpp index ba35cf18..98ff5a64 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/task/src/mock_component_manager.cpp +++ b/services/distributedhardwarefwkservice/test/unittest/common/task/src/mock_component_manager.cpp @@ -74,5 +74,10 @@ int32_t ComponentManager::DisableSource(const std::string &networkId, { return IComponentManager::GetOrCtreateInstance()->DisableSource(networkId, dhDescriptor, callingUid, callingPid); } + +int32_t ComponentManager::CheckSinkConfigStart(const DHType dhType, bool &enableSink) +{ + return IComponentManager::GetOrCtreateInstance()->CheckSinkConfigStart(dhType, enableSink); +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/distributedhardwarefwkservice/test/unittest/common/transport/dh_comm_tool_test.cpp b/services/distributedhardwarefwkservice/test/unittest/common/transport/dh_comm_tool_test.cpp index 430a1eb5..be7796c6 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/transport/dh_comm_tool_test.cpp +++ b/services/distributedhardwarefwkservice/test/unittest/common/transport/dh_comm_tool_test.cpp @@ -31,6 +31,10 @@ namespace OHOS { namespace DistributedHardware { using namespace std; constexpr uint16_t TEST_DEV_TYPE = 0x14; +// request remote dh send back full dh capabilities +constexpr int32_t DH_COMM_REQ_FULL_CAPS = 1; +// send back full dh attributes to the requester +constexpr int32_t DH_COMM_RSP_FULL_CAPS = 2; class DhCommToolTest : public testing::Test { public: diff --git a/services/distributedhardwarefwkservice/test/unittest/common/versioninfomanager/include/version_info_manager_test.h b/services/distributedhardwarefwkservice/test/unittest/common/versioninfomanager/include/version_info_manager_test.h index 05710af1..99ee8e94 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/versioninfomanager/include/version_info_manager_test.h +++ b/services/distributedhardwarefwkservice/test/unittest/common/versioninfomanager/include/version_info_manager_test.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 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 @@ -35,7 +35,7 @@ public: class MockDBAdapter : public DBAdapter { public: -MockDBAdapter(const std::string &appId, const std::string &storeId, +MockDBAdapter(const char *appId, const char *storeId, const std::shared_ptr changeListener) : DBAdapter(appId, storeId, changeListener) {} diff --git a/services/distributedhardwarefwkservice/test/unittest/common/versioninfomanager/src/version_info_manager_test.cpp b/services/distributedhardwarefwkservice/test/unittest/common/versioninfomanager/src/version_info_manager_test.cpp index f23e3930..8ce4aa40 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/versioninfomanager/src/version_info_manager_test.cpp +++ b/services/distributedhardwarefwkservice/test/unittest/common/versioninfomanager/src/version_info_manager_test.cpp @@ -259,7 +259,8 @@ HWTEST_F(VersionInfoManagerTest, RemoveVersionInfoByDeviceId_002, TestSize.Level std::string appId; std::string storeId; std::shared_ptr changeListener = nullptr; - VersionInfoManager::GetInstance()->dbAdapterPtr_ = std::make_shared(appId, storeId, changeListener); + VersionInfoManager::GetInstance()->dbAdapterPtr_ = + std::make_shared(appId.c_str(), storeId.c_str(), changeListener); int32_t ret = VersionInfoManager::GetInstance()->RemoveVersionInfoByDeviceId(deviceId); EXPECT_EQ(ERR_DH_FWK_RESOURCE_DB_ADAPTER_OPERATION_FAIL, ret); } @@ -295,7 +296,8 @@ HWTEST_F(VersionInfoManagerTest, SyncVersionInfoFromDB_002, TestSize.Level1) std::string appId; std::string storeId; std::shared_ptr changeListener = nullptr; - VersionInfoManager::GetInstance()->dbAdapterPtr_ = std::make_shared(appId, storeId, changeListener); + VersionInfoManager::GetInstance()->dbAdapterPtr_ = + std::make_shared(appId.c_str(), storeId.c_str(), changeListener); int32_t ret = VersionInfoManager::GetInstance()->SyncVersionInfoFromDB(deviceId); EXPECT_EQ(ERR_DH_FWK_RESOURCE_DB_ADAPTER_OPERATION_FAIL, ret); } @@ -341,7 +343,8 @@ HWTEST_F(VersionInfoManagerTest, SyncRemoteVersionInfos_002, TestSize.Level1) std::string appId; std::string storeId; std::shared_ptr changeListener = nullptr; - VersionInfoManager::GetInstance()->dbAdapterPtr_ = std::make_shared(appId, storeId, changeListener); + VersionInfoManager::GetInstance()->dbAdapterPtr_ = + std::make_shared(appId.c_str(), storeId.c_str(), changeListener); int32_t ret = VersionInfoManager::GetInstance()->SyncRemoteVersionInfos(); EXPECT_EQ(DH_FWK_SUCCESS, ret); } diff --git a/services/distributedhardwarefwkservice/test/unittest/common/versionmanager/src/version_manager_test.cpp b/services/distributedhardwarefwkservice/test/unittest/common/versionmanager/src/version_manager_test.cpp index c92e256f..cb2f0b2f 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/versionmanager/src/version_manager_test.cpp +++ b/services/distributedhardwarefwkservice/test/unittest/common/versionmanager/src/version_manager_test.cpp @@ -54,6 +54,7 @@ const std::string TEST_DH_VERSION = "3.1"; const std::string TEST_COMPONENT_NAME_1 = "distributed_camera"; const std::string TEST_COMPONENT_NAME_2 = "distributed_audio"; const std::string TEST_COMPONENT_NAME_3 = "distributed_mic"; +const std::string DH_LOCAL_VERSION = "1.0"; } /** diff --git a/utils/src/device_param_mgr.cpp b/utils/src/device_param_mgr.cpp index f11dfdcf..7987af6f 100644 --- a/utils/src/device_param_mgr.cpp +++ b/utils/src/device_param_mgr.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-2025 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 @@ -22,7 +22,7 @@ namespace OHOS { namespace DistributedHardware { namespace { - const int32_t BUF_LENTH = 128; + constexpr int32_t BUF_LENTH = 128; const char *SYNC_TYPE_E2E = "1"; const char *DATA_SYNC_PARAM = "persist.distributed_scene.sys_settings_data_sync"; } diff --git a/utils/src/dh_utils_tool.cpp b/utils/src/dh_utils_tool.cpp index 31d45646..b13ba102 100644 --- a/utils/src/dh_utils_tool.cpp +++ b/utils/src/dh_utils_tool.cpp @@ -38,6 +38,13 @@ namespace OHOS { namespace DistributedHardware { namespace { + constexpr uint32_t MAX_MESSAGE_LEN = 40 * 1024 * 1024; + constexpr uint32_t MIN_MESSAGE_LEN = 0; + constexpr uint32_t MAX_ID_LEN = 256; + constexpr uint32_t MAX_ARR_SIZE = 10000; + constexpr uint32_t MAX_JSON_SIZE = 40 * 1024 * 1024; + constexpr uint32_t MAX_HASH_SIZE = 64; + constexpr uint32_t MAX_KEY_SIZE = 256; constexpr int32_t MS_ONE_SECOND = 1000; constexpr int32_t WORD_WIDTH_8 = 8; constexpr int32_t WORD_WIDTH_4 = 4; @@ -45,7 +52,7 @@ namespace { constexpr unsigned char MASK = 0x0F; constexpr int32_t DOUBLE_TIMES = 2; constexpr int32_t COMPRESS_SLICE_SIZE = 1024; - const std::string PARAM_KEY_OS_TYPE = "OS_TYPE"; + constexpr const char *PARAM_KEY_OS_TYPE = "OS_TYPE"; } int64_t GetCurrentTime() @@ -357,7 +364,7 @@ int32_t GetDeviceSystemType(const std::string &extraData) DHLOGE("jsonStr parse failed"); return ERR_DH_FWK_INVALID_OSTYPE; } - cJSON *paramKey = cJSON_GetObjectItem(jsonObj, PARAM_KEY_OS_TYPE.c_str()); + cJSON *paramKey = cJSON_GetObjectItem(jsonObj, PARAM_KEY_OS_TYPE); if (paramKey == NULL || !cJSON_IsNumber(paramKey)) { DHLOGE("paramKey is null or paramKey is invaild type!"); cJSON_Delete(jsonObj); diff --git a/utils/src/histreamer_ability_parser.cpp b/utils/src/histreamer_ability_parser.cpp index 732a83a7..8c6368e6 100644 --- a/utils/src/histreamer_ability_parser.cpp +++ b/utils/src/histreamer_ability_parser.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Copyright (c) 2023-2025 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 @@ -20,20 +20,20 @@ namespace OHOS { namespace DistributedHardware { - -static const std::string NAME = "name"; -static const std::string INS = "ins"; -static const std::string OUTS = "outs"; -static const std::string MIME = "mime"; -static const std::string SAMPLE_RATE = "sample_rate"; -static const std::string AUDIO_SAMPLE_FORMAT = "sample_fmt"; -static const std::string AD_MPEG_VER = "ad_mpeg_ver"; -static const std::string AUDIO_AAC_PROFILE = "aac_profile"; -static const std::string AUDIO_AAC_STREAM_FORMAT = "aac_stm_fmt"; -static const std::string AUDIO_CHANNEL_LAYOUT = "channel_layout"; - -static const std::string VIDEO_PIXEL_FMT = "pixel_fmt"; -static const std::string VIDEO_BIT_STREAM_FMT = "vd_bit_stream_fmt"; +namespace { + constexpr const char *NAME = "name"; + constexpr const char *INS = "ins"; + constexpr const char *OUTS = "outs"; + constexpr const char *MIME = "mime"; + constexpr const char *SAMPLE_RATE = "sample_rate"; + constexpr const char *AUDIO_SAMPLE_FORMAT = "sample_fmt"; + constexpr const char *AD_MPEG_VER = "ad_mpeg_ver"; + constexpr const char *AUDIO_AAC_PROFILE = "aac_profile"; + constexpr const char *AUDIO_AAC_STREAM_FORMAT = "aac_stream_fmt"; + constexpr const char *AUDIO_CHANNEL_LAYOUT = "channel_layout"; + constexpr const char *VIDEO_PIXEL_FMT = "pixel_fmt"; + constexpr const char *VIDEO_BIT_STREAM_FMT = "vd_bit_stream_fmt"; +} void FromJson(const cJSON *jsonObject, AudioEncoderIn &audioEncoderIn) { @@ -41,14 +41,14 @@ void FromJson(const cJSON *jsonObject, AudioEncoderIn &audioEncoderIn) DHLOGE("Json pointer is nullptr!"); return; } - cJSON *mimeJsonObj = cJSON_GetObjectItem(jsonObject, MIME.c_str()); + cJSON *mimeJsonObj = cJSON_GetObjectItem(jsonObject, MIME); if (!IsString(mimeJsonObj)) { DHLOGE("AudioEncoderIn MIME is invalid!"); return; } audioEncoderIn.mime = mimeJsonObj->valuestring; - cJSON *sampleRate = cJSON_GetObjectItem(jsonObject, SAMPLE_RATE.c_str()); + cJSON *sampleRate = cJSON_GetObjectItem(jsonObject, SAMPLE_RATE); if (!IsArray(sampleRate)) { DHLOGE("AudioEncoderIn SAMPLE_RATE is invalid!"); return; @@ -67,28 +67,28 @@ void FromJson(const cJSON *jsonObject, AudioEncoderOut &audioEncoderOut) DHLOGE("Json pointer is nullptr!"); return; } - cJSON *mimeJsonObj = cJSON_GetObjectItem(jsonObject, MIME.c_str()); + cJSON *mimeJsonObj = cJSON_GetObjectItem(jsonObject, MIME); if (!IsString(mimeJsonObj)) { DHLOGE("AudioEncoderOut MIME is invalid!"); return; } audioEncoderOut.mime = mimeJsonObj->valuestring; - cJSON *mpegVerJsonObj = cJSON_GetObjectItem(jsonObject, AD_MPEG_VER.c_str()); + cJSON *mpegVerJsonObj = cJSON_GetObjectItem(jsonObject, AD_MPEG_VER); if (!IsUInt32(mpegVerJsonObj)) { DHLOGE("AudioEncoderOut AD_MPEG_VER is invalid!"); return; } audioEncoderOut.ad_mpeg_ver = static_cast(mpegVerJsonObj->valuedouble); - cJSON *aacProfileJsonObj = cJSON_GetObjectItem(jsonObject, AUDIO_AAC_PROFILE.c_str()); + cJSON *aacProfileJsonObj = cJSON_GetObjectItem(jsonObject, AUDIO_AAC_PROFILE); if (!IsUInt8(aacProfileJsonObj)) { DHLOGE("AudioEncoderOut AUDIO_AAC_PROFILE is invalid!"); return; } audioEncoderOut.aac_profile = (AudioAacProfile)aacProfileJsonObj->valuedouble; - cJSON *aacStreamFmtJsonObj = cJSON_GetObjectItem(jsonObject, AUDIO_AAC_STREAM_FORMAT.c_str()); + cJSON *aacStreamFmtJsonObj = cJSON_GetObjectItem(jsonObject, AUDIO_AAC_STREAM_FORMAT); if (!IsUInt8(aacStreamFmtJsonObj)) { DHLOGE("AudioEncoderOut AUDIO_AAC_STREAM_FORMAT is invalid!"); return; @@ -102,14 +102,14 @@ void FromJson(const cJSON *jsonObject, AudioEncoder &audioEncoder) DHLOGE("Json pointer is nullptr!"); return; } - cJSON *nameJsonObj = cJSON_GetObjectItem(jsonObject, NAME.c_str()); + cJSON *nameJsonObj = cJSON_GetObjectItem(jsonObject, NAME); if (!IsString(nameJsonObj)) { DHLOGE("AudioEncoder NAME is invalid!"); return; } audioEncoder.name = nameJsonObj->valuestring; - cJSON *insJson = cJSON_GetObjectItem(jsonObject, INS.c_str()); + cJSON *insJson = cJSON_GetObjectItem(jsonObject, INS); if (!IsArray(insJson)) { DHLOGE("AudioEncoder INS is invalid!"); return; @@ -121,7 +121,7 @@ void FromJson(const cJSON *jsonObject, AudioEncoder &audioEncoder) audioEncoder.ins.push_back(in); } - cJSON *outsJson = cJSON_GetObjectItem(jsonObject, OUTS.c_str()); + cJSON *outsJson = cJSON_GetObjectItem(jsonObject, OUTS); if (!IsArray(outsJson)) { DHLOGE("AudioEncoder OUTS is invalid!"); return; @@ -140,14 +140,14 @@ void FromJson(const cJSON *jsonObject, AudioDecoderIn &audioDecoderIn) DHLOGE("Json pointer is nullptr!"); return; } - cJSON *mimeJsonObj = cJSON_GetObjectItem(jsonObject, MIME.c_str()); + cJSON *mimeJsonObj = cJSON_GetObjectItem(jsonObject, MIME); if (!IsString(mimeJsonObj)) { DHLOGE("AudioDecoderIn MIME is invalid!"); return; } audioDecoderIn.mime = mimeJsonObj->valuestring; - cJSON *channelLayoutJson = cJSON_GetObjectItem(jsonObject, AUDIO_CHANNEL_LAYOUT.c_str()); + cJSON *channelLayoutJson = cJSON_GetObjectItem(jsonObject, AUDIO_CHANNEL_LAYOUT); if (!IsArray(channelLayoutJson)) { DHLOGE("AudioDecoder AUDIO_CHANNEL_LAYOUT is invalid!"); return; @@ -166,14 +166,14 @@ void FromJson(const cJSON *jsonObject, AudioDecoderOut &audioDecoderOut) DHLOGE("Json pointer is nullptr!"); return; } - cJSON *mimeJsonObj = cJSON_GetObjectItem(jsonObject, MIME.c_str()); + cJSON *mimeJsonObj = cJSON_GetObjectItem(jsonObject, MIME); if (!IsString(mimeJsonObj)) { DHLOGE("AudioDecoderOut MIME is invalid!"); return; } audioDecoderOut.mime = mimeJsonObj->valuestring; - cJSON *sampleFormatJson = cJSON_GetObjectItem(jsonObject, AUDIO_SAMPLE_FORMAT.c_str()); + cJSON *sampleFormatJson = cJSON_GetObjectItem(jsonObject, AUDIO_SAMPLE_FORMAT); if (!IsArray(sampleFormatJson)) { DHLOGE("AudioDecoderOut AUDIO_SAMPLE_FORMAT is invalid!"); return; @@ -192,14 +192,14 @@ void FromJson(const cJSON *jsonObject, AudioDecoder &audioDecoder) DHLOGE("Json pointer is nullptr!"); return; } - cJSON *nameJsonObj = cJSON_GetObjectItem(jsonObject, NAME.c_str()); + cJSON *nameJsonObj = cJSON_GetObjectItem(jsonObject, NAME); if (!IsString(nameJsonObj)) { DHLOGE("AudioDecoderOut MIME is invalid!"); return; } audioDecoder.name = nameJsonObj->valuestring; - cJSON *insJson = cJSON_GetObjectItem(jsonObject, INS.c_str()); + cJSON *insJson = cJSON_GetObjectItem(jsonObject, INS); if (!IsArray(insJson)) { DHLOGE("AudioDecoder INS is invalid!"); return; @@ -211,7 +211,7 @@ void FromJson(const cJSON *jsonObject, AudioDecoder &audioDecoder) audioDecoder.ins.push_back(in); } - cJSON *outsJson = cJSON_GetObjectItem(jsonObject, OUTS.c_str()); + cJSON *outsJson = cJSON_GetObjectItem(jsonObject, OUTS); if (!IsArray(outsJson)) { DHLOGE("AudioDecoder OUTS is invalid!"); return; @@ -230,14 +230,14 @@ void FromJson(const cJSON *jsonObject, VideoEncoderIn &videoEncoderIn) DHLOGE("Json pointer is nullptr!"); return; } - cJSON *mimeJsonObj = cJSON_GetObjectItem(jsonObject, MIME.c_str()); + cJSON *mimeJsonObj = cJSON_GetObjectItem(jsonObject, MIME); if (!IsString(mimeJsonObj)) { DHLOGE("VideoEncoderIn MIME is invalid!"); return; } videoEncoderIn.mime = mimeJsonObj->valuestring; - cJSON *videoPixelFmt = cJSON_GetObjectItem(jsonObject, VIDEO_PIXEL_FMT.c_str()); + cJSON *videoPixelFmt = cJSON_GetObjectItem(jsonObject, VIDEO_PIXEL_FMT); if (!IsArray(videoPixelFmt)) { DHLOGE("VideoEncoderIn VIDEO_PIXEL_FMT is invalid!"); return; @@ -256,7 +256,7 @@ void FromJson(const cJSON *jsonObject, VideoEncoderOut &videoEncoderOut) DHLOGE("Json pointer is nullptr!"); return; } - cJSON *mimeJsonObj = cJSON_GetObjectItem(jsonObject, MIME.c_str()); + cJSON *mimeJsonObj = cJSON_GetObjectItem(jsonObject, MIME); if (!IsString(mimeJsonObj)) { DHLOGE("VideoEncoderOut MIME is invalid!"); return; @@ -270,14 +270,14 @@ void FromJson(const cJSON *jsonObject, VideoEncoder &videoEncoder) DHLOGE("Json pointer is nullptr!"); return; } - cJSON *nameJsonObj = cJSON_GetObjectItem(jsonObject, NAME.c_str()); + cJSON *nameJsonObj = cJSON_GetObjectItem(jsonObject, NAME); if (!IsString(nameJsonObj)) { DHLOGE("VideoEncoder NAME is invalid!"); return; } videoEncoder.name = nameJsonObj->valuestring; - cJSON *videoEncoderInsJson = cJSON_GetObjectItem(jsonObject, INS.c_str()); + cJSON *videoEncoderInsJson = cJSON_GetObjectItem(jsonObject, INS); if (!IsArray(videoEncoderInsJson)) { DHLOGE("VideoEncoder INS is invalid!"); return; @@ -289,7 +289,7 @@ void FromJson(const cJSON *jsonObject, VideoEncoder &videoEncoder) videoEncoder.ins.push_back(in); } - cJSON *videoEncoderOutsJson = cJSON_GetObjectItem(jsonObject, OUTS.c_str()); + cJSON *videoEncoderOutsJson = cJSON_GetObjectItem(jsonObject, OUTS); if (!IsArray(videoEncoderOutsJson)) { DHLOGE("VideoEncoder OUTS is invalid!"); return; @@ -308,14 +308,14 @@ void FromJson(const cJSON *jsonObject, VideoDecoderIn &videoDecoderIn) DHLOGE("Json pointer is nullptr!"); return; } - cJSON *mimeJsonObj = cJSON_GetObjectItem(jsonObject, MIME.c_str()); + cJSON *mimeJsonObj = cJSON_GetObjectItem(jsonObject, MIME); if (!IsString(mimeJsonObj)) { DHLOGE("VideoDecoderIn MIME is invalid!"); return; } videoDecoderIn.mime = mimeJsonObj->valuestring; - cJSON *videoBitStreamFmtJson = cJSON_GetObjectItem(jsonObject, VIDEO_BIT_STREAM_FMT.c_str()); + cJSON *videoBitStreamFmtJson = cJSON_GetObjectItem(jsonObject, VIDEO_BIT_STREAM_FMT); if (!IsArray(videoBitStreamFmtJson)) { DHLOGE("VideoDecoderIn VIDEO_BIT_STREAM_FMT is invalid!"); return; @@ -334,14 +334,14 @@ void FromJson(const cJSON *jsonObject, VideoDecoderOut &videoDecoderOut) DHLOGE("Json pointer is nullptr!"); return; } - cJSON *mimeJsonObj = cJSON_GetObjectItem(jsonObject, MIME.c_str()); + cJSON *mimeJsonObj = cJSON_GetObjectItem(jsonObject, MIME); if (!IsString(mimeJsonObj)) { DHLOGE("VideoDecoderOut MIME is invalid!"); return; } videoDecoderOut.mime = mimeJsonObj->valuestring; - cJSON *videoPixelFmtJson = cJSON_GetObjectItem(jsonObject, VIDEO_PIXEL_FMT.c_str()); + cJSON *videoPixelFmtJson = cJSON_GetObjectItem(jsonObject, VIDEO_PIXEL_FMT); if (!IsArray(videoPixelFmtJson)) { DHLOGE("videoDecoderOut VIDEO_PIXEL_FMT is invalid!"); return; @@ -360,14 +360,14 @@ void FromJson(const cJSON *jsonObject, VideoDecoder &videoDecoder) DHLOGE("Json pointer is nullptr!"); return; } - cJSON *nameJsonObj = cJSON_GetObjectItem(jsonObject, NAME.c_str()); + cJSON *nameJsonObj = cJSON_GetObjectItem(jsonObject, NAME); if (!IsString(nameJsonObj)) { DHLOGE("VideoDecoder NAME is invalid!"); return; } videoDecoder.name = nameJsonObj->valuestring; - cJSON *videoDecoderInsJson = cJSON_GetObjectItem(jsonObject, INS.c_str()); + cJSON *videoDecoderInsJson = cJSON_GetObjectItem(jsonObject, INS); if (!IsArray(videoDecoderInsJson)) { DHLOGE("VideoDecoder INS is invalid!"); return; @@ -379,7 +379,7 @@ void FromJson(const cJSON *jsonObject, VideoDecoder &videoDecoder) videoDecoder.ins.push_back(in); } - cJSON *videoDecoderOutsJson = cJSON_GetObjectItem(jsonObject, OUTS.c_str()); + cJSON *videoDecoderOutsJson = cJSON_GetObjectItem(jsonObject, OUTS); if (!IsArray(videoDecoderOutsJson)) { DHLOGE("VideoDecoder OUTS is invalid!"); return; diff --git a/utils/src/histreamer_query_tool.cpp b/utils/src/histreamer_query_tool.cpp index 1815edf6..2931515c 100644 --- a/utils/src/histreamer_query_tool.cpp +++ b/utils/src/histreamer_query_tool.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Copyright (c) 2023-2025 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 @@ -33,14 +33,13 @@ QueryAudioDecoderFunc queryAudioDecoderFunc = nullptr; QueryVideoEncoderFunc queryVideoEncoderFunc = nullptr; QueryVideoDecoderFunc queryVideoDecoderFunc = nullptr; -const std::string QueryAudioEncoderFuncName = "QueryAudioEncoderAbilityStr"; -const std::string QueryAudioDecoderFuncName = "QueryAudioDecoderAbilityStr"; -const std::string QueryVideoEncoderFuncName = "QueryVideoEncoderAbilityStr"; -const std::string QueryVideoDecoderFuncName = "QueryVideoDecoderAbilityStr"; +constexpr const char *QUERY_AUDIO_ENCODER_FUNC_NAME = "QueryAudioEncoderAbilityStr"; +constexpr const char *QUERY_AUDIO_DECODER_FUNC_NAME = "QueryAudioDecoderAbilityStr"; +constexpr const char *QUERY_VIDEO_ENCODER_FUNC_NAME = "QueryVideoEncoderAbilityStr"; +constexpr const char *QUERY_VIDEO_DECODER_FUNC_NAME = "QueryVideoDecoderAbilityStr"; +constexpr const char *LOAD_SO = "libhistreamer_ability_querier.z.so"; -const uint32_t MAX_MESSAGES_LEN = 1 * 1024 * 1024; - -const std::string LOAD_SO = "libhistreamer_ability_querier.z.so"; +constexpr uint32_t MAX_MESSAGES_LEN = 1 * 1024 * 1024; void HiStreamerQueryTool::Init() { @@ -48,14 +47,13 @@ void HiStreamerQueryTool::Init() return; } DHLOGI("Start Init HiStreamer Query SO"); - void *pHandler = dlopen(LOAD_SO.c_str(), RTLD_LAZY | RTLD_NODELETE); + void *pHandler = dlopen(LOAD_SO, RTLD_LAZY | RTLD_NODELETE); if (pHandler == nullptr) { DHLOGE("libhistreamer_ability_querier.z.so handler load failed, failed reason : %{public}s", dlerror()); return; } - queryAudioEncoderFunc = (QueryAudioEncoderFunc)dlsym(pHandler, - QueryAudioEncoderFuncName.c_str()); + queryAudioEncoderFunc = (QueryAudioEncoderFunc)dlsym(pHandler, QUERY_AUDIO_ENCODER_FUNC_NAME); if (queryAudioEncoderFunc == nullptr) { DHLOGE("get QueryAudioEncoderAbilityStr is null, failed reason : %{public}s", dlerror()); dlclose(pHandler); @@ -63,8 +61,7 @@ void HiStreamerQueryTool::Init() return; } - queryAudioDecoderFunc = (QueryAudioDecoderFunc)dlsym(pHandler, - QueryAudioDecoderFuncName.c_str()); + queryAudioDecoderFunc = (QueryAudioDecoderFunc)dlsym(pHandler, QUERY_AUDIO_DECODER_FUNC_NAME); if (queryAudioDecoderFunc == nullptr) { DHLOGE("get QueryAudioDecoderAbilityStr is null, failed reason : %{public}s", dlerror()); dlclose(pHandler); @@ -72,8 +69,7 @@ void HiStreamerQueryTool::Init() return; } - queryVideoEncoderFunc = (QueryVideoEncoderFunc)dlsym(pHandler, - QueryVideoEncoderFuncName.c_str()); + queryVideoEncoderFunc = (QueryVideoEncoderFunc)dlsym(pHandler, QUERY_VIDEO_ENCODER_FUNC_NAME); if (queryVideoEncoderFunc == nullptr) { DHLOGE("get QueryVideoEncoderAbilityStr is null, failed reason : %{public}s", dlerror()); dlclose(pHandler); @@ -81,8 +77,7 @@ void HiStreamerQueryTool::Init() return; } - queryVideoDecoderFunc = (QueryVideoDecoderFunc)dlsym(pHandler, - QueryVideoDecoderFuncName.c_str()); + queryVideoDecoderFunc = (QueryVideoDecoderFunc)dlsym(pHandler, QUERY_VIDEO_DECODER_FUNC_NAME); if (queryVideoDecoderFunc == nullptr) { DHLOGE("get QueryVideoDecoderAbilityStr is null, failed reason : %{public}s", dlerror()); dlclose(pHandler); -- Gitee