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_service_proxy.h"
17
18 #include "devattest_log.h"
19 #include "devattest_errno.h"
20
21 using namespace std;
22 namespace OHOS {
23 namespace DevAttest {
GetAttestStatus(AttestResultInfo & attestResultInfo)24 int32_t DevAttestServiceProxy::GetAttestStatus(AttestResultInfo &attestResultInfo)
25 {
26 MessageParcel data;
27 MessageParcel reply;
28 MessageOption option;
29
30 if (!data.WriteInterfaceToken(GetDescriptor())) {
31 HILOGE("[DevAttestServiceProxy] write interface token failed");
32 return DEVATTEST_FAIL;
33 }
34
35 sptr<IRemoteObject> remote = Remote();
36 if (remote == nullptr) {
37 HILOGE("[DevAttestServiceProxy] remote service null");
38 return DEVATTEST_FAIL;
39 }
40 int ret = remote->SendRequest(GET_AUTH_RESULT, data, reply, option);
41 if (ret != DEVATTEST_SUCCESS) {
42 HILOGE("[DevAttestServiceProxy] call SendRequest failed %{public}d", ret);
43 return DEVATTEST_FAIL;
44 }
45 int32_t authRet;
46 if (!reply.ReadInt32(authRet)) {
47 HILOGE("[DevAttestServiceProxy] authRet failed %{public}d", authRet);
48 return DEVATTEST_FAIL;
49 }
50 if (authRet != DEVATTEST_SUCCESS) {
51 HILOGE("[DevAttestServiceProxy] authRet failed code %{public}d", authRet);
52 return authRet;
53 }
54
55 sptr<AttestResultInfo> attestResultInfoPtr = AttestResultInfo::Unmarshalling(reply);
56 if (attestResultInfoPtr == nullptr) {
57 HILOGE("[DevAttestServiceProxy] attestResultInfoPtr is nullptr");
58 return DEVATTEST_FAIL;
59 }
60 attestResultInfo = *attestResultInfoPtr;
61 return DEVATTEST_SUCCESS;
62 }
63 }
64 }