• 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 "executor_messenger_stub.h"
17 
18 #include <cinttypes>
19 
20 #include "iam_check.h"
21 #include "iam_logger.h"
22 #include "iam_ptr.h"
23 #include "iam_common_defines.h"
24 
25 #define LOG_LABEL UserIam::Common::LABEL_USER_AUTH_SA
26 
27 namespace OHOS {
28 namespace UserIam {
29 namespace UserAuth {
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)30 int32_t ExecutorMessengerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
31     MessageOption &option)
32 {
33     IAM_LOGD("ExecutorMessengerStub::OnRemoteRequest, cmd = %{public}u, flags = %{public}d", code, option.GetFlags());
34     if (ExecutorMessengerStub::GetDescriptor() != data.ReadInterfaceToken()) {
35         IAM_LOGE("descriptor is not matched");
36         return GENERAL_ERROR;
37     }
38     switch (code) {
39         case ExecutorMessengerInterface::CO_AUTH_SEND_DATA:
40             return SendDataStub(data, reply);
41         case ExecutorMessengerInterface::CO_AUTH_FINISH:
42             return FinishStub(data, reply);
43         default:
44             return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
45     }
46 }
47 
SendDataStub(MessageParcel & data,MessageParcel & reply)48 int32_t ExecutorMessengerStub::SendDataStub(MessageParcel &data, MessageParcel &reply)
49 {
50     uint64_t scheduleId;
51     uint64_t transNum;
52     int32_t srcRole;
53     int32_t dstRole;
54     std::vector<uint8_t> msg;
55 
56     if (!data.ReadUint64(scheduleId)) {
57         IAM_LOGE("read scheduleId failed");
58         return READ_PARCEL_ERROR;
59     }
60     if (!data.ReadUint64(transNum)) {
61         IAM_LOGE("read transNum failed");
62         return READ_PARCEL_ERROR;
63     }
64     if (!data.ReadInt32(srcRole)) {
65         IAM_LOGE("read srcRole failed");
66         return READ_PARCEL_ERROR;
67     }
68     if (!data.ReadInt32(dstRole)) {
69         IAM_LOGE("read dstRole failed");
70         return READ_PARCEL_ERROR;
71     }
72     if (!data.ReadUInt8Vector(&msg)) {
73         IAM_LOGE("read msg failed");
74         return GENERAL_ERROR;
75     }
76 
77     int32_t result =
78         SendData(scheduleId, transNum, static_cast<ExecutorRole>(srcRole), static_cast<ExecutorRole>(dstRole), msg);
79     if (!reply.WriteInt32(result)) {
80         IAM_LOGE("write SendData result failed");
81         return WRITE_PARCEL_ERROR;
82     }
83     return SUCCESS;
84 }
85 
FinishStub(MessageParcel & data,MessageParcel & reply)86 int32_t ExecutorMessengerStub::FinishStub(MessageParcel &data, MessageParcel &reply)
87 {
88     uint64_t scheduleId;
89     int32_t srcRole;
90     int32_t resultCode;
91     std::vector<uint8_t> attributes;
92 
93     if (!data.ReadUint64(scheduleId)) {
94         IAM_LOGE("read scheduleId failed");
95         return READ_PARCEL_ERROR;
96     }
97     if (!data.ReadInt32(srcRole)) {
98         IAM_LOGE("read srcRole failed");
99         return READ_PARCEL_ERROR;
100     }
101     if (!data.ReadInt32(resultCode)) {
102         IAM_LOGE("read resultCode failed");
103         return READ_PARCEL_ERROR;
104     }
105     if (!data.ReadUInt8Vector(&attributes)) {
106         IAM_LOGE("read attributes failed");
107         return READ_PARCEL_ERROR;
108     }
109     auto finalResult = Common::MakeShared<Attributes>(attributes);
110     IF_FALSE_LOGE_AND_RETURN_VAL(finalResult != nullptr, WRITE_PARCEL_ERROR);
111     int32_t result =
112         Finish(scheduleId, static_cast<ExecutorRole>(srcRole), static_cast<ResultCode>(resultCode), finalResult);
113     if (!reply.WriteInt32(result)) {
114         IAM_LOGE("write Finish result failed");
115         return WRITE_PARCEL_ERROR;
116     }
117     return SUCCESS;
118 }
119 } // namespace UserAuth
120 } // namespace UserIam
121 } // namespace OHOS