mirror of
https://github.com/openharmony/security_security_component_manager.git
synced 2026-08-24 22:51:27 -04:00
@@ -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<int32_t>();
|
||||
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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -93,5 +93,6 @@ ohos_shared_library("security_component_service") {
|
||||
"safwk:system_ability_fwk",
|
||||
"samgr:samgr_proxy",
|
||||
"window_manager:libdm",
|
||||
"window_manager:libwm",
|
||||
]
|
||||
}
|
||||
|
||||
@@ -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<sptr<Rosen::AccessibilityWindowInfo>> 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;
|
||||
|
||||
@@ -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<SecCompBase>& 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
|
||||
|
||||
@@ -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",
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user