diff --git a/frameworks/inner_api/el5filekeymanager/include/el5_filekey_manager_client.h b/frameworks/inner_api/el5filekeymanager/include/el5_filekey_manager_client.h index 7c20df1cbfa218c5ff56e6ffc104120a87b313a3..4f1333c9363cf2492ad60c751f097d7d098818ab 100644 --- a/frameworks/inner_api/el5filekeymanager/include/el5_filekey_manager_client.h +++ b/frameworks/inner_api/el5filekeymanager/include/el5_filekey_manager_client.h @@ -23,6 +23,7 @@ namespace OHOS { namespace Security { namespace AccessToken { +constexpr int32_t DEFAULT_SA_REQUEST_RETRY_TIMES = 1; class El5FilekeyManagerClient { public: static El5FilekeyManagerClient &GetInstance(); @@ -37,7 +38,7 @@ public: int32_t SetFilePathPolicy(); int32_t RegisterCallback(const sptr &callback); int32_t CallProxyWithRetry(const std::function &)> &func, - const char *funcName, int32_t def = EFM_ERR_REMOTE_CONNECTION); + const char *funcName, int32_t retryTimes = DEFAULT_SA_REQUEST_RETRY_TIMES); bool IsRequestNeedRetry(int32_t ret); private: diff --git a/interfaces/inner_api/el5filekeymanager/src/el5_filekey_manager_client.cpp b/interfaces/inner_api/el5filekeymanager/src/el5_filekey_manager_client.cpp index 31ed08fd358e2cb340243758ba20c6337769cd22..10f1aa6d347e54fb36e5060e885dec13db0bd8b1 100644 --- a/interfaces/inner_api/el5filekeymanager/src/el5_filekey_manager_client.cpp +++ b/interfaces/inner_api/el5filekeymanager/src/el5_filekey_manager_client.cpp @@ -28,7 +28,7 @@ namespace AccessToken { namespace { constexpr int32_t LOAD_SA_TIMEOUT_SECOND = 4; constexpr int32_t LOAD_SA_RETRY_TIMES = 5; -static const int32_t SA_REQUEST_RETRY_TIMES = 1; +constexpr int32_t SA_REQUEST_RETRY_TIMES = 3; static const int32_t SENDREQ_FAIL_ERR = 32; static const std::vector RETRY_CODE_LIST = { BR_DEAD_REPLY, BR_FAILED_REPLY, SENDREQ_FAIL_ERR }; } @@ -80,7 +80,7 @@ int32_t El5FilekeyManagerClient::GetUserAppKey(int32_t userId, bool getAllFlag, std::function &)> func = [&](sptr &proxy) { return proxy->GetUserAppKey(userId, getAllFlag, keyInfos); }; - return CallProxyWithRetry(func, __FUNCTION__, EFM_SUCCESS); + return CallProxyWithRetry(func, __FUNCTION__, SA_REQUEST_RETRY_TIMES); } int32_t El5FilekeyManagerClient::ChangeUserAppkeysLoadInfo(int32_t userId, @@ -137,7 +137,7 @@ sptr El5FilekeyManagerClient::GetProxy() } int32_t El5FilekeyManagerClient::CallProxyWithRetry( - const std::function &)> &func, const char *funcName, int32_t def) + const std::function &)> &func, const char *funcName, int32_t retryTimes) { LOG_INFO("call proxy with retry function:%s", funcName); auto proxy = GetProxy(); @@ -151,7 +151,7 @@ int32_t El5FilekeyManagerClient::CallProxyWithRetry( LOG_WARN("First try call %{public}s failed, proxy is NULL. Begin retry.", funcName); } - for (int32_t i = 0; i < SA_REQUEST_RETRY_TIMES; i++) { + for (int32_t i = 0; i < retryTimes; i++) { proxy = GetProxy(); if (proxy == nullptr) { LOG_WARN("Get proxy %{public}s failed, retry time = %{public}d.", funcName, i); @@ -163,8 +163,8 @@ int32_t El5FilekeyManagerClient::CallProxyWithRetry( } LOG_WARN("Call %{public}s failed, retry time = %{public}d, result = %{public}d", funcName, i, ret); } - LOG_ERROR("Retry call service %{public}s error, tried %{public}d times.", funcName, SA_REQUEST_RETRY_TIMES); - return def; + LOG_ERROR("Retry call service %{public}s error, tried %{public}d times.", funcName, retryTimes); + return EFM_ERR_REMOTE_CONNECTION; } bool El5FilekeyManagerClient::IsRequestNeedRetry(int32_t ret)