From 29d6c15e748bfe25acc142bf89e00e329bea35a6 Mon Sep 17 00:00:00 2001 From: z30053694 Date: Tue, 19 Mar 2024 11:21:50 +0800 Subject: [PATCH] fix: retry getting display id Change-Id: Ia1992f467fed06240cbba93158a983c4b768e8b0 Signed-off-by: z30053694 --- .../native/src/display_power_mgr_service.cpp | 26 +++++++++---------- .../service/native/src/screen_action.cpp | 4 --- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/state_manager/service/native/src/display_power_mgr_service.cpp b/state_manager/service/native/src/display_power_mgr_service.cpp index 5f48105..dfbd5e9 100644 --- a/state_manager/service/native/src/display_power_mgr_service.cpp +++ b/state_manager/service/native/src/display_power_mgr_service.cpp @@ -41,9 +41,9 @@ namespace { DisplayParamHelper::BootCompletedCallback g_bootCompletedCallback; FFRTHandle g_screenOffDelayTaskHandle; const uint32_t GET_DISPLAY_ID_DELAY_MS = 50; +const uint32_t US_PER_MS = 1000; const uint32_t GET_DISPLAY_ID_RETRY_COUNT = 3; const uint32_t DEFALUT_DISPLAY_ID = 0; -uint32_t g_getDisplayIdRetryCount = 0; } const uint32_t DisplayPowerMgrService::BRIGHTNESS_MIN = DisplayParamHelper::GetMinBrightness(); @@ -55,19 +55,19 @@ DisplayPowerMgrService::DisplayPowerMgrService() = default; void DisplayPowerMgrService::Init() { queue_ = std::make_shared ("display_power_mgr_service"); - if (queue_ == nullptr) { - return; - } DISPLAY_HILOGI(COMP_SVC, "DisplayPowerMgrService Create"); - std::vector displayIds = ScreenAction::GetAllDisplayId(); - uint32_t retryCount = GET_DISPLAY_ID_RETRY_COUNT; - if (displayIds.empty()) { - if (g_getDisplayIdRetryCount < GET_DISPLAY_ID_RETRY_COUNT) { - DISPLAY_HILOGI(COMP_SVC, "cannot find any display id, retry!"); - g_getDisplayIdRetryCount++; - FFRTTask task = [this]() { Init(); }; - FFRTUtils::SubmitDelayTask(task, GET_DISPLAY_ID_DELAY_MS, queue_); - return; + std::vector displayIds; + for (int tryCount = 0; tryCount <= GET_DISPLAY_ID_RETRY_COUNT; tryCount++) { + displayIds = ScreenAction::GetAllDisplayId(); + if (!displayIds.empty()) { + break; + } + if (tryCount < GET_DISPLAY_ID_RETRY_COUNT) { + usleep(GET_DISPLAY_ID_DELAY_MS * US_PER_MS); + DISPLAY_HILOGI(COMP_SVC, "cannot find any display id, retry! count: %{public}u", tryCount + 1); + } else { + displayIds.emplace_back(DEFALUT_DISPLAY_ID); + DISPLAY_HILOGE(COMP_SVC, "cannot find any display id after max retry, fill with 0"); } } for (const auto& id: displayIds) { diff --git a/state_manager/service/native/src/screen_action.cpp b/state_manager/service/native/src/screen_action.cpp index 0f5662f..7e366c8 100644 --- a/state_manager/service/native/src/screen_action.cpp +++ b/state_manager/service/native/src/screen_action.cpp @@ -43,10 +43,6 @@ std::vector ScreenAction::GetAllDisplayId() std::vector allIds = Rosen::DisplayManager::GetInstance().GetAllDisplayIds(); IPCSkeleton::SetCallingIdentity(identity); std::vector displayIds; - if (allIds.empty()) { - displayIds.push_back(DEFAULT_DISPLAY_ID); - return displayIds; - } std::transform(allIds.begin(), allIds.end(), back_inserter(displayIds), [](uint64_t id) { return static_cast(id); }); -- Gitee