• 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_probe.h"
17 
18 #include "base/log/ace_scoring_log.h"
19 #include "base/memory/ace_type.h"
20 #include "core/components_ng/pattern/security_component/security_component_handler.h"
21 #include "core/components_v2/inspector/inspector_constants.h"
22 #include "core/pipeline/base/element_register.h"
23 #include "core/pipeline_ng/pipeline_context.h"
24 
25 namespace OHOS::Ace::NG {
26 namespace {
27 constexpr uint64_t MAX_CALLBACK_WAITING_TIME = 500; // 500ms
28 }
29 
InitProbeTask()30 void SecurityComponentProbe::InitProbeTask()
31 {
32     if (taskExec_.has_value()) {
33         return;
34     }
35     tmux_.lock();
36     if (taskExec_.has_value()) {
37         tmux_.unlock();
38         return;
39     }
40     auto context = PipelineContext::GetCurrentContext();
41     CHECK_NULL_VOID(context);
42     taskExec_ = SingleTaskExecutor::Make(context->GetTaskExecutor(), TaskExecutor::TaskType::UI);
43     tmux_.unlock();
44     return;
45 }
46 
GetComponentInfo(int32_t nodeId,std::string & compInfoStr)47 int32_t SecurityComponentProbe::GetComponentInfo(int32_t nodeId, std::string& compInfoStr)
48 {
49     if (!taskExec_.has_value()) {
50         LOGW("callback task do not exist.");
51         return -1;
52     }
53     if (!tmux_.try_lock_for(std::chrono::milliseconds(MAX_CALLBACK_WAITING_TIME))) {
54         LOGW("callback task timeout.");
55         return -1;
56     }
57     int taskRes;
58     taskExec_.value().PostSyncTask([nodeId, &compInfoStr, &taskRes] {
59         auto node = AceType::DynamicCast<FrameNode>(ElementRegister::GetInstance()->GetNodeById(nodeId));
60         if (!node) {
61             LOGW("node do not exist.");
62             taskRes = -1;
63             return;
64         }
65 
66         if ((node->GetTag() != V2::LOCATION_BUTTON_ETS_TAG) && (node->GetTag() != V2::PASTE_BUTTON_ETS_TAG) &&
67             (node->GetTag() != V2::SAVE_BUTTON_ETS_TAG)) {
68             LOGW("node is not security component.");
69             taskRes = -1;
70             return;
71         }
72         if (!SecurityComponentHandler::InitButtonInfo(compInfoStr, node)) {
73             LOGW("node init info failed.");
74             taskRes = -1;
75             return;
76         }
77         taskRes = 0;
78     });
79     tmux_.unlock();
80     return taskRes;
81 }
82 } // namespace OHOS::Ace::NG
83