From 566ca6a0aa958ba4b4889a21fe4e60012915a960 Mon Sep 17 00:00:00 2001 From: AXYChen Date: Tue, 2 Sep 2025 22:38:50 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8E=B7=E5=8F=96=E7=AA=97=E5=8F=A3=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E5=A2=9E=E5=8A=A0=E9=87=8D=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: AXYChen Change-Id: I6912f0c338a8c14a669f75b81be8ba4549ef3e5c --- .../sa/sa_main/window_info_helper.cpp | 46 +++++++++++++------ .../sa/sa_main/window_info_helper.h | 2 + 2 files changed, 35 insertions(+), 13 deletions(-) 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 059d583..2ac0c66 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 272c518..98e49ee 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: -- Gitee