1 /*
2 * Copyright (c) 2023-2025 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "core/components_ng/pattern/security_component/security_component_handler.h"
17 #include "ui/base/geometry/dimension.h"
18 #include "ui/base/utils/utils.h"
19
20 #include "adapter/ohos/entrance/ace_container.h"
21 #include "base/geometry/dimension.h"
22 #include "base/utils/system_properties.h"
23 #include "core/components_ng/pattern/button/button_layout_property.h"
24 #include "core/components_ng/pattern/security_component/security_component_log.h"
25 #include "core/components_ng/pattern/window_scene/scene/system_window_scene.h"
26 #include "core/components_ng/property/gradient_property.h"
27 #include "core/components_ng/render/render_context.h"
28 #include "core/components_v2/inspector/inspector_constants.h"
29 #ifdef SECURITY_COMPONENT_ENABLE
30 #include "pointer_event.h"
31 #endif
32
33 namespace OHOS::Ace::NG {
34 using namespace OHOS::Security;
35 using namespace OHOS::Security::SecurityComponent;
36 namespace {
37 constexpr uint64_t SECOND_TO_MILLISECOND = 1000;
38 constexpr float HALF = 2.0f;
39 const std::string SEC_COMP_ID = "security component id = ";
40 const std::string SEC_COMP_TYPE = ", security component type = ";
41 constexpr int32_t PARENT_EFFECT_CHECK_FUNC_NUM = 15;
42 }
43
44 static std::vector<uintptr_t> g_callList = {
45 reinterpret_cast<uintptr_t>(SecurityComponentHandler::RegisterSecurityComponent),
46 reinterpret_cast<uintptr_t>(SecurityComponentHandler::UpdateSecurityComponent),
47 reinterpret_cast<uintptr_t>(SecurityComponentHandler::ReportSecurityComponentClickEventInner)
48 };
49
50 SecurityComponentProbe SecurityComponentHandler::probe;
51 SecurityComponent::SecCompUiRegister uiRegister(g_callList, &SecurityComponentHandler::probe);
52
GetDisplayOffset(RefPtr<FrameNode> & node,double & offsetX,double & offsetY)53 bool SecurityComponentHandler::GetDisplayOffset(RefPtr<FrameNode>& node, double& offsetX, double& offsetY)
54 {
55 double x = node->GetTransformRelativeOffset().GetX();
56 double y = node->GetTransformRelativeOffset().GetY();
57 auto container = Container::CurrentSafely();
58 CHECK_NULL_RETURN(container, false);
59 auto pipelineContext = container->GetPipelineContext();
60 CHECK_NULL_RETURN(pipelineContext, false);
61 auto windowOffset = pipelineContext->GetDisplayWindowRectInfo().GetOffset();
62 offsetX = x + windowOffset.GetX();
63 offsetY = y + windowOffset.GetY();
64 return true;
65 }
66
GetWindowRect(RefPtr<FrameNode> & node,OHOS::Security::SecurityComponent::SecCompRect & winRect)67 bool SecurityComponentHandler::GetWindowRect(RefPtr<FrameNode>& node,
68 OHOS::Security::SecurityComponent::SecCompRect& winRect)
69 {
70 auto container = Container::CurrentSafely();
71 CHECK_NULL_RETURN(container, false);
72 auto pipelineContext = container->GetPipelineContext();
73 CHECK_NULL_RETURN(pipelineContext, false);
74 auto rect = pipelineContext->GetDisplayWindowRectInfo();
75 winRect.x_ = rect.Left();
76 winRect.y_ = rect.Top();
77 winRect.width_ = rect.Right() - rect.Left();
78 winRect.height_ = rect.Bottom() - rect.Top();
79 return true;
80 }
81
CheckOpacity(const RefPtr<FrameNode> & node,const RefPtr<RenderContext> & renderContext,std::string & message)82 bool SecurityComponentHandler::CheckOpacity(const RefPtr<FrameNode>& node, const RefPtr<RenderContext>& renderContext,
83 std::string& message)
84 {
85 if (node->GetTag() == V2::MENU_WRAPPER_ETS_TAG) {
86 return false;
87 }
88 if (renderContext->GetOpacity().has_value() &&
89 !NearEqual(renderContext->GetOpacity().value(), 1.0f)) {
90 SC_LOG_ERROR("SecurityComponentCheckFail: Parent %{public}s opacity = %{public}f, " \
91 "security component is invalid", node->GetTag().c_str(), renderContext->GetOpacity().value());
92 message = ", attribute opacity of parent component " + node->GetTag() +
93 "(id = " + std::to_string(node->GetId()) + ") is set, opacity = " +
94 std::to_string(renderContext->GetOpacity().value());
95 return true;
96 }
97 return false;
98 }
99
CheckBrightness(const RefPtr<FrameNode> & node,const RefPtr<RenderContext> & renderContext,std::string & message)100 bool SecurityComponentHandler::CheckBrightness(const RefPtr<FrameNode>& node,
101 const RefPtr<RenderContext>& renderContext, std::string& message)
102 {
103 if (renderContext->GetFrontBrightness().has_value() &&
104 !NearEqual(renderContext->GetFrontBrightness().value().Value(), 1.0f)) {
105 SC_LOG_ERROR("SecurityComponentCheckFail: Parent %{public}s brightness = %{public}f, " \
106 "security component is invalid", node->GetTag().c_str(),
107 renderContext->GetFrontBrightness().value().Value());
108 message = ", attribute brightness of parent component " + node->GetTag() +
109 "(id = " + std::to_string(node->GetId()) + ") is set, brightness = " +
110 std::to_string(renderContext->GetFrontBrightness().value().Value());
111 return true;
112 }
113 return false;
114 }
115
CheckVisibility(const RefPtr<FrameNode> & node,RefPtr<LayoutProperty> & layoutProperty,std::string & message)116 bool SecurityComponentHandler::CheckVisibility(const RefPtr<FrameNode>& node, RefPtr<LayoutProperty>& layoutProperty,
117 std::string& message)
118 {
119 if (layoutProperty->GetVisibility().has_value() &&
120 (layoutProperty->GetVisibility().value() != VisibleType::VISIBLE)) {
121 SC_LOG_ERROR("SecurityComponentCheckFail: Parent %{public}s is not visible, security component is invalid",
122 node->GetTag().c_str());
123 message = ", attribute visibility of parent component " + node->GetTag() +
124 "(id = " + std::to_string(node->GetId()) + ") is set, parent component is not visible";
125 return true;
126 }
127 return false;
128 }
129
CheckBlur(const RefPtr<FrameNode> & node,const RefPtr<RenderContext> & renderContext,std::string & message)130 bool SecurityComponentHandler::CheckBlur(const RefPtr<FrameNode>& node, const RefPtr<RenderContext>& renderContext,
131 std::string& message)
132 {
133 if (renderContext->GetFrontBlurRadius().has_value() &&
134 GreatNotEqual(renderContext->GetFrontBlurRadius().value().ConvertToPx(), 0.0f)) {
135 SC_LOG_ERROR("SecurityComponentCheckFail: Parent %{public}s blur is set, security component is invalid",
136 node->GetTag().c_str());
137 message = ", attribute blur of parent component " + node->GetTag() +
138 "(id = " + std::to_string(node->GetId()) + ") is set";
139 return true;
140 }
141 return false;
142 }
143
CheckForegroundBlurStyle(const RefPtr<FrameNode> & node,const RefPtr<RenderContext> & renderContext,std::string & message)144 bool SecurityComponentHandler::CheckForegroundBlurStyle(const RefPtr<FrameNode>& node,
145 const RefPtr<RenderContext>& renderContext, std::string& message)
146 {
147 auto blurStyleOption = renderContext->GetFrontBlurStyle();
148 if (blurStyleOption.has_value() && (blurStyleOption->blurStyle != BlurStyle::NO_MATERIAL) &&
149 (!NearEqual(blurStyleOption->scale, 0.0))) {
150 SC_LOG_ERROR("SecurityComponentCheckFail: Parent %{public}s foregroundBlurStyle is set, " \
151 "security component is invalid", node->GetTag().c_str());
152 message = ", attribute foregroundBlurStyle of parent component " +
153 node->GetTag() + "(id = " + std::to_string(node->GetId()) + ") is set";
154 return true;
155 }
156 return false;
157 }
158
CheckBlendMode(const RefPtr<FrameNode> & node,const RefPtr<RenderContext> & renderContext,std::string & message)159 bool SecurityComponentHandler::CheckBlendMode(const RefPtr<FrameNode>& node,
160 const RefPtr<RenderContext>& renderContext, std::string& message)
161 {
162 auto blendMode = renderContext->GetBackBlendMode();
163 if (blendMode.has_value() && blendMode != BlendMode::NONE && blendMode != BlendMode::SRC_OVER) {
164 SC_LOG_ERROR("SecurityComponentCheckFail: Parent %{public}s blendMode is set, " \
165 "security component is invalid", node->GetTag().c_str());
166 message = ", attribute blendMode of parent component " +
167 node->GetTag() + "(id = " + std::to_string(node->GetId()) + ") is set";
168 return true;
169 }
170 return false;
171 }
172
GetBorderRect(const RefPtr<FrameNode> & parentNode,std::vector<RectF> & borderRects)173 bool SecurityComponentHandler::GetBorderRect(const RefPtr<FrameNode>& parentNode, std::vector<RectF>& borderRects)
174 {
175 auto renderContext = parentNode->GetRenderContext();
176 CHECK_NULL_RETURN(renderContext, false);
177 auto borderWidth = renderContext->GetBorderWidth();
178 CHECK_NULL_RETURN(borderWidth, false);
179 auto parentRect = renderContext->GetPaintRectWithTransform();
180 parentRect.SetOffset(parentNode->GetPositionToWindowWithTransform());
181 auto borderColor = renderContext->GetBorderColor();
182 auto leftIsTransparent = borderColor && borderColor->leftColor.has_value() &&
183 (borderColor->leftColor.value() == Color::TRANSPARENT);
184 auto rightIsTransparent = borderColor && borderColor->rightColor.has_value() &&
185 (borderColor->rightColor.value() == Color::TRANSPARENT);
186 auto topIsTransparent = borderColor && borderColor->topColor.has_value() &&
187 (borderColor->topColor.value() == Color::TRANSPARENT);
188 auto bottomIsTransparent = borderColor && borderColor->bottomColor.has_value() &&
189 (borderColor->bottomColor.value() == Color::TRANSPARENT);
190
191 if (borderWidth->leftDimen.has_value() && GreatNotEqual(borderWidth->leftDimen.value().ConvertToPx(), 1.0) &&
192 !leftIsTransparent) {
193 auto leftWidth = borderWidth->leftDimen.value().ConvertToPx();
194 borderRects.emplace_back(RectF(parentRect.GetX(), parentRect.GetY(), leftWidth, parentRect.Height()));
195 }
196 if (borderWidth->rightDimen.has_value() && GreatNotEqual(borderWidth->rightDimen.value().ConvertToPx(), 1.0) &&
197 !rightIsTransparent) {
198 auto rightWidth = borderWidth->rightDimen.value().ConvertToPx();
199 borderRects.emplace_back(RectF(parentRect.GetX() + parentRect.Width() - rightWidth, parentRect.GetY(),
200 rightWidth, parentRect.Height()));
201 }
202 if (borderWidth->topDimen.has_value() && GreatNotEqual(borderWidth->topDimen.value().ConvertToPx(), 1.0) &&
203 !topIsTransparent) {
204 auto topWidth = borderWidth->topDimen.value().ConvertToPx();
205 borderRects.emplace_back(RectF(parentRect.GetX(), parentRect.GetY(), parentRect.Width(), topWidth));
206 }
207 if (borderWidth->bottomDimen.has_value() && GreatNotEqual(borderWidth->bottomDimen.value().ConvertToPx(), 1.0) &&
208 !bottomIsTransparent) {
209 auto bottomWidth = borderWidth->bottomDimen.value().ConvertToPx();
210 borderRects.emplace_back(RectF(parentRect.GetX(), parentRect.GetY() + parentRect.Height() - bottomWidth,
211 parentRect.Width(), bottomWidth));
212 }
213 return true;
214 }
215
CheckParentBorder(const RefPtr<FrameNode> & parentNode,const RectF & scRect,std::string & message)216 bool SecurityComponentHandler::CheckParentBorder(const RefPtr<FrameNode>& parentNode, const RectF& scRect,
217 std::string& message)
218 {
219 std::vector<RectF> borderRects;
220 if (!GetBorderRect(parentNode, borderRects)) {
221 return false;
222 }
223 for (const auto& rect : borderRects) {
224 if (!rect.IsInnerIntersectWithRound(scRect)) {
225 continue;
226 }
227 SC_LOG_ERROR("SecurityComponentCheckFail: security component is covered by the border of parent" \
228 " %{public}s", parentNode->GetTag().c_str());
229 message = ", security component is covered by the border of parent component " +
230 parentNode->GetTag() + "(id = " + std::to_string(parentNode->GetId()) + ")";
231 return true;
232 }
233
234 return false;
235 }
236
GetLinearGradientBlurRatio(std::vector<std::pair<float,float>> & fractionStops)237 float SecurityComponentHandler::GetLinearGradientBlurRatio(std::vector<std::pair<float, float>>& fractionStops)
238 {
239 float ratio = 1.0;
240 int32_t size = static_cast<int32_t>(fractionStops.size());
241 for (auto i = 0; i < size; i++) {
242 auto fraction = fractionStops[i];
243 if (NearEqual(fraction.first, 0.0)) {
244 ratio = fraction.second;
245 } else {
246 break;
247 }
248 }
249 return ratio;
250 }
251
CheckDistance(const float & deltaY,const float & radius,const float & distance,const int32_t & multiplier)252 bool SecurityComponentHandler::CheckDistance(const float& deltaY, const float& radius, const float& distance,
253 const int32_t& multiplier)
254 {
255 if (NearEqual(radius, 0.0)) {
256 if (GreatNotEqual(deltaY * multiplier, 0.0)) {
257 if (GreatNotEqual(distance, 1.0)) {
258 return true;
259 }
260 }
261 return false;
262 }
263
264 if (GreatOrEqual(deltaY * multiplier, 0.0)) {
265 return true;
266 }
267 if (LessNotEqual(distance, (radius - 1) * (radius - 1))) {
268 return true;
269 }
270 return false;
271 }
272
CheckDiagonalLinearGradientBlur(const RectF & parentRect,const RectF & rect,const NG::GradientDirection direction,const float & ratio,const float & radius)273 bool SecurityComponentHandler::CheckDiagonalLinearGradientBlur(const RectF& parentRect, const RectF& rect,
274 const NG::GradientDirection direction, const float& ratio, const float& radius)
275 {
276 Point dest;
277 Point src;
278 float gradient;
279 int32_t multiplier = 0;
280 switch (direction) {
281 case GradientDirection::LEFT_TOP:
282 dest.SetX(rect.GetX() + radius);
283 dest.SetY(rect.GetY() + radius);
284 src.SetX(parentRect.GetX() + (1 - ratio) * parentRect.Width());
285 src.SetY(parentRect.GetY() + (1 - ratio) * parentRect.Height());
286 gradient = (0 - parentRect.Width()) / parentRect.Height();
287 multiplier = 1;
288 break;
289 case GradientDirection::LEFT_BOTTOM:
290 dest.SetX(rect.GetX() + radius);
291 dest.SetY(rect.GetY() + rect.Height() - radius);
292 src.SetX(parentRect.GetX() + (1 - ratio) * parentRect.Width());
293 src.SetY(parentRect.GetY() + ratio * parentRect.Height());
294 gradient = parentRect.Width() / parentRect.Height();
295 multiplier = -1;
296 break;
297 case GradientDirection::RIGHT_TOP:
298 dest.SetX(rect.GetX() + rect.Width() - radius);
299 dest.SetY(rect.GetY() + radius);
300 src.SetX(parentRect.GetX() + ratio * parentRect.Width());
301 src.SetY(parentRect.GetY() + (1 - ratio) * parentRect.Height());
302 gradient = parentRect.Width() / parentRect.Height();
303 multiplier = 1;
304 break;
305 case GradientDirection::RIGHT_BOTTOM:
306 dest.SetX(rect.GetX() + rect.Width() - radius);
307 dest.SetY(rect.GetY() + rect.Height() - radius);
308 src.SetX(parentRect.GetX() + ratio * parentRect.Width());
309 src.SetY(parentRect.GetY() + ratio * parentRect.Height());
310 gradient = (0 - parentRect.Width()) / parentRect.Height();
311 multiplier = -1;
312 break;
313 default:
314 return false;
315 }
316
317 float deltaY = gradient * dest.GetX() + src.GetY() - gradient * src.GetX() - dest.GetY();
318 auto distance = (deltaY * deltaY) / (1 + gradient * gradient);
319 return CheckDistance(deltaY, radius, distance, multiplier);
320 }
321
GetBorderRadius(RefPtr<FrameNode> & node,const NG::GradientDirection direction)322 float SecurityComponentHandler::GetBorderRadius(RefPtr<FrameNode>& node, const NG::GradientDirection direction)
323 {
324 RectF rect = node->GetTransformRectRelativeToWindow();
325 auto maxRadius = std::min(rect.Width(), rect.Height()) / HALF;
326 auto layoutProperty = AceType::DynamicCast<SecurityComponentLayoutProperty>(node->GetLayoutProperty());
327 CHECK_NULL_RETURN(layoutProperty, 0.0);
328 if (layoutProperty->GetBackgroundType() == static_cast<int32_t>(ButtonType::CIRCLE) ||
329 layoutProperty->GetBackgroundType() == static_cast<int32_t>(ButtonType::CAPSULE)) {
330 return maxRadius;
331 }
332
333 RefPtr<FrameNode> buttonNode = GetSecCompChildNode(node, V2::BUTTON_ETS_TAG);
334 CHECK_NULL_RETURN(buttonNode, 0.0);
335 auto bgProp = buttonNode->GetLayoutProperty<ButtonLayoutProperty>();
336 CHECK_NULL_RETURN(bgProp, 0.0);
337 auto borderRadius = bgProp->GetBorderRadius();
338 float radius = 0.0;
339
340 switch (direction) {
341 case GradientDirection::LEFT_TOP:
342 if (borderRadius.has_value() && borderRadius->radiusTopLeft.has_value()) {
343 auto obtainedRadius = borderRadius->radiusTopLeft.value().ConvertToPx();
344 radius = GreatNotEqual(obtainedRadius, maxRadius) ? maxRadius : obtainedRadius;
345 }
346 return radius;
347 case GradientDirection::LEFT_BOTTOM:
348 if (borderRadius.has_value() && borderRadius->radiusBottomLeft.has_value()) {
349 auto obtainedRadius = borderRadius->radiusBottomLeft.value().ConvertToPx();
350 radius = GreatNotEqual(obtainedRadius, maxRadius) ? maxRadius : obtainedRadius;
351 }
352 return radius;
353 case GradientDirection::RIGHT_TOP:
354 if (borderRadius.has_value() && borderRadius->radiusTopRight.has_value()) {
355 auto obtainedRadius = borderRadius->radiusTopRight.value().ConvertToPx();
356 radius = GreatNotEqual(obtainedRadius, maxRadius) ? maxRadius : obtainedRadius;
357 }
358 return radius;
359 case GradientDirection::RIGHT_BOTTOM:
360 if (borderRadius.has_value() && borderRadius->radiusBottomRight.has_value()) {
361 auto obtainedRadius = borderRadius->radiusBottomRight.value().ConvertToPx();
362 radius = GreatNotEqual(obtainedRadius, maxRadius) ? maxRadius : obtainedRadius;
363 }
364 return radius;
365 default:
366 return radius;
367 }
368 return radius;
369 }
370
CheckLinearGradientBlur(const RefPtr<FrameNode> & parentNode,RefPtr<FrameNode> & node,bool & isBlured,double & blurRadius)371 bool SecurityComponentHandler::CheckLinearGradientBlur(const RefPtr<FrameNode>& parentNode,
372 RefPtr<FrameNode>& node, bool& isBlured, double& blurRadius)
373 {
374 RectF parentRect = parentNode->GetTransformRectRelativeToWindow();
375 if (NearEqual(parentRect.Width(), 0.0) || NearEqual(parentRect.Height(), 0.0)) {
376 return false;
377 }
378
379 RectF rect = node->GetTransformRectRelativeToWindow();
380 const auto& parentRender = parentNode->GetRenderContext();
381 CHECK_NULL_RETURN(parentRender, false);
382 auto linearGradientBlurPara = parentRender->GetLinearGradientBlur();
383 CHECK_NULL_RETURN(linearGradientBlurPara, false);
384 isBlured = true;
385 blurRadius = linearGradientBlurPara->blurRadius_.ConvertToPx();
386 float ratio = GetLinearGradientBlurRatio(linearGradientBlurPara->fractionStops_);
387 if (NearEqual(ratio, 1.0)) {
388 return false;
389 }
390
391 float radius = 0.0;
392 switch (linearGradientBlurPara->direction_) {
393 case GradientDirection::LEFT:
394 return GreatNotEqual((parentRect.GetX() + parentRect.Width() - rect.GetX()) / parentRect.Width(), ratio);
395 case GradientDirection::TOP:
396 return GreatNotEqual((parentRect.GetY() + parentRect.Height() - rect.GetY()) / parentRect.Height(), ratio);
397 case GradientDirection::RIGHT:
398 return GreatNotEqual((rect.GetX() + rect.Width() - parentRect.GetX()) / parentRect.Width(), ratio);
399 case GradientDirection::BOTTOM:
400 return GreatNotEqual((rect.GetY() + rect.Height() - parentRect.GetY()) / parentRect.Height(), ratio);
401 case GradientDirection::LEFT_TOP:
402 case GradientDirection::LEFT_BOTTOM:
403 case GradientDirection::RIGHT_TOP:
404 case GradientDirection::RIGHT_BOTTOM:
405 radius = GetBorderRadius(node, linearGradientBlurPara->direction_);
406 return CheckDiagonalLinearGradientBlur(parentRect, rect,
407 linearGradientBlurPara->direction_, ratio, radius);
408 default:
409 return false;
410 }
411 }
412
CheckSaturate(const RefPtr<FrameNode> & node,const RefPtr<RenderContext> & renderContext,std::string & message)413 bool SecurityComponentHandler::CheckSaturate(const RefPtr<FrameNode>& node, const RefPtr<RenderContext>& renderContext,
414 std::string& message)
415 {
416 if (renderContext->GetFrontSaturate().has_value() &&
417 !NearEqual(renderContext->GetFrontSaturate().value().ConvertToVp(), 1.0f)) {
418 SC_LOG_ERROR("SecurityComponentCheckFail: Parent %{public}s saturate is set, security component is invalid",
419 node->GetTag().c_str());
420 message = ", attribute saturate of parent component " + node->GetTag() +
421 "(id = " + std::to_string(node->GetId()) + ") is set";
422 return true;
423 }
424 return false;
425 }
426
CheckContrast(const RefPtr<FrameNode> & node,const RefPtr<RenderContext> & renderContext,std::string & message)427 bool SecurityComponentHandler::CheckContrast(const RefPtr<FrameNode>& node, const RefPtr<RenderContext>& renderContext,
428 std::string& message)
429 {
430 if (renderContext->GetFrontContrast().has_value() &&
431 !NearEqual(renderContext->GetFrontContrast().value().ConvertToVp(), 1.0f)) {
432 SC_LOG_ERROR("SecurityComponentCheckFail: Parent %{public}s contrast is set, security component is invalid",
433 node->GetTag().c_str());
434 message = ", attribute contrast of parent component " + node->GetTag() +
435 "(id = " + std::to_string(node->GetId()) + ") is set";
436 return true;
437 }
438 return false;
439 }
440
CheckInvert(const RefPtr<FrameNode> & node,const RefPtr<RenderContext> & renderContext,std::string & message)441 bool SecurityComponentHandler::CheckInvert(const RefPtr<FrameNode>& node, const RefPtr<RenderContext>& renderContext,
442 std::string& message)
443 {
444 if (renderContext->GetFrontInvert().has_value() && renderContext->GetFrontInvert()->index() == 0 &&
445 !NearEqual(std::get<float>(renderContext->GetFrontInvert().value()), 0.0f)) {
446 SC_LOG_ERROR("SecurityComponentCheckFail: Parent %{public}s invert is set, security component is invalid",
447 node->GetTag().c_str());
448 message = ", attribute invert of parent component " + node->GetTag() +
449 "(id = " + std::to_string(node->GetId()) + ") is set";
450 return true;
451 }
452 return false;
453 }
454
CheckSepia(const RefPtr<FrameNode> & node,const RefPtr<RenderContext> & renderContext,std::string & message)455 bool SecurityComponentHandler::CheckSepia(const RefPtr<FrameNode>& node, const RefPtr<RenderContext>& renderContext,
456 std::string& message)
457 {
458 if (renderContext->GetFrontSepia().has_value() &&
459 !NearEqual(renderContext->GetFrontSepia().value().ConvertToVp(), 0.0f)) {
460 SC_LOG_ERROR("SecurityComponentCheckFail: Parent %{public}s sepia is set, security component is invalid",
461 node->GetTag().c_str());
462 message = ", attribute sepia of parent component " + node->GetTag() +
463 "(id = " + std::to_string(node->GetId()) + ") is set";
464 return true;
465 }
466 return false;
467 }
468
CheckHueRotate(const RefPtr<FrameNode> & node,const RefPtr<RenderContext> & renderContext,std::string & message)469 bool SecurityComponentHandler::CheckHueRotate(const RefPtr<FrameNode>& node, const RefPtr<RenderContext>& renderContext,
470 std::string& message)
471 {
472 if (renderContext->GetFrontHueRotate().has_value() &&
473 !NearEqual(renderContext->GetFrontHueRotate().value(), 0.0f) &&
474 !NearEqual(renderContext->GetFrontHueRotate().value(), 360.0f)) {
475 SC_LOG_ERROR("SecurityComponentCheckFail: Parent %{public}s hueRotate is set, security component is invalid",
476 node->GetTag().c_str());
477 message = ", attribute hueRotate of parent component " + node->GetTag() +
478 "(id = " + std::to_string(node->GetId()) + ") is set";
479 return true;
480 }
481 return false;
482 }
483
CheckColorBlend(const RefPtr<FrameNode> & node,const RefPtr<RenderContext> & renderContext,std::string & message)484 bool SecurityComponentHandler::CheckColorBlend(const RefPtr<FrameNode>& node,
485 const RefPtr<RenderContext>& renderContext, std::string& message)
486 {
487 if (renderContext->GetFrontColorBlend().has_value() &&
488 (renderContext->GetFrontColorBlend().value() != Color::TRANSPARENT)) {
489 SC_LOG_ERROR("SecurityComponentCheckFail: Parent %{public}s colorBlend is set, security component is invalid",
490 node->GetTag().c_str());
491 message = ", attribute colorBlend of parent component " + node->GetTag() +
492 "(id = " + std::to_string(node->GetId()) + ") is set";
493 return true;
494 }
495 return false;
496 }
497
CheckClipMask(const RefPtr<FrameNode> & node,const RefPtr<RenderContext> & renderContext,std::string & message)498 bool SecurityComponentHandler::CheckClipMask(const RefPtr<FrameNode>& node, const RefPtr<RenderContext>& renderContext,
499 std::string& message)
500 {
501 if (renderContext->GetClipMask().has_value()) {
502 SC_LOG_ERROR("SecurityComponentCheckFail: Parent %{public}s clip mask is set, security component is invalid",
503 node->GetTag().c_str());
504 message = ", attribute maskShape of parent component " + node->GetTag() +
505 "(id = " + std::to_string(node->GetId()) + ") is set";
506 return true;
507 }
508 return false;
509 }
510
CheckForegroundColor(const RefPtr<FrameNode> & node,const RefPtr<RenderContext> & renderContext,std::string & message)511 bool SecurityComponentHandler::CheckForegroundColor(const RefPtr<FrameNode>& node,
512 const RefPtr<RenderContext>& renderContext, std::string& message)
513 {
514 if (renderContext->GetForegroundColor().has_value()) {
515 SC_LOG_ERROR("SecurityComponentCheckFail: Parent %{public}s foregroundColor is set, " \
516 "security component is invalid", node->GetTag().c_str());
517 message = ", attribute foregroundColor of parent component " + node->GetTag() +
518 "(id = " + std::to_string(node->GetId()) + ") is set";
519 return true;
520 }
521 return false;
522 }
523
CheckSphericalEffect(const RefPtr<FrameNode> & node,const RefPtr<RenderContext> & renderContext,std::string & message)524 bool SecurityComponentHandler::CheckSphericalEffect(const RefPtr<FrameNode>& node,
525 const RefPtr<RenderContext>& renderContext, std::string& message)
526 {
527 if (renderContext->GetSphericalEffect().has_value() &&
528 !NearEqual(renderContext->GetSphericalEffect().value(), 0.0f)) {
529 SC_LOG_ERROR("SecurityComponentCheckFail: Parent %{public}s sphericalEffect is set, " \
530 "security component is invalid", node->GetTag().c_str());
531 message = ", attribute sphericalEffect of parent component " + node->GetTag() +
532 "(id = " + std::to_string(node->GetId()) + ") is set";
533 return true;
534 }
535 return false;
536 }
537
CheckLightUpEffect(const RefPtr<FrameNode> & node,const RefPtr<RenderContext> & renderContext,std::string & message)538 bool SecurityComponentHandler::CheckLightUpEffect(const RefPtr<FrameNode>& node,
539 const RefPtr<RenderContext>& renderContext, std::string& message)
540 {
541 if (renderContext->GetLightUpEffect().has_value()) {
542 SC_LOG_ERROR("SecurityComponentCheckFail: Parent %{public}s lightUpEffect is set, " \
543 "security component is invalid", node->GetTag().c_str());
544 message = ", attribute lightUpEffect of parent component " + node->GetTag() +
545 "(id = " + std::to_string(node->GetId()) + ") is set";
546 return true;
547 }
548 return false;
549 }
550
CheckPixelStretchEffect(const RefPtr<FrameNode> & node,const RefPtr<RenderContext> & renderContext,std::string & message)551 bool SecurityComponentHandler::CheckPixelStretchEffect(const RefPtr<FrameNode>& node,
552 const RefPtr<RenderContext>& renderContext, std::string& message)
553 {
554 if (renderContext->GetPixelStretchEffect().has_value()) {
555 SC_LOG_ERROR("SecurityComponentCheckFail: Parent %{public}s pixelStretchEffect is set, " \
556 "security component is invalid", node->GetTag().c_str());
557 message = ", attribute pixelStretchEffect of parent component " + node->GetTag() +
558 "(id = " + std::to_string(node->GetId()) + ") is set";
559 return true;
560 }
561 return false;
562 }
563
CheckForegroundEffect(const RefPtr<FrameNode> & node,std::string & message,const RefPtr<RenderContext> & renderContext,OHOS::Security::SecurityComponent::SecCompBase & buttonInfo)564 bool SecurityComponentHandler::CheckForegroundEffect(const RefPtr<FrameNode>& node, std::string& message,
565 const RefPtr<RenderContext>& renderContext, OHOS::Security::SecurityComponent::SecCompBase& buttonInfo)
566 {
567 if (!NearEqual(renderContext->GetForegroundEffect().value_or(0.0f), 0.0f)) {
568 buttonInfo.hasNonCompatibleChange_ = true;
569 buttonInfo.foregroundBlurRadius_ = renderContext->GetForegroundEffect().value();
570 }
571 return false;
572 }
573
CheckOverlayText(const RefPtr<FrameNode> & node,std::string & message,const RefPtr<RenderContext> & renderContext,OHOS::Security::SecurityComponent::SecCompBase & buttonInfo)574 bool SecurityComponentHandler::CheckOverlayText(const RefPtr<FrameNode>& node, std::string& message,
575 const RefPtr<RenderContext>& renderContext, OHOS::Security::SecurityComponent::SecCompBase& buttonInfo)
576 {
577 auto overlayText = renderContext->GetOverlayText();
578 if (overlayText.has_value()) {
579 buttonInfo.hasNonCompatibleChange_ = true;
580 buttonInfo.isOverlayTextSet_ = true;
581 }
582 return false;
583 }
584
CheckRenderEffect(const RefPtr<FrameNode> & secNode,RefPtr<FrameNode> & parentNode,std::string & message,OHOS::Security::SecurityComponent::SecCompBase & buttonInfo)585 bool SecurityComponentHandler::CheckRenderEffect(const RefPtr<FrameNode>& secNode, RefPtr<FrameNode>& parentNode,
586 std::string& message, OHOS::Security::SecurityComponent::SecCompBase& buttonInfo)
587 {
588 const auto& renderContext = parentNode->GetRenderContext();
589 CHECK_NULL_RETURN(renderContext, false);
590 auto layoutProperty = parentNode->GetLayoutProperty();
591 CHECK_NULL_RETURN(layoutProperty, false);
592
593 using CheckFunc = bool(*)(const RefPtr<FrameNode>& parentNode,
594 const RefPtr<RenderContext>& renderContext, std::string& message);
595
596 const std::array<CheckFunc, PARENT_EFFECT_CHECK_FUNC_NUM> renderChecks = {
597 &CheckOpacity,
598 &CheckBrightness,
599 &CheckBlur,
600 &CheckSaturate,
601 &CheckContrast,
602 &CheckInvert,
603 &CheckSepia,
604 &CheckHueRotate,
605 &CheckColorBlend,
606 &CheckForegroundColor,
607 &CheckSphericalEffect,
608 &CheckLightUpEffect,
609 &CheckPixelStretchEffect,
610 &CheckForegroundBlurStyle,
611 &CheckBlendMode
612 };
613
614 for (auto check : renderChecks) {
615 if (check(parentNode, renderContext, message)) {
616 return true;
617 }
618 }
619
620 if (CheckVisibility(parentNode, layoutProperty, message) ||
621 CheckForegroundEffect(parentNode, message, renderContext, buttonInfo) ||
622 CheckOverlayText(parentNode, message, renderContext, buttonInfo)) {
623 return true;
624 }
625 if (secNode->GetTag() != V2::SAVE_BUTTON_ETS_TAG) {
626 return CheckClipMask(parentNode, renderContext, message);
627 }
628 return false;
629 }
630
GetClipErrorMsg(const std::string & scId,const std::string & scType,const RectF & visibleRect,const RectF & frameRect,const RefPtr<FrameNode> & parentNode)631 std::string GetClipErrorMsg(const std::string& scId, const std::string& scType,
632 const RectF& visibleRect, const RectF& frameRect, const RefPtr<FrameNode>& parentNode)
633 {
634 std::string message = "The id of " + scType + " is " + scId +
635 ", attribute clip of parent component " + parentNode->GetTag() +
636 "(id = " + std::to_string(parentNode->GetId()) + ") is set, " + scType +
637 " is not completely displayed. The rect of visible part is {width = " +
638 std::to_string(visibleRect.Width()) +
639 ", height = " + std::to_string(visibleRect.Height()) +
640 "}, the real size of " + scType + " is {width = " +
641 std::to_string(frameRect.Width()) +
642 ", height = " + std::to_string(frameRect.Height()) + "}";
643 return message;
644 }
645
IsSecComponentClipped(RefPtr<FrameNode> & parentNode,RectF & visibleRect,const RectF & frameRect,OHOS::Security::SecurityComponent::SecCompBase & buttonInfo)646 bool SecurityComponentHandler::IsSecComponentClipped(RefPtr<FrameNode>& parentNode,
647 RectF& visibleRect, const RectF& frameRect, OHOS::Security::SecurityComponent::SecCompBase& buttonInfo)
648 {
649 GetVisibleRect(parentNode, visibleRect);
650 bool isClipped = IsOutOfParentWithRound(visibleRect, frameRect, buttonInfo);
651 buttonInfo.isClipped_ = isClipped;
652 buttonInfo.parentTag_ = parentNode->GetTag();
653
654 if (isClipped && (visibleRect.IsValid() || frameRect.IsValid())) {
655 SC_LOG_ERROR("SecurityComponentCheckFail: Parents clip is set, " \
656 "security component is not completely displayed.");
657 SC_LOG_ERROR("visibleWidth: %{public}f, visibleHeight: %{public}f, " \
658 "frameWidth: %{public}f, frameHeight: %{public}f",
659 visibleRect.Width(), visibleRect.Height(), frameRect.Width(), frameRect.Height());
660 return true;
661 }
662 return false;
663 }
664
CheckOverlayNode(RefPtr<FrameNode> & parentNode,RefPtr<FrameNode> & node,std::string & message,OHOS::Security::SecurityComponent::SecCompBase & buttonInfo)665 bool SecurityComponentHandler::CheckOverlayNode(RefPtr<FrameNode>& parentNode, RefPtr<FrameNode>& node,
666 std::string& message, OHOS::Security::SecurityComponent::SecCompBase& buttonInfo)
667 {
668 CHECK_NULL_RETURN(parentNode, false);
669 auto overlayNode = parentNode->GetOverlayNode();
670 CHECK_NULL_RETURN(overlayNode, false);
671 auto overlayRect = overlayNode->GetPaintRectWithTransform();
672 CHECK_NULL_RETURN(node, false);
673 auto secRect = node->GetPaintRectWithTransform();
674 if (overlayRect.IsInnerIntersectWithRound(secRect)) {
675 buttonInfo.hasNonCompatibleChange_ = true;
676 buttonInfo.isOverlayNodeCovered_ = true;
677 }
678 return false;
679 }
680
CheckParentNodesEffect(RefPtr<FrameNode> & node,OHOS::Security::SecurityComponent::SecCompBase & buttonInfo,std::string & message)681 bool SecurityComponentHandler::CheckParentNodesEffect(RefPtr<FrameNode>& node,
682 OHOS::Security::SecurityComponent::SecCompBase& buttonInfo, std::string& message)
683 {
684 RefPtr<RenderContext> renderContext = node->GetRenderContext();
685 CHECK_NULL_RETURN(renderContext, false);
686 auto frameRect = renderContext->GetPaintRectWithTransform();
687 frameRect.SetOffset(node->GetPositionToWindowWithTransform());
688 auto visibleRect = frameRect;
689 auto parent = node->GetParent();
690 std::string scId = std::to_string(node->GetId());
691 std::string scType = node->GetTag();
692 while (parent != nullptr) {
693 auto parentNode = AceType::DynamicCast<FrameNode>(parent);
694 if (parentNode == nullptr) {
695 parent = parent->GetParent();
696 continue;
697 }
698 if (parentNode->CheckTopWindowBoundary()) {
699 break;
700 }
701 if (CheckRenderEffect(node, parentNode, message, buttonInfo) ||
702 CheckParentBorder(parentNode, frameRect, message)) {
703 message = SEC_COMP_ID + scId + SEC_COMP_TYPE + scType + message;
704 return true;
705 }
706 CheckOverlayNode(parentNode, node, message, buttonInfo);
707 if (CheckLinearGradientBlur(parentNode, node, buttonInfo.hasNonCompatibleChange_, buttonInfo.blurRadius_)) {
708 SC_LOG_ERROR("SecurityComponentCheckFail: Parent %{public}s LinearGradientBlur is set, " \
709 "security component is invalid", parentNode->GetTag().c_str());
710 message = SEC_COMP_ID + scId + SEC_COMP_TYPE + scType +
711 ", attribute linearGradientBlur of parent component " +
712 parentNode->GetTag() + " is set";
713 return true;
714 }
715 RefPtr<RenderContext> parentRenderContext = parentNode->GetRenderContext();
716 if ((node->GetTag() == V2::SAVE_BUTTON_ETS_TAG) || (parentRenderContext == nullptr) ||
717 !parentRenderContext->GetClipEdge().value_or(false)) {
718 parent = parent->GetParent();
719 continue;
720 }
721 if (IsSecComponentClipped(parentNode, visibleRect, frameRect, buttonInfo)) {
722 message = GetClipErrorMsg(scId, scType, visibleRect, frameRect, parentNode);
723 return true;
724 }
725 parent = parent->GetParent();
726 }
727 return false;
728 }
729
GetVisibleRect(RefPtr<FrameNode> & node,RectF & visibleRect)730 void SecurityComponentHandler::GetVisibleRect(RefPtr<FrameNode>& node, RectF& visibleRect)
731 {
732 auto renderContext = node->GetRenderContext();
733 CHECK_NULL_VOID(renderContext);
734 RectF parentRect = renderContext->GetPaintRectWithTransform();
735 parentRect.SetOffset(node->GetPositionToWindowWithTransform());
736 visibleRect = visibleRect.Constrain(parentRect);
737 }
738
IsOutOfParentWithRound(const RectF & visibleRect,const RectF & renderRect,OHOS::Security::SecurityComponent::SecCompBase & buttonInfo)739 bool SecurityComponentHandler::IsOutOfParentWithRound(const RectF& visibleRect, const RectF& renderRect,
740 OHOS::Security::SecurityComponent::SecCompBase& buttonInfo)
741 {
742 if (!visibleRect.IsValid() || !renderRect.IsValid()) {
743 return true;
744 }
745
746 if (NearEqual(visibleRect.Width(), 0.0) || NearEqual(visibleRect.Height(), 0.0) ||
747 NearEqual(renderRect.Width(), 0.0) || NearEqual(renderRect.Height(), 0.0)) {
748 return true;
749 }
750
751 buttonInfo.leftClip_ = visibleRect.Left() - renderRect.Left();
752 buttonInfo.rightClip_ = renderRect.Right() - visibleRect.Right();
753 buttonInfo.topClip_ = visibleRect.Top() - renderRect.Top();
754 buttonInfo.bottomClip_ = renderRect.Bottom() - visibleRect.Bottom();
755
756 return LessNotEqual(renderRect.Left() + 1.0, visibleRect.Left()) ||
757 GreatNotEqual(renderRect.Right(), visibleRect.Right() + 1.0) ||
758 LessNotEqual(renderRect.Top() + 1.0, visibleRect.Top()) ||
759 GreatNotEqual(renderRect.Bottom(), visibleRect.Bottom() + 1.0);
760 }
761
GetWindowSceneWindowId(RefPtr<FrameNode> & node,uint32_t & windId)762 bool SecurityComponentHandler::GetWindowSceneWindowId(RefPtr<FrameNode>& node, uint32_t& windId)
763 {
764 CHECK_NULL_RETURN(node, false);
765 auto parent = node->GetParent();
766 while (parent != nullptr && parent->GetTag() != V2::WINDOW_SCENE_ETS_TAG) {
767 parent = parent->GetParent();
768 }
769 CHECK_NULL_RETURN(parent, false);
770 auto windowSceneFrameNode = AceType::DynamicCast<FrameNode>(parent);
771 CHECK_NULL_RETURN(windowSceneFrameNode, false);
772 auto windowScene = windowSceneFrameNode->GetPattern<SystemWindowScene>();
773 CHECK_NULL_RETURN(windowScene, false);
774 auto session = windowScene->GetSession();
775 CHECK_NULL_RETURN(session, false);
776
777 windId = static_cast<uint32_t>(session->GetPersistentId());
778 return true;
779 }
780
GetPaddingInfo(OHOS::Security::SecurityComponent::SecCompBase & buttonInfo,RefPtr<FrameNode> & node)781 bool SecurityComponentHandler::GetPaddingInfo(OHOS::Security::SecurityComponent::SecCompBase& buttonInfo,
782 RefPtr<FrameNode>& node)
783 {
784 CHECK_NULL_RETURN(node, false);
785 auto layoutProperty = AceType::DynamicCast<SecurityComponentLayoutProperty>(node->GetLayoutProperty());
786 CHECK_NULL_RETURN(layoutProperty, false);
787 auto pipeline = node->GetContextRefPtr();
788 CHECK_NULL_RETURN(pipeline, false);
789 auto theme = pipeline->GetTheme<SecurityComponentTheme>();
790 CHECK_NULL_RETURN(theme, false);
791 buttonInfo.padding_.top =
792 layoutProperty->GetBackgroundTopPadding().value_or(theme->GetBackgroundTopPadding()).ConvertToVp();
793 buttonInfo.padding_.right =
794 layoutProperty->GetBackgroundRightPadding().value_or(theme->GetBackgroundRightPadding()).ConvertToVp();
795 buttonInfo.padding_.bottom =
796 layoutProperty->GetBackgroundBottomPadding().value_or(theme->GetBackgroundBottomPadding()).ConvertToVp();
797 buttonInfo.padding_.left =
798 layoutProperty->GetBackgroundLeftPadding().value_or(theme->GetBackgroundLeftPadding()).ConvertToVp();
799 buttonInfo.textIconSpace_ =
800 layoutProperty->GetTextIconSpace().value_or(theme->GetTextIconSpace()).ConvertToVp();
801 return true;
802 }
803
InitBaseInfo(OHOS::Security::SecurityComponent::SecCompBase & buttonInfo,RefPtr<FrameNode> & node)804 bool SecurityComponentHandler::InitBaseInfo(OHOS::Security::SecurityComponent::SecCompBase& buttonInfo,
805 RefPtr<FrameNode>& node)
806 {
807 CHECK_NULL_RETURN(node, false);
808 buttonInfo.nodeId_ = node->GetId();
809 if (!GetPaddingInfo(buttonInfo, node)) {
810 SC_LOG_WARN("InitBaseInfoWarning: Get padding info failed");
811 return false;
812 }
813
814 if (!GetDisplayOffset(node, buttonInfo.rect_.x_, buttonInfo.rect_.y_)) {
815 SC_LOG_WARN("InitBaseInfoWarning: Get display offset failed");
816 return false;
817 }
818
819 if (!GetWindowRect(node, buttonInfo.windowRect_)) {
820 SC_LOG_WARN("InitBaseInfoWarning: Get window rect failed");
821 return false;
822 }
823 auto render = node->GetRenderContext();
824 CHECK_NULL_RETURN(render, false);
825 auto rect = render->GetPaintRectWithTransform();
826 buttonInfo.rect_.width_ = rect.Width();
827 buttonInfo.rect_.height_ = rect.Height();
828 auto container = AceType::DynamicCast<Platform::AceContainer>(Container::CurrentSafely());
829 CHECK_NULL_RETURN(container, false);
830 uint32_t windId = container->GetWindowId();
831 auto pipeline = node->GetContextRefPtr();
832 CHECK_NULL_RETURN(pipeline, false);
833 if (pipeline->IsFocusWindowIdSetted()) {
834 windId = pipeline->GetFocusWindowId();
835 }
836 if (container->IsSceneBoardWindow()) {
837 GetWindowSceneWindowId(node, windId);
838 }
839 buttonInfo.windowId_ = static_cast<int32_t>(windId);
840 buttonInfo.crossAxisState_ = CrossAxisState::STATE_INVALID;
841 auto instanceId = pipeline->GetInstanceId();
842 auto window = Platform::AceContainer::GetUIWindow(instanceId);
843 if (window) {
844 buttonInfo.crossAxisState_ = static_cast<CrossAxisState>(window->GetCrossAxisState());
845 }
846 uint64_t displayId = container->GetDisplayId();
847 if (displayId == Rosen::DISPLAY_ID_INVALID) {
848 SC_LOG_WARN("InitBaseInfoWarning: Get displayId failed, using default displayId");
849 displayId = 0;
850 }
851 buttonInfo.displayId_ = displayId;
852 return true;
853 }
854
InitSCIconInfo(OHOS::Security::SecurityComponent::SecCompBase & buttonInfo,RefPtr<FrameNode> & iconNode)855 bool InitSCIconInfo(OHOS::Security::SecurityComponent::SecCompBase& buttonInfo, RefPtr<FrameNode>& iconNode)
856 {
857 if (iconNode != nullptr) {
858 auto pipeline = iconNode->GetContextRefPtr();
859 CHECK_NULL_RETURN(pipeline, false);
860 auto theme = pipeline->GetTheme<SecurityComponentTheme>();
861 CHECK_NULL_RETURN(theme, false);
862
863 CHECK_NULL_RETURN(iconNode->GetGeometryNode(), false);
864 auto iconProp = iconNode->GetLayoutProperty<ImageLayoutProperty>();
865 CHECK_NULL_RETURN(iconProp, false);
866 CHECK_NULL_RETURN(iconProp->GetCalcLayoutConstraint(), false);
867 auto width = iconProp->GetCalcLayoutConstraint()->selfIdealSize->Width();
868 CHECK_EQUAL_RETURN(width.has_value(), false, false);
869 buttonInfo.iconSize_ = width->GetDimension().ConvertToVp();
870
871 auto fillColor = iconProp->GetImageSourceInfo()->GetFillColor();
872 buttonInfo.iconColor_.value = fillColor.value_or(theme->GetIconColor()).GetValue();
873 }
874 return true;
875 }
876
InitSCSymbolIconInfo(OHOS::Security::SecurityComponent::SecCompBase & buttonInfo,RefPtr<FrameNode> & iconNode)877 bool InitSCSymbolIconInfo(OHOS::Security::SecurityComponent::SecCompBase& buttonInfo,
878 RefPtr<FrameNode>& iconNode)
879 {
880 if (iconNode == nullptr) {
881 return true;
882 }
883
884 CHECK_NULL_RETURN(iconNode->GetGeometryNode(), false);
885 auto iconProp = iconNode->GetLayoutProperty<TextLayoutProperty>();
886 CHECK_NULL_RETURN(iconProp, false);
887 auto fontSize = iconProp->GetFontSize();
888 CHECK_NULL_RETURN(fontSize, false);
889 buttonInfo.iconSize_ = fontSize->ConvertToVp();
890 auto colorList = iconProp->GetSymbolColorList();
891 if (colorList.has_value() && !colorList.value().empty()) {
892 buttonInfo.iconColor_.value = colorList.value()[0].GetValue();
893 }
894 return true;
895 }
896
InitSCTextInfo(OHOS::Security::SecurityComponent::SecCompBase & buttonInfo,RefPtr<FrameNode> & textNode)897 bool InitSCTextInfo(OHOS::Security::SecurityComponent::SecCompBase& buttonInfo,
898 RefPtr<FrameNode>& textNode)
899 {
900 if (textNode != nullptr) {
901 auto textProp = textNode->GetLayoutProperty<TextLayoutProperty>();
902 CHECK_NULL_RETURN(textProp, false);
903 auto pipeline = textNode->GetContextRefPtr();
904 CHECK_NULL_RETURN(pipeline, false);
905 auto theme = pipeline->GetTheme<SecurityComponentTheme>();
906 CHECK_NULL_RETURN(theme, false);
907 if (textProp->GetFontSize().has_value()) {
908 buttonInfo.fontSize_ = textProp->GetFontSize()->Value();
909 } else {
910 buttonInfo.fontSize_ = theme->GetFontSize().Value();
911 }
912 if (textProp->GetTextColor().has_value()) {
913 buttonInfo.fontColor_.value = textProp->GetTextColor().value().GetValue();
914 }
915 }
916 return true;
917 }
918
InitSCButtonInfo(OHOS::Security::SecurityComponent::SecCompBase & buttonInfo,RefPtr<FrameNode> & buttonNode)919 bool InitSCButtonInfo(OHOS::Security::SecurityComponent::SecCompBase& buttonInfo,
920 RefPtr<FrameNode>& buttonNode)
921 {
922 if (buttonNode != nullptr) {
923 const auto& renderContext = buttonNode->GetRenderContext();
924 CHECK_NULL_RETURN(renderContext, false);
925 if (renderContext->GetBackgroundColor().has_value()) {
926 buttonInfo.bgColor_.value = renderContext->GetBackgroundColor().value().GetValue();
927 }
928
929 auto bgProp = buttonNode->GetLayoutProperty<ButtonLayoutProperty>();
930 CHECK_NULL_RETURN(bgProp, false);
931 const auto& borderWidth = bgProp->GetBorderWidthProperty();
932 if (borderWidth != nullptr) {
933 if (borderWidth->leftDimen.has_value()) {
934 buttonInfo.borderWidth_ = borderWidth->leftDimen.value().ConvertToVp();
935 }
936 }
937 }
938 return true;
939 }
940
InitChildInfo(OHOS::Security::SecurityComponent::SecCompBase & buttonInfo,RefPtr<FrameNode> & node)941 bool SecurityComponentHandler::InitChildInfo(OHOS::Security::SecurityComponent::SecCompBase& buttonInfo,
942 RefPtr<FrameNode>& node)
943 {
944 RefPtr<FrameNode> iconNode = GetSecCompChildNode(node, V2::IMAGE_ETS_TAG);
945 if (!InitSCIconInfo(buttonInfo, iconNode)) {
946 return false;
947 }
948
949 RefPtr<FrameNode> symbolIconNode = GetSecCompChildNode(node, V2::SYMBOL_ETS_TAG);
950 if (!InitSCSymbolIconInfo(buttonInfo, symbolIconNode)) {
951 return false;
952 }
953
954 RefPtr<FrameNode> textNode = GetSecCompChildNode(node, V2::TEXT_ETS_TAG);
955 if (!InitSCTextInfo(buttonInfo, textNode)) {
956 return false;
957 }
958
959 RefPtr<FrameNode> buttonNode = GetSecCompChildNode(node, V2::BUTTON_ETS_TAG);
960 if (!InitSCButtonInfo(buttonInfo, buttonNode)) {
961 return false;
962 }
963
964 if (!InitBaseInfo(buttonInfo, node)) {
965 return false;
966 }
967 return true;
968 }
969
WriteButtonInfo(const RefPtr<OHOS::Ace::NG::SecurityComponentLayoutProperty> & layoutProperty,RefPtr<FrameNode> & node,OHOS::Security::SecurityComponent::SecCompBase & buttonInfo,std::string & message)970 void SecurityComponentHandler::WriteButtonInfo(
971 const RefPtr<OHOS::Ace::NG::SecurityComponentLayoutProperty>& layoutProperty,
972 RefPtr<FrameNode>& node, OHOS::Security::SecurityComponent::SecCompBase& buttonInfo,
973 std::string& message)
974 {
975 buttonInfo.parentEffect_ = CheckParentNodesEffect(node, buttonInfo, message);
976 buttonInfo.text_= layoutProperty->GetSecurityComponentDescription().value_or(
977 static_cast<int32_t>(SaveButtonSaveDescription::TEXT_NULL));
978 buttonInfo.icon_ = layoutProperty->GetIconStyle().value_or(
979 static_cast<int32_t>(SaveButtonIconStyle::ICON_NULL));
980 buttonInfo.bg_ = static_cast<SecCompBackground>(
981 layoutProperty->GetBackgroundType().value_or(static_cast<int32_t>(SecCompBackground::UNKNOWN_BG)));
982 buttonInfo.tipPosition_ = static_cast<Security::SecurityComponent::TipPosition>(
983 layoutProperty->GetTipPosition().value_or(TipPosition::ABOVE_BOTTOM));
984 buttonInfo.isCustomizable_ =
985 (layoutProperty->GetImageSourceInfo().has_value() || layoutProperty->GetTextContent().has_value());
986
987 RectF rect = node->GetTransformRectRelativeToWindow();
988 auto maxRadius = std::min(rect.Width(), rect.Height()) / HALF;
989 if (layoutProperty->GetBackgroundType() == static_cast<int32_t>(ButtonType::CIRCLE) ||
990 layoutProperty->GetBackgroundType() == static_cast<int32_t>(ButtonType::CAPSULE)) {
991 buttonInfo.borderRadius_.leftBottom = maxRadius;
992 buttonInfo.borderRadius_.leftTop = maxRadius;
993 buttonInfo.borderRadius_.rightBottom = maxRadius;
994 buttonInfo.borderRadius_.rightTop = maxRadius;
995 } else {
996 RefPtr<FrameNode> buttonNode = GetSecCompChildNode(node, V2::BUTTON_ETS_TAG);
997 CHECK_NULL_VOID(buttonNode);
998 auto bgProp = buttonNode->GetLayoutProperty<ButtonLayoutProperty>();
999 CHECK_NULL_VOID(bgProp);
1000 const auto& borderRadius = bgProp->GetBorderRadius();
1001 if (borderRadius.has_value()) {
1002 buttonInfo.borderRadius_.leftBottom = borderRadius->radiusBottomLeft.value_or(Dimension(0.0)).ConvertToPx();
1003 buttonInfo.borderRadius_.leftTop = borderRadius->radiusTopLeft.value_or(Dimension(0.0)).ConvertToPx();
1004 buttonInfo.borderRadius_.rightBottom =
1005 borderRadius->radiusBottomRight.value_or(Dimension(0.0)).ConvertToPx();
1006 buttonInfo.borderRadius_.rightTop = borderRadius->radiusTopRight.value_or(Dimension(0.0)).ConvertToPx();
1007 }
1008 }
1009
1010 if (SystemProperties::GetDeviceType() == DeviceType::WEARABLE) {
1011 buttonInfo.isWearableDevice_ = true;
1012 }
1013 }
1014
InitButtonInfoValue(RefPtr<FrameNode> & node,OHOS::Security::SecurityComponent::SecCompBase & buttonInfo,const SecCompType & scType,std::string & message)1015 bool SecurityComponentHandler::InitButtonInfoValue(RefPtr<FrameNode>& node,
1016 OHOS::Security::SecurityComponent::SecCompBase& buttonInfo, const SecCompType& scType, std::string& message)
1017 {
1018 auto layoutProperty = AceType::DynamicCast<SecurityComponentLayoutProperty>(node->GetLayoutProperty());
1019 CHECK_NULL_RETURN(layoutProperty, false);
1020 WriteButtonInfo(layoutProperty, node, buttonInfo, message);
1021 buttonInfo.type_ = scType;
1022 if (layoutProperty->GetIsIconExceeded().has_value() && layoutProperty->GetIsIconExceeded().value()) {
1023 buttonInfo.isIconExceeded_ = true;
1024 buttonInfo.hasNonCompatibleChange_ = true;
1025 }
1026 if (!InitChildInfo(buttonInfo, node)) {
1027 return false;
1028 }
1029 return true;
1030 }
1031
InitButtonInfo(std::string & componentInfo,RefPtr<FrameNode> & node,SecCompType & scType,std::string & message)1032 bool SecurityComponentHandler::InitButtonInfo(std::string& componentInfo, RefPtr<FrameNode>& node, SecCompType& scType,
1033 std::string& message)
1034 {
1035 CHECK_NULL_RETURN(node, false);
1036 std::string type = node->GetTag();
1037 if (type == V2::LOCATION_BUTTON_ETS_TAG) {
1038 LocationButton buttonInfo;
1039 scType = SecCompType::LOCATION_COMPONENT;
1040 if (!InitButtonInfoValue(node, buttonInfo, scType, message)) {
1041 return false;
1042 }
1043 componentInfo = buttonInfo.ToJsonStr();
1044 } else if (type == V2::PASTE_BUTTON_ETS_TAG) {
1045 PasteButton buttonInfo;
1046 scType = SecCompType::PASTE_COMPONENT;
1047 if (!InitButtonInfoValue(node, buttonInfo, scType, message)) {
1048 return false;
1049 }
1050 componentInfo = buttonInfo.ToJsonStr();
1051 } else if (type == V2::SAVE_BUTTON_ETS_TAG) {
1052 SaveButton buttonInfo;
1053 scType = SecCompType::SAVE_COMPONENT;
1054 if (!InitButtonInfoValue(node, buttonInfo, scType, message)) {
1055 return false;
1056 }
1057 componentInfo = buttonInfo.ToJsonStr();
1058 } else {
1059 return false;
1060 }
1061 return true;
1062 }
1063
UpdateClipRect(NG::RectF & clipRect,NG::RectF & paintRect)1064 NG::RectF SecurityComponentHandler::UpdateClipRect(NG::RectF& clipRect, NG::RectF& paintRect)
1065 {
1066 if (clipRect.IsIntersectWith(paintRect)) {
1067 return clipRect.IntersectRectT(paintRect);
1068 }
1069
1070 return NG::RectF(0.0, 0.0, 0.0, 0.0);
1071 }
1072
UpdatePaintRect(NG::RectF & paintRect,NG::RectF & clipRect)1073 NG::RectF SecurityComponentHandler::UpdatePaintRect(NG::RectF& paintRect, NG::RectF& clipRect)
1074 {
1075 if (NearEqual(clipRect.Width(), -1.0) && NearEqual(clipRect.Height(), -1.0)) {
1076 return paintRect;
1077 }
1078
1079 if (paintRect.IsIntersectWith(clipRect)) {
1080 return paintRect.IntersectRectT(clipRect);
1081 }
1082
1083 return NG::RectF(0.0, 0.0, 0.0, 0.0);
1084 }
1085
RegisterSecurityComponent(RefPtr<FrameNode> & node,int32_t & scId)1086 int32_t SecurityComponentHandler::RegisterSecurityComponent(RefPtr<FrameNode>& node, int32_t& scId)
1087 {
1088 SecurityComponentHandler::probe.InitProbeTask();
1089 std::string componentInfo;
1090 SecCompType type;
1091 std::string message;
1092 if (!InitButtonInfo(componentInfo, node, type, message)) {
1093 return -1;
1094 }
1095 int32_t ret = SecCompKit::RegisterSecurityComponent(
1096 type, componentInfo, scId);
1097 return ret;
1098 }
1099
UpdateSecurityComponent(RefPtr<FrameNode> & node,int32_t & scId)1100 int32_t SecurityComponentHandler::UpdateSecurityComponent(RefPtr<FrameNode>& node, int32_t& scId)
1101 {
1102 std::string componentInfo;
1103 SecCompType type;
1104 std::string message;
1105 if (!InitButtonInfo(componentInfo, node, type, message)) {
1106 return -1;
1107 }
1108 int32_t ret = SecCompKit::UpdateSecurityComponent(scId, componentInfo);
1109 return ret;
1110 }
1111
UnregisterSecurityComponent(int32_t & scId)1112 int32_t SecurityComponentHandler::UnregisterSecurityComponent(int32_t& scId)
1113 {
1114 if (scId == -1) {
1115 return -1;
1116 }
1117 int32_t ret = SecCompKit::UnregisterSecurityComponent(scId);
1118 return ret;
1119 }
1120
IsContextTransparent(const RefPtr<FrameNode> & frameNode)1121 bool SecurityComponentHandler::IsContextTransparent(const RefPtr<FrameNode>& frameNode)
1122 {
1123 const RefPtr<RenderContext> renderContext = frameNode->GetRenderContext();
1124 CHECK_NULL_RETURN(renderContext, false);
1125 auto layoutProperty = frameNode->GetLayoutProperty();
1126 CHECK_NULL_RETURN(layoutProperty, false);
1127 if (renderContext->GetOpacity().has_value() && renderContext->GetOpacity().value() == 0.0) {
1128 return true;
1129 }
1130 if (static_cast<int32_t>(layoutProperty->GetVisibility().value_or(VisibleType::VISIBLE)) != 0) {
1131 return true;
1132 }
1133 return false;
1134 }
1135
CheckContainerTags(const RefPtr<FrameNode> & frameNode)1136 bool SecurityComponentHandler::CheckContainerTags(const RefPtr<FrameNode>& frameNode)
1137 {
1138 static std::set<std::string> containerComponentTags = { "Flex", "Stack", "Row", "Column", "WindowScene", "root",
1139 "Swiper", "Grid", "GridItem", "page", "stage", "FormComponent", "Tabs", "TabContent", "ColumnSplit",
1140 "FolderStack", "GridCol", "GridRow", "RelativeContainer", "RowSplit", "List", "Scroll", "WaterFlow",
1141 "SideBarContainer", "Refresh", "Navigator", "ListItemGroup", "ListItem", "Hyperlink", "FormLink", "FlowItem",
1142 "Counter", "Custom", "overlay" };
1143
1144 const RefPtr<RenderContext> renderContext = frameNode->GetRenderContext();
1145 CHECK_NULL_RETURN(renderContext, false);
1146 if (containerComponentTags.find(frameNode->GetTag()) != containerComponentTags.end() &&
1147 renderContext->GetBackgroundColor()->ColorToString().compare("#00000000") == 0) {
1148 return true;
1149 }
1150 return false;
1151 }
1152
IsInModalPage(const RefPtr<UINode> & node)1153 bool SecurityComponentHandler::IsInModalPage(const RefPtr<UINode>& node)
1154 {
1155 RefPtr<UINode> tmpNode = node;
1156 while (tmpNode) {
1157 if (tmpNode->GetTag() == V2::MODAL_PAGE_TAG) {
1158 return true;
1159 }
1160 tmpNode = tmpNode->GetParent();
1161 }
1162 return false;
1163 }
1164
CheckSecurityComponentStatus(const RefPtr<UINode> & root,NodeMaps & maps,int32_t secNodeId,std::string & message,NG::RectF & clipRect)1165 bool SecurityComponentHandler::CheckSecurityComponentStatus(const RefPtr<UINode>& root, NodeMaps& maps,
1166 int32_t secNodeId, std::string& message, NG::RectF& clipRect)
1167 {
1168 bool res = false;
1169 RectF paintRect;
1170
1171 auto frameNode = AceType::DynamicCast<NG::FrameNode>(root);
1172 if (frameNode) {
1173 paintRect = frameNode->GetTransformRectRelativeToWindow();
1174 if (IsSecurityComponent(frameNode) && (frameNode->GetId() == secNodeId)) {
1175 if (IsInModalPage(root)) {
1176 return false;
1177 }
1178 return CheckRectIntersect(paintRect, secNodeId, maps.nodeId2Rect, maps.nodeId2Zindex, message);
1179 }
1180 }
1181 auto& children = root->GetChildren();
1182 for (auto child = children.rbegin(); child != children.rend(); ++child) {
1183 auto node = AceType::DynamicCast<NG::FrameNode>(*child);
1184 if (node && (IsContextTransparent(node) || !node->IsActive())) {
1185 continue;
1186 }
1187 NG::RectF bakClipRect = clipRect;
1188 if (frameNode && frameNode->GetRenderContext() &&
1189 frameNode->GetRenderContext()->GetClipEdge().has_value() && frameNode->GetRenderContext()->GetClipEdge()) {
1190 if (NearEqual(clipRect.Width(), -1.0) && NearEqual(clipRect.Height(), -1.0)) {
1191 clipRect = paintRect;
1192 } else {
1193 clipRect = UpdateClipRect(clipRect, paintRect);
1194 }
1195 }
1196 res |= CheckSecurityComponentStatus(*child, maps, secNodeId, message, clipRect);
1197 clipRect = bakClipRect;
1198 }
1199
1200 if (frameNode && frameNode->GetTag() != V2::SHEET_WRAPPER_TAG && !CheckContainerTags(frameNode)) {
1201 paintRect = UpdatePaintRect(paintRect, clipRect);
1202 maps.nodeId2Rect[frameNode->GetId()] = std::make_pair(frameNode->GetTag(), paintRect);
1203 }
1204 return res;
1205 }
1206
CheckRectIntersect(const RectF & dest,int32_t secNodeId,const std::unordered_map<int32_t,std::pair<std::string,NG::RectF>> & nodeId2Rect,std::unordered_map<int32_t,int32_t> & nodeId2Zindex,std::string & message)1207 bool SecurityComponentHandler::CheckRectIntersect(const RectF& dest, int32_t secNodeId,
1208 const std::unordered_map<int32_t, std::pair<std::string, NG::RectF>>& nodeId2Rect,
1209 std::unordered_map<int32_t, int32_t>& nodeId2Zindex, std::string& message)
1210 {
1211 for (const auto& originRect : nodeId2Rect) {
1212 if (originRect.second.second.IsInnerIntersectWithRound(dest) &&
1213 (nodeId2Zindex[secNodeId] <= nodeId2Zindex[originRect.first]) &&
1214 (!NearEqual(originRect.second.second.Width(), 0.0) && !NearEqual(originRect.second.second.Height(), 0.0))) {
1215 SC_LOG_ERROR("SecurityComponentCheckFail: Security component id = %{public}d " \
1216 "is covered by id = %{public}d.", secNodeId, originRect.first);
1217 message = ", security component is covered by component " + originRect.second.first +
1218 "(id = " + std::to_string(originRect.first) +
1219 "), the size of security component is (x = " +
1220 std::to_string(dest.GetX()) +
1221 ", y = " + std::to_string(dest.GetY()) +
1222 ", width = " + std::to_string(dest.Width()) +
1223 ", height = " + std::to_string(dest.Height()) +
1224 "), the size of the component of covering security component "
1225 "is (x = " + std::to_string(originRect.second.second.GetX()) +
1226 ", y = " + std::to_string(originRect.second.second.GetY()) +
1227 ", width = " + std::to_string(originRect.second.second.Width()) +
1228 ", height = " + std::to_string(originRect.second.second.Height()) + ")";
1229 return true;
1230 }
1231 }
1232 return false;
1233 }
1234
IsSecurityComponent(RefPtr<FrameNode> & node)1235 bool SecurityComponentHandler::IsSecurityComponent(RefPtr<FrameNode>& node)
1236 {
1237 return node->GetTag() == V2::LOCATION_BUTTON_ETS_TAG || node->GetTag() == V2::PASTE_BUTTON_ETS_TAG ||
1238 node->GetTag() == V2::SAVE_BUTTON_ETS_TAG;
1239 }
1240
GetNodeZIndex(const RefPtr<UINode> & root)1241 int32_t SecurityComponentHandler::GetNodeZIndex(const RefPtr<UINode>& root)
1242 {
1243 int32_t zIndex;
1244 auto node = AceType::DynamicCast<NG::FrameNode>(root);
1245 if (node) {
1246 const RefPtr<RenderContext> renderContext = node->GetRenderContext();
1247 if (!renderContext) {
1248 zIndex = 0;
1249 } else {
1250 zIndex = renderContext->GetZIndexValue(ZINDEX_DEFAULT_VALUE);
1251 }
1252 } else {
1253 zIndex = 0;
1254 }
1255
1256 return zIndex;
1257 }
1258
UpdateAllZindex(const RefPtr<UINode> & root,std::unordered_map<int32_t,int32_t> & nodeId2Zindex)1259 void SecurityComponentHandler::UpdateAllZindex(const RefPtr<UINode>& root,
1260 std::unordered_map<int32_t, int32_t>& nodeId2Zindex)
1261 {
1262 if (nodeId2Zindex.count(root->GetId()) == 0) {
1263 nodeId2Zindex[root->GetId()] = GetNodeZIndex(root);
1264 }
1265 auto& children = root->GetChildren();
1266 for (auto child = children.begin(); child != children.end(); ++child) {
1267 int32_t nodeZIndex = GetNodeZIndex(*child);
1268 nodeId2Zindex[(*child)->GetId()] = std::max(nodeZIndex, nodeId2Zindex[root->GetId()]);
1269 UpdateAllZindex(*child, nodeId2Zindex);
1270 }
1271 }
1272
CheckComponentCoveredStatus(int32_t secNodeId,std::string & message)1273 bool SecurityComponentHandler::CheckComponentCoveredStatus(int32_t secNodeId, std::string& message)
1274 {
1275 auto pipeline = PipelineContext::GetCurrentContextSafely();
1276 CHECK_NULL_RETURN(pipeline, false);
1277 RefPtr<UINode> root = pipeline->GetRootElement();
1278 CHECK_NULL_RETURN(root, false);
1279 NodeMaps maps;
1280 UpdateAllZindex(root, maps.nodeId2Zindex);
1281 NG::RectF clipRect = NG::RectF(-1.0, -1.0, -1.0, -1.0);
1282 if (CheckSecurityComponentStatus(root, maps, secNodeId, message, clipRect)) {
1283 return true;
1284 }
1285 return false;
1286 }
1287
ReportSecurityComponentClickEventInner(int32_t & scId,RefPtr<FrameNode> & node,SecCompClickEvent & event,Security::SecurityComponent::OnFirstUseDialogCloseFunc && callback,std::string & message)1288 int32_t SecurityComponentHandler::ReportSecurityComponentClickEventInner(int32_t& scId,
1289 RefPtr<FrameNode>& node, SecCompClickEvent& event,
1290 Security::SecurityComponent::OnFirstUseDialogCloseFunc&& callback, std::string& message)
1291 {
1292 std::string componentInfo;
1293 SecCompType type;
1294 std::string invalidEffectMsg;
1295 auto ret = InitButtonInfo(componentInfo, node, type, invalidEffectMsg);
1296 if (!ret) {
1297 return -1;
1298 }
1299 bool isSecCompCheckFailed = false;
1300 if (!message.empty()) {
1301 isSecCompCheckFailed = true;
1302 }
1303 auto container = AceType::DynamicCast<Platform::AceContainer>(Container::CurrentSafely());
1304 CHECK_NULL_RETURN(container, -1);
1305 sptr<IRemoteObject> token = container->GetToken();
1306 if (container->GetParentToken() != nullptr) {
1307 token = container->GetParentToken();
1308 }
1309 SecCompInfo secCompInfo{ scId, componentInfo, event };
1310 int32_t res = SecCompKit::ReportSecurityComponentClickEvent(
1311 secCompInfo, token, std::move(callback), message);
1312 if (isSecCompCheckFailed) {
1313 return res;
1314 }
1315 if (!message.empty() && message != "PARENT_HAVE_INVALID_EFFECT") {
1316 message = SEC_COMP_ID + std::to_string(node->GetId()) + SEC_COMP_TYPE + node->GetTag() + message;
1317 }
1318
1319 if (res == SC_SERVICE_ERROR_COMPONENT_INFO_INVALID && !message.empty() &&
1320 message == "PARENT_HAVE_INVALID_EFFECT") {
1321 message = invalidEffectMsg;
1322 }
1323 return res;
1324 }
1325
CheckSecurityComponentClickEvent(const RefPtr<FrameNode> & node,std::string & message)1326 void SecurityComponentHandler::CheckSecurityComponentClickEvent(const RefPtr<FrameNode>& node, std::string& message)
1327 {
1328 auto layoutProperty = AceType::DynamicCast<SecurityComponentLayoutProperty>(node->GetLayoutProperty());
1329 if (layoutProperty && layoutProperty->GetIsMaxLineLimitExceeded().has_value() &&
1330 layoutProperty->GetIsMaxLineLimitExceeded().value()) {
1331 SC_LOG_ERROR("SecurityComponentCheckFail: The text of the security component is cliped by lines.");
1332 message = SEC_COMP_ID + std::to_string(node->GetId()) + SEC_COMP_TYPE +
1333 node->GetTag() + ", the text of the security component is cliped by lines";
1334 return;
1335 }
1336 if (layoutProperty && layoutProperty->GetIsTextLimitExceeded().has_value() &&
1337 layoutProperty->GetIsTextLimitExceeded().value()) {
1338 SC_LOG_ERROR("SecurityComponentCheckFail: The text of the security component is out of range.");
1339 message = SEC_COMP_ID + std::to_string(node->GetId()) + SEC_COMP_TYPE +
1340 node->GetTag() + ", the text of the security component is out of range";
1341 return;
1342 }
1343 if (node->GetTag() == V2::SAVE_BUTTON_ETS_TAG) {
1344 return;
1345 }
1346 if (CheckComponentCoveredStatus(node->GetId(), message)) {
1347 SC_LOG_ERROR("SecurityComponentCheckFail: Security component is covered by another component.");
1348 message = SEC_COMP_ID + std::to_string(node->GetId()) + SEC_COMP_TYPE + node->GetTag() + message;
1349 return;
1350 }
1351 }
1352
ReportSecurityComponentClickEvent(int32_t & scId,RefPtr<FrameNode> & node,const SecCompEnhanceEvent & event,Security::SecurityComponent::OnFirstUseDialogCloseFunc && callback)1353 int32_t SecurityComponentHandler::ReportSecurityComponentClickEvent(int32_t& scId,
1354 RefPtr<FrameNode>& node, const SecCompEnhanceEvent& event,
1355 Security::SecurityComponent::OnFirstUseDialogCloseFunc&& callback)
1356 {
1357 CHECK_NULL_RETURN(node, -1);
1358 SecCompClickEvent secEvent = {};
1359 secEvent.type = ClickEventType::ACCESSIBILITY_EVENT_TYPE;
1360 #ifdef SECURITY_COMPONENT_ENABLE
1361 std::vector<uint8_t> dataBuffer = event.dataBuffer;
1362 if (dataBuffer.size() > 0) {
1363 secEvent.extraInfo.data = dataBuffer.data();
1364 secEvent.extraInfo.dataSize = dataBuffer.size();
1365 }
1366 secEvent.accessibility.timestamp =
1367 static_cast<int64_t>(event.time.time_since_epoch().count()) / SECOND_TO_MILLISECOND;
1368 secEvent.accessibility.componentId = node->GetId();
1369 #endif
1370 std::string message;
1371 CheckSecurityComponentClickEvent(node, message);
1372
1373 return ReportSecurityComponentClickEventInner(scId, node, secEvent, std::move(callback), message);
1374 }
1375
ReportSecurityComponentClickEvent(int32_t & scId,RefPtr<FrameNode> & node,GestureEvent & event,Security::SecurityComponent::OnFirstUseDialogCloseFunc && callback,std::string & message)1376 int32_t SecurityComponentHandler::ReportSecurityComponentClickEvent(int32_t& scId,
1377 RefPtr<FrameNode>& node, GestureEvent& event,
1378 Security::SecurityComponent::OnFirstUseDialogCloseFunc&& callback,
1379 std::string& message)
1380 {
1381 SecCompClickEvent secEvent = {};
1382 secEvent.type = ClickEventType::POINT_EVENT_TYPE;
1383 #ifdef SECURITY_COMPONENT_ENABLE
1384 secEvent.point.touchX = event.GetDisplayX();
1385 secEvent.point.touchY = event.GetDisplayY();
1386 auto pointerEvent = event.GetClickPointerEvent();
1387 uint8_t defaultData = 0;
1388 std::vector<uint8_t> dataBuffer;
1389 if (pointerEvent == nullptr) {
1390 SC_LOG_WARN("SecurityComponentClickEventWarning: Receive a NULL pointerEvent, set default data.");
1391 secEvent.extraInfo.data = &defaultData;
1392 secEvent.extraInfo.dataSize = 1;
1393 secEvent.point.timestamp = 0;
1394 } else {
1395 dataBuffer = pointerEvent->GetEnhanceData();
1396 if (dataBuffer.size() > 0) {
1397 secEvent.extraInfo.data = dataBuffer.data();
1398 secEvent.extraInfo.dataSize = dataBuffer.size();
1399 }
1400 std::chrono::microseconds microseconds(pointerEvent->GetActionTime());
1401 TimeStamp time(microseconds);
1402 secEvent.point.timestamp =
1403 static_cast<uint64_t>(time.time_since_epoch().count()) / SECOND_TO_MILLISECOND;
1404 }
1405 #endif
1406 CheckSecurityComponentClickEvent(node, message);
1407
1408 return ReportSecurityComponentClickEventInner(scId, node, secEvent, std::move(callback), message);
1409 }
1410
ReportSecurityComponentClickEvent(int32_t & scId,RefPtr<FrameNode> & node,const KeyEvent & event,Security::SecurityComponent::OnFirstUseDialogCloseFunc && callback)1411 int32_t SecurityComponentHandler::ReportSecurityComponentClickEvent(int32_t& scId,
1412 RefPtr<FrameNode>& node, const KeyEvent& event,
1413 Security::SecurityComponent::OnFirstUseDialogCloseFunc&& callback)
1414 {
1415 SecCompClickEvent secEvent = {};
1416 secEvent.type = ClickEventType::KEY_EVENT_TYPE;
1417
1418 secEvent.key.timestamp =
1419 static_cast<uint64_t>(event.timeStamp.time_since_epoch().count()) / SECOND_TO_MILLISECOND;
1420 secEvent.key.keyCode = static_cast<int32_t>(event.code);
1421 auto data = event.enhanceData;
1422 if (data.size() > 0) {
1423 secEvent.extraInfo.data = data.data();
1424 secEvent.extraInfo.dataSize = data.size();
1425 }
1426 std::string message;
1427 CheckSecurityComponentClickEvent(node, message);
1428
1429 return ReportSecurityComponentClickEventInner(scId, node, secEvent, std::move(callback), message);
1430 }
1431
IsSecurityComponentServiceExist()1432 bool SecurityComponentHandler::IsSecurityComponentServiceExist()
1433 {
1434 return SecCompKit::IsServiceExist();
1435 }
1436
LoadSecurityComponentService()1437 bool SecurityComponentHandler::LoadSecurityComponentService()
1438 {
1439 return SecCompKit::LoadService();
1440 }
1441
IsSystemAppCalling()1442 bool SecurityComponentHandler::IsSystemAppCalling()
1443 {
1444 return SecCompKit::IsSystemAppCalling();
1445 }
1446
HasCustomPermissionForSecComp()1447 bool SecurityComponentHandler::HasCustomPermissionForSecComp()
1448 {
1449 return SecCompKit::HasCustomPermissionForSecComp();
1450 }
1451 } // namespace OHOS::Ace::NG
1452