diff --git a/services/security_component_service/sa/sa_main/window_info_helper.cpp b/services/security_component_service/sa/sa_main/window_info_helper.cpp index 059d58351cdb3002ef4ffa884828bc0e14f1d7ca..2ac0c66f27a4907189d141e64aee534c7433c608 100644 --- a/services/security_component_service/sa/sa_main/window_info_helper.cpp +++ b/services/security_component_service/sa/sa_main/window_info_helper.cpp @@ -14,10 +14,10 @@ */ #include "window_info_helper.h" +#include #include #include "sec_comp_info_helper.h" #include "sec_comp_log.h" -#include "window_manager.h" namespace OHOS { namespace Security { @@ -26,32 +26,52 @@ namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_SECURITY_COMPONENT, "WindowInfoHelper"}; constexpr int32_t INVALID_WINDOW_LAYER = -1; constexpr uint32_t UI_EXTENSION_MASK = 0x40000000; +static constexpr int32_t GET_WINDOW_WAITTIME_MILLISECONDS = 1; // 1ms +static constexpr int32_t GET_WINDOW_REPEAT_TIMES = 10; } -Scales WindowInfoHelper::GetWindowScale(int32_t windowId, bool& isCompatScaleMode, SecCompRect& scaleRect) +bool WindowInfoHelper::TryGetWindowInfo(int32_t windowId, sptr& windowInfo) { - Scales scales; - scales.floatingScale = FULL_SCREEN_SCALE; std::vector> infos; if (Rosen::WindowManager::GetInstance().GetAccessibilityWindowInfo(infos) != Rosen::WMError::WM_OK) { SC_LOG_ERROR(LABEL, "Get AccessibilityWindowInfo failed"); - return scales; + return false; } auto iter = std::find_if(infos.begin(), infos.end(), [windowId](const sptr info) { return windowId == info->wid_; }); if ((iter == infos.end()) || (*iter == nullptr)) { + return false; + } + windowInfo = *iter; + return true; +} + +Scales WindowInfoHelper::GetWindowScale(int32_t windowId, bool& isCompatScaleMode, SecCompRect& scaleRect) +{ + Scales scales; + scales.floatingScale = FULL_SCREEN_SCALE; + auto sleepTime = std::chrono::milliseconds(GET_WINDOW_WAITTIME_MILLISECONDS); + sptr windowInfo = nullptr; + int32_t i = 0; + for (i = 0; i < GET_WINDOW_REPEAT_TIMES; ++i) { + if (TryGetWindowInfo(windowId, windowInfo)) { + break; + } + std::this_thread::sleep_for(sleepTime); + } + if ((i >= GET_WINDOW_REPEAT_TIMES) || (windowInfo == nullptr)) { SC_LOG_WARN(LABEL, "Cannot find AccessibilityWindowInfo, return default scale"); return scales; } - isCompatScaleMode = (*iter)->isCompatScaleMode_; - scales.floatingScale = (*iter)->scaleVal_; - scales.scaleX = (*iter)->scaleX_; - scales.scaleY = (*iter)->scaleY_; - scaleRect.x_ = (*iter)->scaleRect_.posX_; - scaleRect.y_ = (*iter)->scaleRect_.posY_; - scaleRect.width_ = (*iter)->scaleRect_.width_; - scaleRect.height_ = (*iter)->scaleRect_.height_; + isCompatScaleMode = windowInfo->isCompatScaleMode_; + scales.floatingScale = windowInfo->scaleVal_; + scales.scaleX = windowInfo->scaleX_; + scales.scaleY = windowInfo->scaleY_; + scaleRect.x_ = windowInfo->scaleRect_.posX_; + scaleRect.y_ = windowInfo->scaleRect_.posY_; + scaleRect.width_ = windowInfo->scaleRect_.width_; + scaleRect.height_ = windowInfo->scaleRect_.height_; SC_LOG_INFO(LABEL, "Get floatingScale = %{public}f, scaleX = %{public}f, scaleY = %{public}f, \ isCompatScaleMode = %{public}d", scales.floatingScale, scales.scaleX, scales.scaleY, isCompatScaleMode); return scales; diff --git a/services/security_component_service/sa/sa_main/window_info_helper.h b/services/security_component_service/sa/sa_main/window_info_helper.h index 272c518e6b9e9ab35a36966c65237e3af02d975c..98e49ee1289731db5870b3e16625db6282fbfbb5 100644 --- a/services/security_component_service/sa/sa_main/window_info_helper.h +++ b/services/security_component_service/sa/sa_main/window_info_helper.h @@ -17,12 +17,14 @@ #include #include "sec_comp_info.h" +#include "window_manager.h" namespace OHOS { namespace Security { namespace SecurityComponent { class __attribute__((visibility("default"))) WindowInfoHelper { public: + static bool TryGetWindowInfo(int32_t windowId, sptr& windowInfo); static Scales GetWindowScale(int32_t windowId, bool& isCompatScaleMode, SecCompRect& scaleRect); static bool CheckOtherWindowCoverComp(int32_t compWinId, const SecCompRect& secRect, std::string& message); public: