diff --git a/interfaces/inner_api/appexecfwk_base/include/appexecfwk_errors.h b/interfaces/inner_api/appexecfwk_base/include/appexecfwk_errors.h index ae6ba815b4791daa05e02f0a6a59d79cf1f66d7a..e32d33ddd39c829a952a8d1de7afe944a0107431 100644 --- a/interfaces/inner_api/appexecfwk_base/include/appexecfwk_errors.h +++ b/interfaces/inner_api/appexecfwk_base/include/appexecfwk_errors.h @@ -139,6 +139,7 @@ enum { ERR_APPEXECFWK_INSTALL_FAILED_CHECK_HAP_HASH_PARAM = 8519758, ERR_BUNDLEMANAGER_INSTALL_FAILED_SIGNATURE_EXTENSION_NOT_EXISTED = 8519759, ERR_APPEXECFWK_INSTALL_CHECK_ENCRYPTION_FAILED = 8519760, + ERR_APPEXECFWK_INSTALLD_SERVICE_DIED = 8519761, ERR_APPEXECFWK_INSTALL_ENTERPRISE_BUNDLE_NOT_ALLOWED = 8519780, ERR_APPEXECFWK_INSTALL_SELF_UPDATE_NOT_MDM = 8519781, diff --git a/services/bundlemgr/include/installd_client.h b/services/bundlemgr/include/installd_client.h index f9e866b1534ce3394f43717f86d707288b1d2374..0603943e8dc7b78f68bc319c3c392f9a8d56d667 100644 --- a/services/bundlemgr/include/installd_client.h +++ b/services/bundlemgr/include/installd_client.h @@ -24,6 +24,7 @@ #include "nocopyable.h" #include "singleton.h" +#include "app_log_wrapper.h" #include "appexecfwk_errors.h" #include "bundle_constants.h" #include "ipc/installd_interface.h" @@ -242,10 +243,26 @@ private: template ErrCode CallService(F func, Args&&... args) { - if (!GetInstalldProxy()) { - return ERR_APPEXECFWK_INSTALLD_GET_PROXY_ERROR; + int32_t maxRetryTimes = 2; + ErrCode errCode = ERR_APPEXECFWK_INSTALLD_SERVICE_DIED; + for (int32_t retryTimes = 0; retryTimes < maxRetryTimes; retryTimes++) { + if (!GetInstalldProxy()) { + return ERR_APPEXECFWK_INSTALLD_GET_PROXY_ERROR; + } + { + std::lock_guard lock(mutex_); + if (installdProxy_ != nullptr) { + errCode = (installdProxy_->*func)(std::forward(args)...); + } + } + if (errCode == ERR_APPEXECFWK_INSTALLD_SERVICE_DIED) { + APP_LOGE("CallService failed, retry times: %{public}d", retryTimes + 1); + ResetInstalldProxy(); + } else { + return errCode; + } } - return (installdProxy_->*func)(std::forward(args)...); + return errCode; } private: diff --git a/services/bundlemgr/src/installd_client.cpp b/services/bundlemgr/src/installd_client.cpp index afc112ab325c93c77d5ff4a913bdf4204cef1f5a..9af2371ef9045cccddfd318a63d278470b14bfd9 100644 --- a/services/bundlemgr/src/installd_client.cpp +++ b/services/bundlemgr/src/installd_client.cpp @@ -15,7 +15,6 @@ #include "installd_client.h" -#include "app_log_wrapper.h" #include "bundle_constants.h" #include "if_system_ability_manager.h" #include "installd/installd_load_callback.h" diff --git a/services/bundlemgr/src/ipc/installd_proxy.cpp b/services/bundlemgr/src/ipc/installd_proxy.cpp index 7f4bcaed85d74a91d01c77c97e1444f3344166c7..2f9001705aba47dc289259b6bd8fa698b79a139d 100644 --- a/services/bundlemgr/src/ipc/installd_proxy.cpp +++ b/services/bundlemgr/src/ipc/installd_proxy.cpp @@ -907,7 +907,7 @@ ErrCode InstalldProxy::TransactInstalldCmd(InstalldInterfaceCode code, MessagePa if (remote->SendRequest(static_cast(code), data, reply, option) != OHOS::NO_ERROR) { LOG_E(BMS_TAG_INSTALLD, "fail to send %{public}u request to service due to transact error", code); - return ERR_APPEXECFWK_INSTALL_INSTALLD_SERVICE_ERROR; + return ERR_APPEXECFWK_INSTALLD_SERVICE_DIED; } return reply.ReadInt32(); }