diff --git a/services/distributedhardwarefwkserviceimpl/src/componentmanager/component_manager.cpp b/services/distributedhardwarefwkserviceimpl/src/componentmanager/component_manager.cpp index 0e4271a97545a6d7b4eb697295a3cde000de741e..7b86679e67054a5ff07bf7bdb0e06713868eab6b 100644 --- a/services/distributedhardwarefwkserviceimpl/src/componentmanager/component_manager.cpp +++ b/services/distributedhardwarefwkserviceimpl/src/componentmanager/component_manager.cpp @@ -43,6 +43,7 @@ IMPLEMENT_SINGLE_INSTANCE(ComponentManager); namespace { constexpr int32_t ENABLE_RETRY_MAX_TIMES = 30; constexpr int32_t DISABLE_RETRY_MAX_TIMES = 30; + constexpr int32_t ENABLE_PARAM_RETRY_TIME = 500 * 1000; } ComponentManager::~ComponentManager() @@ -221,18 +222,30 @@ int32_t ComponentManager::Enable(const std::string &networkId, const std::string if (ret != DH_FWK_SUCCESS) { DHLOGE("GetEnableParam failed, uuid = %s, dhId = %s, errCode = %d", GetAnonyString(uuid).c_str(), dhId.c_str(), ret); - return ret; + for (int32_t retryCount = 0; retryCount < ENABLE_RETRY_MAX_TIMES; retryCount++) { + if (!DHContext::GetInstance().IsDeviceOnline(uuid)) { + DHLOGE("device is already offline, no need try GetEnableParam, uuid = %s", + GetAnonyString(uuid).c_str()); + return ret; + } + if (GetEnableParam(networkId, uuid, dhId, dhType, param) == DH_FWK_SUCCESS) { + DHLOGE("GetEnableParam success, retryCount = %d", retryCount); + break; + } + DHLOGE("GetEnableParam failed, retryCount = %d", retryCount); + usleep(ENABLE_PARAM_RETRY_TIME); + } } auto compEnable = std::make_shared(); auto result = compEnable->Enable(networkId, dhId, param, find->second); if (result != DH_FWK_SUCCESS) { - for (int retryCount = 0; retryCount < ENABLE_RETRY_MAX_TIMES; retryCount++) { + for (int32_t retryCount = 0; retryCount < ENABLE_RETRY_MAX_TIMES; retryCount++) { if (!DHContext::GetInstance().IsDeviceOnline(uuid)) { - DHLOGW("device is already offline, no need try enable, uuid = %s", GetAnonyString(uuid).c_str()); + DHLOGE("device is already offline, no need try enable, uuid = %s", GetAnonyString(uuid).c_str()); return result; } if (compEnable->Enable(networkId, dhId, param, find->second) == DH_FWK_SUCCESS) { - DHLOGI("enable success, retryCount = %d", retryCount); + DHLOGE("enable success, retryCount = %d", retryCount); return DH_FWK_SUCCESS; } DHLOGE("enable failed, retryCount = %d", retryCount); @@ -254,13 +267,13 @@ int32_t ComponentManager::Disable(const std::string &networkId, const std::strin auto compDisable = std::make_shared(); auto result = compDisable->Disable(networkId, dhId, find->second); if (result != DH_FWK_SUCCESS) { - for (int retryCount = 0; retryCount < DISABLE_RETRY_MAX_TIMES; retryCount++) { + for (int32_t retryCount = 0; retryCount < DISABLE_RETRY_MAX_TIMES; retryCount++) { if (DHContext::GetInstance().IsDeviceOnline(uuid)) { - DHLOGW("device is already online, no need try disable, uuid = %s", GetAnonyString(uuid).c_str()); + DHLOGE("device is already online, no need try disable, uuid = %s", GetAnonyString(uuid).c_str()); return result; } if (compDisable->Disable(networkId, dhId, find->second) == DH_FWK_SUCCESS) { - DHLOGI("disable success, retryCount = %d", retryCount); + DHLOGE("disable success, retryCount = %d", retryCount); return DH_FWK_SUCCESS; } DHLOGE("disable failed, retryCount = %d", retryCount);