• 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 "devattest_client.h"
17 
18 #include "system_ability_definition.h"
19 
20 #include "iservice_registry.h"
21 
22 #include "devattest_log.h"
23 #include "devattest_errno.h"
24 #include "attest_result_info.h"
25 
26 using namespace std;
27 using namespace OHOS;
28 
29 namespace OHOS {
30 namespace DevAttest {
DevAttestClient()31 DevAttestClient::DevAttestClient()
32 {
33     (void)InitClientService();
34 }
35 
~DevAttestClient()36 DevAttestClient::~DevAttestClient()
37 {
38 }
39 
InitClientService()40 int DevAttestClient::InitClientService()
41 {
42     HILOGI("DevAttestClient InitClientService begin");
43     if (attestClientInterface_ != nullptr) {
44         HILOGI("DevAttestClient InitClientService already init");
45         return DEVATTEST_SUCCESS;
46     }
47 
48     auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
49     if (!samgr) {
50         HILOGE("Failed to get system ability mgr.");
51         return DEVATTEST_SA_NO_INIT;
52     }
53 
54     auto object = samgr->CheckSystemAbility(DEVICE_ATTEST_PROFILE_SA_ID);
55     if (!object) {
56         HILOGE("Failed to get Device Attest.");
57         return DEVATTEST_SA_NO_INIT;
58     }
59     attestClientInterface_ = iface_cast<DevAttestInterface>(object);
60     HILOGI("DevAttestClient InitClientService success");
61     return DEVATTEST_SUCCESS;
62 }
63 
GetAttestStatus(AttestResultInfo & attestResultInfo)64 int DevAttestClient::GetAttestStatus(AttestResultInfo &attestResultInfo)
65 {
66     HILOGI("DevAttestClient GetAttestStatus Begin");
67     if (attestClientInterface_ == nullptr) {
68         HILOGE("DevAttestClient GetAttestStatus attestClientInterface_ is null");
69         return DEVATTEST_FAIL;
70     }
71     int ret = attestClientInterface_->GetAttestStatus(attestResultInfo);
72     if (ret != DEVATTEST_SUCCESS) {
73         HILOGE("DevAttestClient GetAttestStatus failed ret = %{public}d", ret);
74         return ret;
75     }
76     HILOGI("DevAttestClient GetAttestStatus end");
77     return DEVATTEST_SUCCESS;
78 }
79 }
80 }