From 7fd731907bc9b024075bdf3e0b399ae168149984 Mon Sep 17 00:00:00 2001 From: libing23 Date: Fri, 1 Dec 2023 15:27:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BD=93=E7=AA=97=E5=8F=A3=E7=BC=A9=E6=94=BE?= =?UTF-8?q?=E6=97=B6=EF=BC=8C=E8=B0=83=E6=95=B4=E5=AE=89=E5=85=A8=E6=8E=A7?= =?UTF-8?q?=E4=BB=B6=E5=AE=9E=E9=99=85=E5=B0=BA=E5=AF=B8=E5=92=8C=E4=BD=8D?= =?UTF-8?q?=E7=BD=AE=20Signed-off-by:=20libing23=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../security_component/src/sec_comp_base.cpp | 8 ++++ .../include/sec_comp_base.h | 2 + .../security_component_service/sa/BUILD.gn | 1 + .../sa/sa_main/sec_comp_info_helper.cpp | 38 ++++++++++++++++++- .../sa/sa_main/sec_comp_info_helper.h | 6 ++- .../sa/test/BUILD.gn | 2 + 6 files changed, 55 insertions(+), 2 deletions(-) diff --git a/frameworks/security_component/src/sec_comp_base.cpp b/frameworks/security_component/src/sec_comp_base.cpp index f5659f2..2b6754d 100644 --- a/frameworks/security_component/src/sec_comp_base.cpp +++ b/frameworks/security_component/src/sec_comp_base.cpp @@ -55,6 +55,7 @@ const std::string JsonTagConstants::JSON_STYLE_TAG = "style"; const std::string JsonTagConstants::JSON_TEXT_TAG = "text"; const std::string JsonTagConstants::JSON_ICON_TAG = "icon"; const std::string JsonTagConstants::JSON_BG_TAG = "bg"; +const std::string JsonTagConstants::JSON_WINDOW_ID = "windowId"; bool SecCompBase::ParseDimension(const nlohmann::json& json, const std::string& tag, DimensionT& res) { @@ -250,6 +251,12 @@ bool SecCompBase::FromJson(const nlohmann::json& jsonSrc) return false; } + if ((jsonSrc.find(JsonTagConstants::JSON_WINDOW_ID) == jsonSrc.end()) || + !jsonSrc.at(JsonTagConstants::JSON_WINDOW_ID).is_number()) { + SC_LOG_ERROR(LABEL, "json: %{public}s tag invalid.", JsonTagConstants::JSON_WINDOW_ID.c_str()); + return false; + } + windowId_ = jsonSrc.at(JsonTagConstants::JSON_WINDOW_ID).get(); return true; } @@ -301,6 +308,7 @@ void SecCompBase::ToJson(nlohmann::json& jsonRes) const { JsonTagConstants::JSON_ICON_TAG, icon_ }, { JsonTagConstants::JSON_BG_TAG, bg_ }, }; + jsonRes[JsonTagConstants::JSON_WINDOW_ID] = windowId_; } std::string SecCompBase::ToJsonStr() const diff --git a/interfaces/inner_api/security_component/include/sec_comp_base.h b/interfaces/inner_api/security_component/include/sec_comp_base.h index 4d23c05..db539bd 100644 --- a/interfaces/inner_api/security_component/include/sec_comp_base.h +++ b/interfaces/inner_api/security_component/include/sec_comp_base.h @@ -71,6 +71,7 @@ public: static const std::string JSON_TEXT_TAG; static const std::string JSON_ICON_TAG; static const std::string JSON_BG_TAG; + static const std::string JSON_WINDOW_ID; }; class SecCompBase { @@ -117,6 +118,7 @@ public: int32_t icon_ = UNKNOWN_ICON; SecCompBackground bg_ = SecCompBackground::UNKNOWN_BG; + int32_t windowId_ = 0; int32_t nodeId_ = 0; protected: virtual bool IsTextIconTypeValid() = 0; diff --git a/services/security_component_service/sa/BUILD.gn b/services/security_component_service/sa/BUILD.gn index d754242..804cbca 100644 --- a/services/security_component_service/sa/BUILD.gn +++ b/services/security_component_service/sa/BUILD.gn @@ -93,5 +93,6 @@ ohos_shared_library("security_component_service") { "safwk:system_ability_fwk", "samgr:samgr_proxy", "window_manager:libdm", + "window_manager:libwm", ] } diff --git a/services/security_component_service/sa/sa_main/sec_comp_info_helper.cpp b/services/security_component_service/sa/sa_main/sec_comp_info_helper.cpp index 33fa440..02b152c 100644 --- a/services/security_component_service/sa/sa_main/sec_comp_info_helper.cpp +++ b/services/security_component_service/sa/sa_main/sec_comp_info_helper.cpp @@ -24,6 +24,7 @@ #include "sec_comp_log.h" #include "sec_comp_service.h" #include "sec_comp_tool.h" +#include "window_manager.h" namespace OHOS { namespace Security { @@ -32,9 +33,39 @@ namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_SECURITY_COMPONENT, "SecCompInfoHelper"}; static constexpr double MAX_RECT_PERCENT = 0.1F; // 10% static constexpr double ZERO_OFFSET = 0.0F; +static constexpr float FULL_SCREEN_SCALE = 1.0F; static std::mutex g_renderLock; } +float SecCompInfoHelper::GetWindowScale(int32_t windowId) +{ + float scale = FULL_SCREEN_SCALE; + std::vector> infos; + if (Rosen::WindowManager::GetInstance().GetAccessibilityWindowInfo(infos) != Rosen::WMError::WM_OK) { + SC_LOG_ERROR(LABEL, "Get AccessibilityWindowInfo failed"); + return scale; + } + for (auto& info : infos) { + if ((info != nullptr) && (info->wid_ == windowId)) { + scale = info->scaleVal_; + SC_LOG_INFO(LABEL, "Get scale %{public}f", scale); + break; + } + } + return scale; +} + +void SecCompInfoHelper::AdjustSecCompRect(SecCompBase* comp, float scale) +{ + comp->rect_.width_ *= scale; + comp->rect_.height_ *= scale; + comp->rect_.x_ = comp->windowRect_.x_ + (comp->rect_.x_ - comp->windowRect_.x_) * scale; + comp->rect_.y_ = comp->windowRect_.y_ + (comp->rect_.y_ - comp->windowRect_.y_) * scale; + + SC_LOG_DEBUG(LABEL, "After adjust x %{public}lf, y %{public}lf, width %{public}lf, height %{public}lf", + comp->rect_.x_, comp->rect_.y_, comp->rect_.width_, comp->rect_.height_); +} + SecCompBase* SecCompInfoHelper::ParseComponent(SecCompType type, const nlohmann::json& jsonComponent) { SecCompBase* comp = nullptr; @@ -183,13 +214,18 @@ static bool CheckSecCompBase(const SecCompBase* comp) return true; } -bool SecCompInfoHelper::CheckComponentValid(const SecCompBase* comp) +bool SecCompInfoHelper::CheckComponentValid(SecCompBase* comp) { if ((comp == nullptr) || !IsComponentTypeValid(comp->type_)) { SC_LOG_INFO(LABEL, "comp is null or type is invalid."); return false; } + float scale = GetWindowScale(comp->windowId_); + if (!IsEqual(scale, FULL_SCREEN_SCALE)) { + AdjustSecCompRect(comp, scale); + } + if (!CheckSecCompBase(comp)) { SC_LOG_INFO(LABEL, "SecComp base is invalid."); return false; diff --git a/services/security_component_service/sa/sa_main/sec_comp_info_helper.h b/services/security_component_service/sa/sa_main/sec_comp_info_helper.h index 0d97f69..ba8006b 100644 --- a/services/security_component_service/sa/sa_main/sec_comp_info_helper.h +++ b/services/security_component_service/sa/sa_main/sec_comp_info_helper.h @@ -40,8 +40,12 @@ public: static SecCompBase* ParseComponent(SecCompType type, const nlohmann::json& jsonComponent); static int32_t GrantTempPermission(AccessToken::AccessTokenID tokenId, const std::shared_ptr& componentInfo); - static bool CheckComponentValid(const SecCompBase* comp); + static bool CheckComponentValid(SecCompBase* comp); static bool CheckRectValid(const SecCompRect& rect, const SecCompRect& windowRect); + +private: + static float GetWindowScale(int32_t windowId); + static void AdjustSecCompRect(SecCompBase* comp, float scale); }; } // namespace SecurityComponent } // namespace Security diff --git a/services/security_component_service/sa/test/BUILD.gn b/services/security_component_service/sa/test/BUILD.gn index 0edc634..ad0e754 100644 --- a/services/security_component_service/sa/test/BUILD.gn +++ b/services/security_component_service/sa/test/BUILD.gn @@ -83,6 +83,7 @@ ohos_unittest("sec_comp_service_test") { "hitrace:hitrace_meter", "ipc:ipc_core", "window_manager:libdm", + "window_manager:libwm", ] } @@ -150,6 +151,7 @@ ohos_unittest("sec_comp_service_mock_test") { "hitrace:hitrace_meter", "ipc:ipc_core", "window_manager:libdm", + "window_manager:libwm", ] }