• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 "resource_node_utils.h"
17 
18 #include "iam_check.h"
19 #include "iam_logger.h"
20 #include "iam_hitrace_helper.h"
21 #include "resource_node_pool.h"
22 
23 #define LOG_LABEL UserIam::Common::LABEL_USER_AUTH_SA
24 
25 namespace OHOS {
26 namespace UserIam {
27 namespace UserAuth {
NotifyExecutorToDeleteTemplates(const std::vector<std::shared_ptr<CredentialInfo>> & infos)28 int32_t ResourceNodeUtils::NotifyExecutorToDeleteTemplates(const std::vector<std::shared_ptr<CredentialInfo>> &infos)
29 {
30     if (infos.size() == 0) {
31         IAM_LOGE("bad infos, infos size is 0");
32         return INVALID_PARAMETERS;
33     }
34 
35     for (const auto &info : infos) {
36         uint64_t executorIndex = info->GetExecutorIndex();
37 
38         auto resourceNode = ResourceNodePool::Instance().Select(executorIndex).lock();
39         if (resourceNode == nullptr) {
40             IAM_LOGE("failed to find ****%{public}hx", static_cast<uint16_t>(executorIndex));
41             continue;
42         }
43         Attributes properties;
44         properties.SetUint32Value(Attributes::ATTR_PROPERTY_MODE, PROPERTY_MODE_DEL);
45         properties.SetUint64Value(Attributes::ATTR_TEMPLATE_ID, info->GetTemplateId());
46         IamHitraceHelper traceHelper("NotifyExecutorToDeleteTemplates");
47         int32_t ret = resourceNode->SetProperty(properties);
48         if (ret != SUCCESS) {
49             IAM_LOGE("failed to set property to ****%{public}hx", static_cast<uint16_t>(executorIndex));
50         }
51     }
52 
53     return SUCCESS;
54 }
55 
SendMsgToExecutor(uint64_t executorIndex,const std::vector<uint8_t> & msg)56 void ResourceNodeUtils::SendMsgToExecutor(uint64_t executorIndex, const std::vector<uint8_t> &msg)
57 {
58     auto resourceNode = ResourceNodePool::Instance().Select(executorIndex).lock();
59     if (resourceNode == nullptr) {
60         IAM_LOGE("failed to find ****%{public}hx", static_cast<uint16_t>(executorIndex));
61         return;
62     }
63     Attributes properties;
64     // In current version, msg type is not set, temporary use PROPER_MODE_FREEZE
65     bool setAuthPropertyModeRet =
66         properties.SetUint32Value(UserIam::UserAuth::Attributes::ATTR_PROPERTY_MODE, PROPERTY_MODE_FREEZE);
67     IF_FALSE_LOGE_AND_RETURN(setAuthPropertyModeRet == true);
68     bool setExtraInfoRet = properties.SetUint8ArrayValue(UserIam::UserAuth::Attributes::ATTR_EXTRA_INFO, msg);
69     IF_FALSE_LOGE_AND_RETURN(setExtraInfoRet == true);
70     int32_t ret = resourceNode->SetProperty(properties);
71     if (ret != SUCCESS) {
72         IAM_LOGE("failed to set property to ****%{public}hx", static_cast<uint16_t>(executorIndex));
73         return;
74     }
75     IAM_LOGI("send msg to ****%{public}hx success", static_cast<uint16_t>(executorIndex));
76 }
77 } // namespace UserAuth
78 } // namespace UserIam
79 } // namespace OHOS