From 4d18b5fc32436caf8d933632a71d3511c868b4ed Mon Sep 17 00:00:00 2001 From: Haryslee Date: Sat, 22 Feb 2025 16:50:10 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96=E5=AE=89=E5=85=A8?= =?UTF-8?q?=E6=8E=A7=E4=BB=B6=E4=BB=A3=E7=A0=81=EF=BC=8C=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E6=97=A5=E5=BF=97=E6=89=93=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Haryslee --- .../security_component/src/sec_comp_base.cpp | 2 +- .../sa/sa_main/first_use_dialog.cpp | 6 ++--- .../sa/sa_main/first_use_dialog.h | 2 +- .../sa/sa_main/sec_comp_entity.cpp | 26 ++++++++++++++++--- .../sa/sa_main/sec_comp_entity.h | 1 + .../sa/sa_main/sec_comp_info_helper.cpp | 10 +++---- .../sa/sa_main/sec_comp_manager.cpp | 24 +++++++++++------ .../sa/sa_main/sec_comp_manager.h | 2 +- .../src/sec_comp_info_helper_test.cpp | 8 +++--- 9 files changed, 54 insertions(+), 27 deletions(-) diff --git a/frameworks/security_component/src/sec_comp_base.cpp b/frameworks/security_component/src/sec_comp_base.cpp index 323d9e3..6d00cd2 100644 --- a/frameworks/security_component/src/sec_comp_base.cpp +++ b/frameworks/security_component/src/sec_comp_base.cpp @@ -294,7 +294,7 @@ bool SecCompBase::ParseCrossAxisState(const nlohmann::json& json, const std::str int32_t value = json.at(tag).get(); if ((value < static_cast(CrossAxisState::STATE_INVALID)) || (value > static_cast(CrossAxisState::STATE_NO_CROSS))) { - SC_LOG_ERROR(LABEL, "Cross axis state value is invalid."); + SC_LOG_ERROR(LABEL, "Cross axis state: %{public}d is invalid.", value); return false; } crossAxisState_ = static_cast(value); diff --git a/services/security_component_service/sa/sa_main/first_use_dialog.cpp b/services/security_component_service/sa/sa_main/first_use_dialog.cpp index 302056a..445c621 100644 --- a/services/security_component_service/sa/sa_main/first_use_dialog.cpp +++ b/services/security_component_service/sa/sa_main/first_use_dialog.cpp @@ -302,7 +302,7 @@ int32_t FirstUseDialog::GrantDialogWaitEntity(int32_t scId) return res; } -bool FirstUseDialog::GetDialogInfo(AAFwk::Want& want, const uint64_t displayId, const CrossAxisState crossAxisState) +bool FirstUseDialog::SetDialogInfo(AAFwk::Want& want, const uint64_t displayId, const CrossAxisState crossAxisState) { sptr display = OHOS::Rosen::DisplayManager::GetInstance().GetDisplayById(displayId); @@ -363,8 +363,8 @@ void FirstUseDialog::StartDialogAbility(std::shared_ptr entity, s want.SetParam(WINDOW_ID_KEY, displayInfo.windowId); int32_t uid = IPCSkeleton::GetCallingUid(); want.SetParam(CALLER_UID_KEY, uid); - if (!GetDialogInfo(want, displayInfo.displayId, displayInfo.crossAxisState)) { - SC_LOG_ERROR(LABEL, "Get display info failed."); + if (!SetDialogInfo(want, displayInfo.displayId, displayInfo.crossAxisState)) { + SC_LOG_ERROR(LABEL, "Set dialog info failed."); return; } diff --git a/services/security_component_service/sa/sa_main/first_use_dialog.h b/services/security_component_service/sa/sa_main/first_use_dialog.h index ade6495..a705d60 100644 --- a/services/security_component_service/sa/sa_main/first_use_dialog.h +++ b/services/security_component_service/sa/sa_main/first_use_dialog.h @@ -82,7 +82,7 @@ private: void SaveFirstUseRecord(void); void StartDialogAbility(std::shared_ptr entity, sptr callerToken, sptr dialogCallback, const DisplayInfo& displayInfo); - bool GetDialogInfo(AAFwk::Want& want, const uint64_t displayId, const CrossAxisState crossAxisState); + bool SetDialogInfo(AAFwk::Want& want, const uint64_t displayId, const CrossAxisState crossAxisState); void SendSaveEventHandler(void); std::mutex useMapMutex_; diff --git a/services/security_component_service/sa/sa_main/sec_comp_entity.cpp b/services/security_component_service/sa/sa_main/sec_comp_entity.cpp index bff6ef2..66924a4 100644 --- a/services/security_component_service/sa/sa_main/sec_comp_entity.cpp +++ b/services/security_component_service/sa/sa_main/sec_comp_entity.cpp @@ -73,6 +73,7 @@ int32_t SecCompEntity::CheckPointEvent(SecCompClickEvent& clickInfo, int32_t sup if ((crossAxisState == CrossAxisState::STATE_CROSS) && componentInfo_->rect_.IsInRect(clickInfo.point.touchX, clickInfo.point.touchY + superFoldOffsetY)) { clickInfo.point.touchY += superFoldOffsetY; + SC_LOG_INFO(LABEL, "Fold PC cross state and component is in PC virtual screen."); return SC_OK; } SC_LOG_ERROR(LABEL, "touch point is not in component rect = (%{public}f, %{public}f)" \ @@ -104,18 +105,35 @@ int32_t SecCompEntity::CheckKeyEvent(const SecCompClickEvent& clickInfo) const return SC_OK; } +bool SecCompEntity::IsInPCVirtualScreen(const CrossAxisState crossAxisState) const +{ + bool isInPCVirtualScreen = false; + if (componentInfo_->displayId_ == FOLD_VIRTUAL_DISPLAY_ID) { + if (crossAxisState == CrossAxisState::STATE_NO_CROSS) { + isInPCVirtualScreen = true; + } else { + SC_LOG_WARN(LABEL, "Security component maybe in PC virtual screen, the cross axis state is %{public}d", + static_cast(crossAxisState)); + } + } + return isInPCVirtualScreen; +} + int32_t SecCompEntity::CheckClickInfo(SecCompClickEvent& clickInfo, int32_t superFoldOffsetY, const CrossAxisState crossAxisState, std::string& message) const { + bool isInPCVirtualScreen = IsInPCVirtualScreen(crossAxisState); + SC_LOG_INFO(LABEL, "The cross axis state: %{public}d, the fold offset y: %{public}d.", + static_cast(crossAxisState), superFoldOffsetY); + if (isInPCVirtualScreen) { + clickInfo.point.touchY += superFoldOffsetY; + componentInfo_->rect_.y_ += superFoldOffsetY; + } if (!WindowInfoHelper::CheckOtherWindowCoverComp(componentInfo_->windowId_, componentInfo_->rect_, message)) { SC_LOG_ERROR(LABEL, "Component may be covered by other window"); return SC_SERVICE_ERROR_CLICK_EVENT_INVALID; } - if (componentInfo_->displayId_ == FOLD_VIRTUAL_DISPLAY_ID) { - clickInfo.point.touchY += superFoldOffsetY; - componentInfo_->rect_.y_ += superFoldOffsetY; - } int32_t res = SC_SERVICE_ERROR_CLICK_EVENT_INVALID; bool isScreenReadMode = IsScreenReadMode(); diff --git a/services/security_component_service/sa/sa_main/sec_comp_entity.h b/services/security_component_service/sa/sa_main/sec_comp_entity.h index fb9d7ba..c49f970 100644 --- a/services/security_component_service/sa/sa_main/sec_comp_entity.h +++ b/services/security_component_service/sa/sa_main/sec_comp_entity.h @@ -48,6 +48,7 @@ public: bool CompareComponentBasicInfo(SecCompBase* other, bool isRectCheck) const; int32_t CheckClickInfo(SecCompClickEvent& clickInfo, int32_t superFoldOffsetY, const CrossAxisState crossAxisState, std::string& message) const; + bool IsInPCVirtualScreen(const CrossAxisState crossAxisState) const; std::shared_ptr componentInfo_; AccessToken::AccessTokenID tokenId_; 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 9abf59d..3f7e0c9 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 @@ -136,8 +136,8 @@ bool SecCompInfoHelper::CheckRectValid(const SecCompRect& rect, const SecCompRec return false; } - if (GreatNotEqual((rect.x_ + rect.width_), curScreenWidth) || - GreatNotEqual((rect.y_ + rect.height_), curScreenHeight)) { + if (GreatNotEqual((rect.x_ + rect.width_), curScreenWidth + 1.0) || + GreatNotEqual((rect.y_ + rect.height_), curScreenHeight + 1.0)) { SC_LOG_ERROR(LABEL, "SecurityComponentCheckFail: security component is out of screen"); message = OUT_OF_SCREEN + std::to_string(rect.x_) + ", y = " + std::to_string(rect.y_) + ", width = " + std::to_string(rect.width_) + ", height = " + std::to_string(rect.height_) + @@ -146,9 +146,9 @@ bool SecCompInfoHelper::CheckRectValid(const SecCompRect& rect, const SecCompRec return false; } - if (GreatNotEqual(windowRect.x_, rect.x_) || GreatNotEqual(windowRect.y_, rect.y_) || - GreatNotEqual(rect.x_ + rect.width_, windowRect.x_ + windowRect.width_) || - GreatNotEqual(rect.y_ + rect.height_, windowRect.y_ + windowRect.height_)) { + if (GreatNotEqual(windowRect.x_, rect.x_ + 1.0) || GreatNotEqual(windowRect.y_, rect.y_ + 1.0) || + GreatNotEqual(rect.x_ + rect.width_, windowRect.x_ + windowRect.width_ + 1.0) || + GreatNotEqual(rect.y_ + rect.height_, windowRect.y_ + windowRect.height_ + 1.0)) { SC_LOG_ERROR(LABEL, "SecurityComponentCheckFail: security component is out of window"); message = OUT_OF_WINDOW + std::to_string(rect.x_) + ", y = " + std::to_string(rect.y_) + ", width = " + std::to_string(rect.width_) + ", height = " + std::to_string(rect.height_) + diff --git a/services/security_component_service/sa/sa_main/sec_comp_manager.cpp b/services/security_component_service/sa/sa_main/sec_comp_manager.cpp index 10eee09..c1fd80e 100644 --- a/services/security_component_service/sa/sa_main/sec_comp_manager.cpp +++ b/services/security_component_service/sa/sa_main/sec_comp_manager.cpp @@ -508,19 +508,27 @@ static void ReportEvent(std::string eventName, HiviewDFX::HiSysEvent::EventType "CALLER_PID", IPCSkeleton::GetCallingPid(), "SC_ID", scId, "SC_TYPE", scType); } -void SecCompManager::GetFoldOffsetY() +void SecCompManager::GetFoldOffsetY(const CrossAxisState crossAxisState) { + if (crossAxisState == CrossAxisState::STATE_INVALID) { + return; + } if (superFoldOffsetY_ != 0) { return; } auto foldCreaseRegion = OHOS::Rosen::DisplayManager::GetInstance().GetCurrentFoldCreaseRegion(); - if (foldCreaseRegion != nullptr) { - const auto& creaseRects = foldCreaseRegion->GetCreaseRects(); - if (!creaseRects.empty()) { - const auto& rect = creaseRects.front(); - superFoldOffsetY_ = rect.height_ + rect.posY_; - } + if (foldCreaseRegion == nullptr) { + SC_LOG_ERROR(LABEL, "foldCreaseRegion is nullptr"); + return; + } + const auto& creaseRects = foldCreaseRegion->GetCreaseRects(); + if (creaseRects.empty()) { + SC_LOG_ERROR(LABEL, "creaseRects is empty"); + return; } + const auto& rect = creaseRects.front(); + superFoldOffsetY_ = rect.height_ + rect.posY_; + SC_LOG_INFO(LABEL, "height: %{public}d, posY: %{public}d", rect.height_, rect.posY_); } int32_t SecCompManager::ReportSecurityComponentClickEvent(SecCompInfo& info, const nlohmann::json& compJson, @@ -551,7 +559,7 @@ int32_t SecCompManager::ReportSecurityComponentClickEvent(SecCompInfo& info, con return SC_SERVICE_ERROR_COMPONENT_INFO_INVALID; } - GetFoldOffsetY(); + GetFoldOffsetY(report->crossAxisState_); res = sc->CheckClickInfo(info.clickInfo, superFoldOffsetY_, report->crossAxisState_, message); if (res != SC_OK) { diff --git a/services/security_component_service/sa/sa_main/sec_comp_manager.h b/services/security_component_service/sa/sa_main/sec_comp_manager.h index 30de2dd..b57b363 100644 --- a/services/security_component_service/sa/sa_main/sec_comp_manager.h +++ b/services/security_component_service/sa/sa_main/sec_comp_manager.h @@ -81,7 +81,7 @@ private: void SendCheckInfoEnhanceSysEvent(int32_t scId, SecCompType type, const std::string& scene, int32_t res); int32_t CreateScId(); - void GetFoldOffsetY(); + void GetFoldOffsetY(const CrossAxisState crossAxisState); OHOS::Utils::RWLock componentInfoLock_; std::mutex scIdMtx_; diff --git a/services/security_component_service/sa/test/unittest/src/sec_comp_info_helper_test.cpp b/services/security_component_service/sa/test/unittest/src/sec_comp_info_helper_test.cpp index 2f1a976..a464dd1 100644 --- a/services/security_component_service/sa/test/unittest/src/sec_comp_info_helper_test.cpp +++ b/services/security_component_service/sa/test/unittest/src/sec_comp_info_helper_test.cpp @@ -199,19 +199,19 @@ HWTEST_F(SecCompInfoHelperTest, ParseComponent005, TestSize.Level1) std::string message; ASSERT_TRUE(SecCompInfoHelper::CheckRectValid(rect, windowRect, 0, CrossAxisState::STATE_INVALID, message)); - windowRect.x_ = g_testWidth + 1; + windowRect.x_ = g_testWidth + 2.0; ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, 0, CrossAxisState::STATE_INVALID, message)); windowRect.x_ = g_testWidth; - windowRect.y_ = g_testHeight + 1; + windowRect.y_ = g_testHeight + 2.0; ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, 0, CrossAxisState::STATE_INVALID, message)); windowRect.y_ = g_testHeight; - windowRect.width_ = g_testWidth - 1; + windowRect.width_ = g_testWidth - 2.0; ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, 0, CrossAxisState::STATE_INVALID, message)); windowRect.width_ = g_testWidth; - windowRect.height_ = g_testHeight - 1; + windowRect.height_ = g_testHeight - 2.0; ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, 0, CrossAxisState::STATE_INVALID, message)); windowRect.height_ = g_testHeight; -- Gitee