From 61e55e0261667fd74c1fd882dc9ca2cfaac4f881 Mon Sep 17 00:00:00 2001 From: zhuofan0129 <861080528@qq.com> Date: Thu, 11 Sep 2025 22:40:53 +0800 Subject: [PATCH] feat: add load promise timeout Signed-off-by: zhuofan0129 <861080528@qq.com> --- .../src/standard/device_security_level_loader.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/interfaces/inner_api/src/standard/device_security_level_loader.cpp b/interfaces/inner_api/src/standard/device_security_level_loader.cpp index 70b3767..b9e25fa 100644 --- a/interfaces/inner_api/src/standard/device_security_level_loader.cpp +++ b/interfaces/inner_api/src/standard/device_security_level_loader.cpp @@ -26,6 +26,8 @@ #include "device_security_level_defines.h" #include "idevice_security_level.h" +constexpr uint32_t MAX_LOAD_TIMEOUT = 30; + namespace OHOS { namespace Security { namespace DeviceSecurityLevel { @@ -70,7 +72,13 @@ void DeviceSecurityLevelLoader::LoadCallback::OnLoadSystemAbilityFail(int32_t si sptr DeviceSecurityLevelLoader::LoadCallback::Promise() { - return promise_.get_future().get(); + std::future> future = promise_.get_future(); + if (future.wait_for(std::chrono::seconds(MAX_LOAD_TIMEOUT)) == std::future_status::timeout) { + HILOG_ERROR(LOG_CORE, "DeviceSecurityLevelLoader loadCallback timeout error."); + return nullptr; + } + + return future.get(); } } // namespace DeviceSecurityLevel } // namespace Security -- Gitee