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