From 81585ca2057eb9595ecc7ed4941f493587eca20b Mon Sep 17 00:00:00 2001 From: cloud_nine Date: Tue, 30 Jan 2024 21:12:45 +0800 Subject: [PATCH] =?UTF-8?q?fixed=202413d51=20from=20https://gitee.com/clou?= =?UTF-8?q?d=5Fnine/window=5Fwindow=5Fmanager/pulls/4931=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8DgetDefaultDisplaySync=E6=8E=A5=E5=8F=A3=E5=9B=A0?= =?UTF-8?q?=E6=97=B6=E5=BA=8F=E5=AF=BC=E8=87=B4=E7=9A=84js=20error=20Signe?= =?UTF-8?q?d-off-by:=20chenyunjiu=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dm/src/display_manager.cpp | 18 ++++++++++++++++-- .../display_runtime/js_display_manager.cpp | 2 +- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/dm/src/display_manager.cpp b/dm/src/display_manager.cpp index 6ad1e8bf94..7fde140119 100644 --- a/dm/src/display_manager.cpp +++ b/dm/src/display_manager.cpp @@ -30,6 +30,8 @@ namespace OHOS::Rosen { namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "DisplayManager"}; + const static uint32_t MAX_RETRY_NUM = 6; + const static uint32_t RETRY_WAIT_MS = 500; const static uint32_t MAX_DISPLAY_SIZE = 32; const static uint32_t MAX_INTERVAL_US = 5000; } @@ -471,10 +473,22 @@ sptr DisplayManager::Impl::GetDefaultDisplaySync() } } - auto displayInfo = SingletonContainer::Get().GetDefaultDisplayInfo(); - if (displayInfo == nullptr) { + uint32_t retryTimes = 0; + sptr displayInfo = nullptr; + while (retryTimes < MAX_RETRY_NUM) { + displayInfo = SingletonContainer::Get().GetDefaultDisplayInfo(); + if (displayInfo != nullptr) { + break; + } + retryTimes++; + WLOGFW("Current get display info is null, retry %{public}u times", retryTimes); + std::this_thread::sleep_for(std::chrono::microseconds(RETRY_WAIT_MS)); + } + if (retryTimes >= MAX_RETRY_NUM || displayInfo == nullptr) { + WLOGFE("Get display info failed, please check whether the onscreenchange event is triggered"); return nullptr; } + auto displayId = displayInfo->GetDisplayId(); std::lock_guard lock(mutex_); if (!UpdateDisplayInfoLocked(displayInfo)) { diff --git a/interfaces/kits/napi/display_runtime/js_display_manager.cpp b/interfaces/kits/napi/display_runtime/js_display_manager.cpp index b63937b998..27923222e7 100644 --- a/interfaces/kits/napi/display_runtime/js_display_manager.cpp +++ b/interfaces/kits/napi/display_runtime/js_display_manager.cpp @@ -175,7 +175,7 @@ napi_value OnGetDefaultDisplaySync(napi_env env, napi_callback_info info) HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "Sync:GetDefaultDisplay"); sptr display = SingletonContainer::Get().GetDefaultDisplaySync(); if (display == nullptr) { - WLOGFE("OnGetDefaultDisplaySync, display is nullptr."); + WLOGFE("[NAPI]Display info is nullptr, js error will be happen"); napi_throw(env, CreateJsError(env, static_cast(DmErrorCode::DM_ERROR_INVALID_SCREEN))); return NapiGetUndefined(env); } -- Gitee