• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 
18 #include <securec.h>
19 
20 #include "adapter/ohos/entrance/ace_container.h"
21 #include "base/log/ace_scoring_log.h"
22 #include "base/utils/system_properties.h"
23 #include "core/common/container.h"
24 #include "core/components_ng/pattern/button/button_layout_property.h"
25 #include "core/components_ng/pattern/text/text_layout_property.h"
26 #include "core/components_v2/inspector/inspector_constants.h"
27 
28 namespace OHOS::Ace::NG {
29 using namespace OHOS::Security;
30 using namespace OHOS::Security::SecurityComponent;
31 namespace {
32 constexpr uint64_t SECOND_TO_MILLISECOND = 1000;
33 }
34 
35 static std::vector<uintptr_t> g_callList = {
36     reinterpret_cast<uintptr_t>(SecurityComponentHandler::RegisterSecurityComponent),
37     reinterpret_cast<uintptr_t>(SecurityComponentHandler::UpdateSecurityComponent),
38     reinterpret_cast<uintptr_t>(SecurityComponentHandler::ReportSecurityComponentClickEventInner)
39 };
40 
41 SecurityComponentProbe SecurityComponentHandler::probe;
42 SecurityComponent::SecCompUiRegister uiRegister(g_callList, &SecurityComponentHandler::probe);
43 
GetDisplayOffset(RefPtr<FrameNode> & node,double & offsetX,double & offsetY)44 bool SecurityComponentHandler::GetDisplayOffset(RefPtr<FrameNode>& node, double& offsetX, double& offsetY)
45 {
46     double x = node->GetTransformRelativeOffset().GetX();
47     double y = node->GetTransformRelativeOffset().GetY();
48     auto container = Container::Current();
49     CHECK_NULL_RETURN(container, false);
50     auto pipelineContext = container->GetPipelineContext();
51     CHECK_NULL_RETURN(pipelineContext, false);
52     auto windowOffset = pipelineContext->GetDisplayWindowRectInfo().GetOffset();
53     offsetX = x + windowOffset.GetX();
54     offsetY = y + windowOffset.GetY();
55     return true;
56 }
57 
GetWindowRect(RefPtr<FrameNode> & node,OHOS::Security::SecurityComponent::SecCompRect & winRect)58 bool SecurityComponentHandler::GetWindowRect(RefPtr<FrameNode>& node,
59     OHOS::Security::SecurityComponent::SecCompRect& winRect)
60 {
61     auto container = Container::Current();
62     CHECK_NULL_RETURN(container, false);
63     auto pipelineContext = container->GetPipelineContext();
64     CHECK_NULL_RETURN(pipelineContext, false);
65     auto rect = pipelineContext->GetDisplayWindowRectInfo();
66     winRect.x_ = rect.Left();
67     winRect.y_ = rect.Top();
68     winRect.width_ = rect.Right() - rect.Left();
69     winRect.height_ = rect.Bottom() - rect.Top();
70     return true;
71 }
72 
CheckOpacity(const RefPtr<FrameNode> & node,const RefPtr<RenderContext> & renderContext)73 bool SecurityComponentHandler::CheckOpacity(const RefPtr<FrameNode>& node, const RefPtr<RenderContext>& renderContext)
74 {
75     if (node->GetTag() == V2::MENU_WRAPPER_ETS_TAG) {
76         return false;
77     }
78     if (renderContext->GetOpacity().has_value() &&
79         !NearEqual(renderContext->GetOpacity().value(), 1.0f)) {
80         LOGW("SecurityComponentCheckFail: Parent %{public}s opacity is set, security component is invalid",
81             node->GetTag().c_str());
82         return true;
83     }
84     return false;
85 }
86 
CheckBrightness(const RefPtr<FrameNode> & node,const RefPtr<RenderContext> & renderContext)87 bool SecurityComponentHandler::CheckBrightness(const RefPtr<FrameNode>& node,
88     const RefPtr<RenderContext>& renderContext)
89 {
90     if (renderContext->GetFrontBrightness().has_value() &&
91         !NearEqual(renderContext->GetFrontBrightness().value().ConvertToVp(), 1.0f)) {
92         LOGW("SecurityComponentCheckFail: Parent %{public}s brightness is set, security component is invalid",
93             node->GetTag().c_str());
94         return true;
95     }
96     return false;
97 }
98 
CheckVisibility(const RefPtr<FrameNode> & node,RefPtr<LayoutProperty> & layoutProperty)99 bool SecurityComponentHandler::CheckVisibility(const RefPtr<FrameNode>& node, RefPtr<LayoutProperty>& layoutProperty)
100 {
101     if (layoutProperty->GetVisibility().has_value() &&
102         (layoutProperty->GetVisibility().value() != VisibleType::VISIBLE)) {
103         LOGW("SecurityComponentCheckFail: Parent %{public}s is not visible, security component is invalid",
104             node->GetTag().c_str());
105         return true;
106     }
107     return false;
108 }
109 
CheckBlur(const RefPtr<FrameNode> & node,const RefPtr<RenderContext> & renderContext)110 bool SecurityComponentHandler::CheckBlur(const RefPtr<FrameNode>& node, const RefPtr<RenderContext>& renderContext)
111 {
112     if (renderContext->GetFrontBlurRadius().has_value() &&
113         GreatNotEqual(renderContext->GetFrontBlurRadius().value().ConvertToPx(), 0.0f)) {
114         LOGW("SecurityComponentCheckFail: Parent %{public}s foregroundBlurStyle is set, security component is invalid",
115             node->GetTag().c_str());
116         return true;
117     }
118     return false;
119 }
120 
CheckGrayScale(const RefPtr<FrameNode> & node,const RefPtr<RenderContext> & renderContext)121 bool SecurityComponentHandler::CheckGrayScale(const RefPtr<FrameNode>& node, const RefPtr<RenderContext>& renderContext)
122 {
123     if (renderContext->GetFrontGrayScale().has_value() &&
124         GreatNotEqual(renderContext->GetFrontGrayScale().value().ConvertToVp(), 0.0f)) {
125         LOGW("SecurityComponentCheckFail: Parent %{public}s grayscale is set, security component is invalid",
126             node->GetTag().c_str());
127         return true;
128     }
129     return false;
130 }
131 
CheckSaturate(const RefPtr<FrameNode> & node,const RefPtr<RenderContext> & renderContext)132 bool SecurityComponentHandler::CheckSaturate(const RefPtr<FrameNode>& node, const RefPtr<RenderContext>& renderContext)
133 {
134     if (renderContext->GetFrontSaturate().has_value() &&
135         !NearEqual(renderContext->GetFrontSaturate().value().ConvertToVp(), 1.0f)) {
136         LOGW("SecurityComponentCheckFail: Parent %{public}s saturate is set, security component is invalid",
137             node->GetTag().c_str());
138         return true;
139     }
140     return false;
141 }
142 
CheckContrast(const RefPtr<FrameNode> & node,const RefPtr<RenderContext> & renderContext)143 bool SecurityComponentHandler::CheckContrast(const RefPtr<FrameNode>& node, const RefPtr<RenderContext>& renderContext)
144 {
145     if (renderContext->GetFrontContrast().has_value() &&
146         !NearEqual(renderContext->GetFrontContrast().value().ConvertToVp(), 1.0f)) {
147         LOGW("SecurityComponentCheckFail: Parent %{public}s contrast is set, security component is invalid",
148             node->GetTag().c_str());
149         return true;
150     }
151     return false;
152 }
153 
CheckInvert(const RefPtr<FrameNode> & node,const RefPtr<RenderContext> & renderContext)154 bool SecurityComponentHandler::CheckInvert(const RefPtr<FrameNode>& node, const RefPtr<RenderContext>& renderContext)
155 {
156     if (renderContext->GetFrontInvert().has_value() && renderContext->GetFrontInvert()->index() == 0 &&
157         !NearEqual(std::get<float>(renderContext->GetFrontInvert().value()), 0.0f)) {
158         LOGW("SecurityComponentCheckFail: Parent %{public}s invert is set, security component is invalid",
159             node->GetTag().c_str());
160         return true;
161     }
162     return false;
163 }
164 
CheckSepia(const RefPtr<FrameNode> & node,const RefPtr<RenderContext> & renderContext)165 bool SecurityComponentHandler::CheckSepia(const RefPtr<FrameNode>& node, const RefPtr<RenderContext>& renderContext)
166 {
167     if (renderContext->GetFrontSepia().has_value() &&
168         !NearEqual(renderContext->GetFrontSepia().value().ConvertToVp(), 0.0f)) {
169         LOGW("SecurityComponentCheckFail: Parent %{public}s sepia is set, security component is invalid",
170             node->GetTag().c_str());
171         return true;
172     }
173     return false;
174 }
175 
CheckHueRotate(const RefPtr<FrameNode> & node,const RefPtr<RenderContext> & renderContext)176 bool SecurityComponentHandler::CheckHueRotate(const RefPtr<FrameNode>& node, const RefPtr<RenderContext>& renderContext)
177 {
178     if (renderContext->GetFrontHueRotate().has_value() &&
179         !NearEqual(renderContext->GetFrontHueRotate().value(), 0.0f) &&
180         !NearEqual(renderContext->GetFrontHueRotate().value(), 360.0f)) {
181         LOGW("SecurityComponentCheckFail: Parent %{public}s hueRotate is set, security component is invalid",
182             node->GetTag().c_str());
183         return true;
184     }
185     return false;
186 }
187 
CheckColorBlend(const RefPtr<FrameNode> & node,const RefPtr<RenderContext> & renderContext)188 bool SecurityComponentHandler::CheckColorBlend(const RefPtr<FrameNode>& node,
189     const RefPtr<RenderContext>& renderContext)
190 {
191     if (renderContext->GetFrontColorBlend().has_value() &&
192         (renderContext->GetFrontColorBlend().value() != Color::TRANSPARENT)) {
193         LOGW("SecurityComponentCheckFail: Parent %{public}s colorBlend is set, security component is invalid",
194             node->GetTag().c_str());
195         return true;
196     }
197     return false;
198 }
199 
CheckClipMask(const RefPtr<FrameNode> & node,const RefPtr<RenderContext> & renderContext)200 bool SecurityComponentHandler::CheckClipMask(const RefPtr<FrameNode>& node, const RefPtr<RenderContext>& renderContext)
201 {
202     if (renderContext->GetClipMask().has_value()) {
203         LOGW("SecurityComponentCheckFail: Parent %{public}s clip mask is set, security component is invalid",
204             node->GetTag().c_str());
205         return true;
206     }
207     return false;
208 }
209 
CheckForegroundColor(const RefPtr<FrameNode> & node,const RefPtr<RenderContext> & renderContext)210 bool SecurityComponentHandler::CheckForegroundColor(const RefPtr<FrameNode>& node,
211     const RefPtr<RenderContext>& renderContext)
212 {
213     if (renderContext->GetForegroundColor().has_value() &&
214         (renderContext->GetForegroundColor().value() != Color::TRANSPARENT)) {
215         LOGW("SecurityComponentCheckFail: Parent %{public}s foregroundColor is set, security component is invalid",
216             node->GetTag().c_str());
217         return true;
218     }
219     return false;
220 }
221 
CheckSphericalEffect(const RefPtr<FrameNode> & node,const RefPtr<RenderContext> & renderContext)222 bool SecurityComponentHandler::CheckSphericalEffect(const RefPtr<FrameNode>& node,
223     const RefPtr<RenderContext>& renderContext)
224 {
225     if (renderContext->GetSphericalEffect().has_value() &&
226         !NearEqual(renderContext->GetSphericalEffect().value(), 0.0f)) {
227         LOGW("SecurityComponentCheckFail: Parent %{public}s sphericalEffect is set, security component is invalid",
228             node->GetTag().c_str());
229         return true;
230     }
231     return false;
232 }
233 
CheckLightUpEffect(const RefPtr<FrameNode> & node,const RefPtr<RenderContext> & renderContext)234 bool SecurityComponentHandler::CheckLightUpEffect(const RefPtr<FrameNode>& node,
235     const RefPtr<RenderContext>& renderContext)
236 {
237     if (renderContext->GetLightUpEffect().has_value()) {
238         LOGW("SecurityComponentCheckFail: Parent %{public}s lightUpEffect is set, security component is invalid",
239             node->GetTag().c_str());
240         return true;
241     }
242     return false;
243 }
244 
CheckPixelStretchEffect(const RefPtr<FrameNode> & node,const RefPtr<RenderContext> & renderContext)245 bool SecurityComponentHandler::CheckPixelStretchEffect(const RefPtr<FrameNode>& node,
246     const RefPtr<RenderContext>& renderContext)
247 {
248     if (renderContext->GetPixelStretchEffect().has_value()) {
249         LOGW("SecurityComponentCheckFail: Parent %{public}s pixelStretchEffect is set, security component is invalid",
250             node->GetTag().c_str());
251         return true;
252     }
253     return false;
254 }
255 
CheckRenderEffect(RefPtr<FrameNode> & node)256 bool SecurityComponentHandler::CheckRenderEffect(RefPtr<FrameNode>& node)
257 {
258     const auto& renderContext = node->GetRenderContext();
259     CHECK_NULL_RETURN(renderContext, false);
260     auto layoutProperty = node->GetLayoutProperty();
261     CHECK_NULL_RETURN(layoutProperty, false);
262 
263     if (CheckOpacity(node, renderContext) || CheckBrightness(node, renderContext) ||
264         CheckVisibility(node, layoutProperty) || CheckBlur(node, renderContext) ||
265         CheckGrayScale(node, renderContext) || CheckSaturate(node, renderContext) ||
266         CheckContrast(node, renderContext) || CheckInvert(node, renderContext) ||
267         CheckSepia(node, renderContext) || CheckHueRotate(node, renderContext) ||
268         CheckColorBlend(node, renderContext) || CheckClipMask(node, renderContext) ||
269         CheckForegroundColor(node, renderContext) || CheckSphericalEffect(node, renderContext)||
270         CheckLightUpEffect(node, renderContext) || CheckPixelStretchEffect(node, renderContext)) {
271         return true;
272     }
273     return false;
274 }
275 
CheckParentNodesEffect(RefPtr<FrameNode> & node)276 bool SecurityComponentHandler::CheckParentNodesEffect(RefPtr<FrameNode>& node)
277 {
278     RefPtr<RenderContext> renderContext = node->GetRenderContext();
279     auto frameRect = renderContext->GetPaintRectWithTransform();
280     frameRect.SetOffset(node->GetOffsetRelativeToWindow());
281     auto visibleRect = frameRect;
282     auto parent = node->GetParent();
283     while (parent != nullptr) {
284         auto parentNode = AceType::DynamicCast<FrameNode>(parent);
285         if (parentNode == nullptr) {
286             return false;
287         }
288         if (CheckRenderEffect(parentNode)) {
289             return true;
290         }
291         RefPtr<RenderContext> parentRenderContext = parentNode->GetRenderContext();
292         if (!parentRenderContext->GetClipEdge().value_or(false)) {
293             parent = parent->GetParent();
294             continue;
295         }
296         GetVisibleRect(parentNode, visibleRect);
297         double currentVisibleRatio = CalculateCurrentVisibleRatio(visibleRect, frameRect);
298         if (!NearEqual(currentVisibleRatio, 1) && (visibleRect.IsValid() || frameRect.IsValid())) {
299             LOGW("SecurityComponentCheckFail: Parents clip is set, security component is not completely displayed.");
300             LOGW("visibleWidth: %{public}f, visibleHeight: %{public}f, frameWidth: %{public}f, frameHeight: %{public}f",
301                 visibleRect.Width(), visibleRect.Height(), frameRect.Width(), frameRect.Height());
302             return true;
303         }
304         parent = parent->GetParent();
305     }
306     return false;
307 }
308 
GetVisibleRect(RefPtr<FrameNode> & node,RectF & visibleRect)309 void SecurityComponentHandler::GetVisibleRect(RefPtr<FrameNode>& node, RectF& visibleRect)
310 {
311     auto parentFrame = AceType::DynamicCast<FrameNode>(node);
312     if (!parentFrame) {
313         LOGW("Parent %{public}s get frame failed", node->GetTag().c_str());
314         return;
315     }
316     RectF parentRect = parentFrame->GetRenderContext()->GetPaintRectWithTransform();
317     parentRect.SetOffset(parentFrame->GetOffsetRelativeToWindow());
318     visibleRect = visibleRect.Constrain(parentRect);
319 }
320 
CalculateCurrentVisibleRatio(const RectF & visibleRect,const RectF & renderRect)321 double SecurityComponentHandler::CalculateCurrentVisibleRatio(const RectF& visibleRect, const RectF& renderRect)
322 {
323     if (!visibleRect.IsValid() || !renderRect.IsValid()) {
324         return 0.0;
325     }
326     return visibleRect.Width() * visibleRect.Height() / (renderRect.Width() * renderRect.Height());
327 }
328 
InitBaseInfo(OHOS::Security::SecurityComponent::SecCompBase & buttonInfo,RefPtr<FrameNode> & node)329 bool SecurityComponentHandler::InitBaseInfo(OHOS::Security::SecurityComponent::SecCompBase& buttonInfo,
330     RefPtr<FrameNode>& node)
331 {
332     CHECK_NULL_RETURN(node, false);
333     auto layoutProperty = AceType::DynamicCast<SecurityComponentLayoutProperty>(node->GetLayoutProperty());
334     CHECK_NULL_RETURN(layoutProperty, false);
335     buttonInfo.nodeId_ = node->GetId();
336 
337     auto pipeline = PipelineContext::GetCurrentContext();
338     CHECK_NULL_RETURN(pipeline, false);
339     auto theme = pipeline->GetTheme<SecurityComponentTheme>();
340     CHECK_NULL_RETURN(theme, false);
341     buttonInfo.padding_.top =
342         layoutProperty->GetBackgroundTopPadding().value_or(theme->GetBackgroundTopPadding()).ConvertToVp();
343     buttonInfo.padding_.right =
344         layoutProperty->GetBackgroundRightPadding().value_or(theme->GetBackgroundRightPadding()).ConvertToVp();
345     buttonInfo.padding_.bottom =
346         layoutProperty->GetBackgroundBottomPadding().value_or(theme->GetBackgroundBottomPadding()).ConvertToVp();
347     buttonInfo.padding_.left =
348         layoutProperty->GetBackgroundLeftPadding().value_or(theme->GetBackgroundLeftPadding()).ConvertToVp();
349     buttonInfo.textIconSpace_ =
350         layoutProperty->GetTextIconSpace().value_or(theme->GetTextIconSpace()).ConvertToVp();
351 
352     auto container = AceType::DynamicCast<Platform::AceContainer>(Container::Current());
353     CHECK_NULL_RETURN(container, false);
354     buttonInfo.windowId_ = static_cast<int32_t>(container->GetWindowId());
355 
356     if (!GetDisplayOffset(node, buttonInfo.rect_.x_, buttonInfo.rect_.y_)) {
357         LOGW("Get display offset failed");
358         return false;
359     }
360 
361     if (!GetWindowRect(node, buttonInfo.windowRect_)) {
362         LOGW("Get window rect failed");
363         return false;
364     }
365     auto render = node->GetRenderContext();
366     CHECK_NULL_RETURN(render, false);
367     auto rect = render->GetPaintRectWithTransform();
368     buttonInfo.rect_.width_ = rect.Width();
369     buttonInfo.rect_.height_ = rect.Height();
370 
371     return true;
372 }
373 
InitChildInfo(OHOS::Security::SecurityComponent::SecCompBase & buttonInfo,RefPtr<FrameNode> & node)374 bool SecurityComponentHandler::InitChildInfo(OHOS::Security::SecurityComponent::SecCompBase& buttonInfo,
375     RefPtr<FrameNode>& node)
376 {
377     RefPtr<FrameNode> iconNode = GetSecCompChildNode(node, V2::IMAGE_ETS_TAG);
378     if (iconNode != nullptr) {
379         CHECK_NULL_RETURN(iconNode->GetGeometryNode(), false);
380         auto iconProp = iconNode->GetLayoutProperty<ImageLayoutProperty>();
381         CHECK_NULL_RETURN(iconProp, false);
382         buttonInfo.iconSize_ =
383             iconProp->GetCalcLayoutConstraint()->selfIdealSize->Width()->GetDimension().ConvertToVp();
384         buttonInfo.iconColor_.value =
385             iconProp->GetImageSourceInfo().value().GetFillColor().value().GetValue();
386     }
387 
388     RefPtr<FrameNode> textNode = GetSecCompChildNode(node, V2::TEXT_ETS_TAG);
389     if (textNode != nullptr) {
390         auto textProp = textNode->GetLayoutProperty<TextLayoutProperty>();
391         CHECK_NULL_RETURN(textProp, false);
392         auto pipeline = PipelineContext::GetCurrentContext();
393         CHECK_NULL_RETURN(pipeline, false);
394         auto theme = pipeline->GetTheme<SecurityComponentTheme>();
395         CHECK_NULL_RETURN(theme, false);
396         buttonInfo.fontSize_ = textProp->GetFontSize().value_or(theme->GetFontSize()).ConvertToVp();
397         buttonInfo.fontColor_.value = textProp->GetTextColor().value().GetValue();
398     }
399 
400     RefPtr<FrameNode> buttonNode = GetSecCompChildNode(node, V2::BUTTON_ETS_TAG);
401     if (buttonNode != nullptr) {
402         const auto& renderContext = buttonNode->GetRenderContext();
403         CHECK_NULL_RETURN(renderContext, false);
404         buttonInfo.bgColor_.value = renderContext->GetBackgroundColor().value().GetValue();
405 
406         auto bgProp = buttonNode->GetLayoutProperty<ButtonLayoutProperty>();
407         CHECK_NULL_RETURN(bgProp, false);
408         const auto& borderWidth = bgProp->GetBorderWidthProperty();
409         if (borderWidth != nullptr) {
410             buttonInfo.borderWidth_ = borderWidth->leftDimen.value().ConvertToVp();
411         }
412     }
413     if (!InitBaseInfo(buttonInfo, node)) {
414         return false;
415     }
416     return true;
417 }
418 
InitButtonInfo(std::string & componentInfo,RefPtr<FrameNode> & node,SecCompType & scType)419 bool SecurityComponentHandler::InitButtonInfo(std::string& componentInfo, RefPtr<FrameNode>& node, SecCompType& scType)
420 {
421     CHECK_NULL_RETURN(node, false);
422     auto layoutProperty = AceType::DynamicCast<SecurityComponentLayoutProperty>(node->GetLayoutProperty());
423     CHECK_NULL_RETURN(layoutProperty, false);
424     std::string type = node->GetTag();
425     if (type == V2::LOCATION_BUTTON_ETS_TAG) {
426         LocationButton buttonInfo;
427         buttonInfo.parentEffect_ = CheckParentNodesEffect(node);
428         buttonInfo.text_ = layoutProperty->GetSecurityComponentDescription().value();
429         buttonInfo.icon_ = layoutProperty->GetIconStyle().value();
430         buttonInfo.bg_ = static_cast<SecCompBackground>(
431             layoutProperty->GetBackgroundType().value());
432         buttonInfo.type_ = SecCompType::LOCATION_COMPONENT;
433         scType = SecCompType::LOCATION_COMPONENT;
434         if (!InitChildInfo(buttonInfo, node)) {
435             return false;
436         }
437         componentInfo = buttonInfo.ToJsonStr();
438     } else if (type == V2::PASTE_BUTTON_ETS_TAG) {
439         PasteButton buttonInfo;
440         buttonInfo.parentEffect_ = CheckParentNodesEffect(node);
441         buttonInfo.text_ = layoutProperty->GetSecurityComponentDescription().value();
442         buttonInfo.icon_ = layoutProperty->GetIconStyle().value();
443         buttonInfo.bg_ = static_cast<SecCompBackground>(
444             layoutProperty->GetBackgroundType().value());
445         buttonInfo.type_ = SecCompType::PASTE_COMPONENT;
446         scType = SecCompType::PASTE_COMPONENT;
447         if (!InitChildInfo(buttonInfo, node)) {
448             return false;
449         }
450         componentInfo = buttonInfo.ToJsonStr();
451     } else if (type == V2::SAVE_BUTTON_ETS_TAG) {
452         SaveButton buttonInfo;
453         buttonInfo.parentEffect_ = CheckParentNodesEffect(node);
454         buttonInfo.text_ = layoutProperty->GetSecurityComponentDescription().value();
455         buttonInfo.icon_ = layoutProperty->GetIconStyle().value();
456         buttonInfo.bg_ = static_cast<SecCompBackground>(
457             layoutProperty->GetBackgroundType().value());
458         buttonInfo.type_ = SecCompType::SAVE_COMPONENT;
459         scType = SecCompType::SAVE_COMPONENT;
460         if (!InitChildInfo(buttonInfo, node)) {
461             return false;
462         }
463         componentInfo = buttonInfo.ToJsonStr();
464     } else {
465         return false;
466     }
467     return true;
468 }
469 
RegisterSecurityComponent(RefPtr<FrameNode> & node,int32_t & scId)470 int32_t SecurityComponentHandler::RegisterSecurityComponent(RefPtr<FrameNode>& node, int32_t& scId)
471 {
472     SecurityComponentHandler::probe.InitProbeTask();
473     std::string componentInfo;
474     SecCompType type;
475     if (!InitButtonInfo(componentInfo, node, type)) {
476         return -1;
477     }
478     int32_t ret = SecCompKit::RegisterSecurityComponent(
479         type, componentInfo, scId);
480     return ret;
481 }
482 
UpdateSecurityComponent(RefPtr<FrameNode> & node,int32_t & scId)483 int32_t SecurityComponentHandler::UpdateSecurityComponent(RefPtr<FrameNode>& node, int32_t& scId)
484 {
485     std::string componentInfo;
486     SecCompType type;
487     if (!InitButtonInfo(componentInfo, node, type)) {
488         return -1;
489     }
490     int32_t ret = SecCompKit::UpdateSecurityComponent(scId, componentInfo);
491     return ret;
492 }
493 
UnregisterSecurityComponent(int32_t & scId)494 int32_t SecurityComponentHandler::UnregisterSecurityComponent(int32_t& scId)
495 {
496     if (scId == -1) {
497         return -1;
498     }
499     int32_t ret = SecCompKit::UnregisterSecurityComponent(scId);
500     return ret;
501 }
502 
ReportSecurityComponentClickEventInner(int32_t & scId,RefPtr<FrameNode> & node,SecCompClickEvent & event)503 int32_t SecurityComponentHandler::ReportSecurityComponentClickEventInner(int32_t& scId,
504     RefPtr<FrameNode>& node, SecCompClickEvent& event)
505 {
506     std::string componentInfo;
507     SecCompType type;
508     if (!InitButtonInfo(componentInfo, node, type)) {
509         return -1;
510     }
511     auto container = AceType::DynamicCast<Platform::AceContainer>(Container::Current());
512     CHECK_NULL_RETURN(container, -1);
513     return SecCompKit::ReportSecurityComponentClickEvent(scId, componentInfo, event, container->GetToken());
514 }
515 
ReportSecurityComponentClickEvent(int32_t & scId,RefPtr<FrameNode> & node,GestureEvent & event)516 int32_t SecurityComponentHandler::ReportSecurityComponentClickEvent(int32_t& scId,
517     RefPtr<FrameNode>& node, GestureEvent& event)
518 {
519     SecCompClickEvent secEvent;
520     secEvent.type = ClickEventType::POINT_EVENT_TYPE;
521 #ifdef SECURITY_COMPONENT_ENABLE
522     secEvent.point.touchX = event.GetDisplayX();
523     secEvent.point.touchY = event.GetDisplayY();
524     auto data = event.GetPointerEvent()->GetEnhanceData();
525     if (data.size() > 0) {
526         secEvent.extraInfo.data = data.data();
527         secEvent.extraInfo.dataSize = data.size();
528     }
529     std::chrono::microseconds microseconds(event.GetPointerEvent()->GetActionTime());
530     TimeStamp time(microseconds);
531     secEvent.point.timestamp =
532         static_cast<uint64_t>(time.time_since_epoch().count()) / SECOND_TO_MILLISECOND;
533 #endif
534 
535     return ReportSecurityComponentClickEventInner(scId, node, secEvent);
536 }
537 
ReportSecurityComponentClickEvent(int32_t & scId,RefPtr<FrameNode> & node,const KeyEvent & event)538 int32_t SecurityComponentHandler::ReportSecurityComponentClickEvent(int32_t& scId,
539     RefPtr<FrameNode>& node, const KeyEvent& event)
540 {
541     SecCompClickEvent secEvent;
542     secEvent.type = ClickEventType::KEY_EVENT_TYPE;
543 
544     secEvent.key.timestamp =
545         static_cast<uint64_t>(event.timeStamp.time_since_epoch().count()) / SECOND_TO_MILLISECOND;
546     secEvent.key.keyCode = static_cast<int32_t>(event.code);
547     auto data = event.enhanceData;
548     if (data.size() > 0) {
549         secEvent.extraInfo.data = data.data();
550         secEvent.extraInfo.dataSize = data.size();
551     }
552     return ReportSecurityComponentClickEventInner(scId, node, secEvent);
553 }
554 } // namespace OHOS::Ace::NG
555