1 /*
2 * Copyright (c) 2022-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 "inputer_set_data_stub.h"
17
18 #include "iam_logger.h"
19 #include "iam_common_defines.h"
20
21 #define LOG_TAG "PIN_AUTH_SA"
22
23 namespace OHOS {
24 namespace UserIam {
25 namespace PinAuth {
26
27 // When true is passed into IRemoteStub, sa will process request serially.
InputerSetDataStub()28 InputerSetDataStub::InputerSetDataStub() : IRemoteStub(true) {};
29
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)30 int32_t InputerSetDataStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
31 MessageOption &option)
32 {
33 IAM_LOGI("cmd = %{public}u, flags = %{public}d", code, option.GetFlags());
34 if (InputerSetDataStub::GetDescriptor() != data.ReadInterfaceToken()) {
35 IAM_LOGE("descriptor is not matched");
36 return UserAuth::GENERAL_ERROR;
37 }
38 switch (code) {
39 case InputerSetDataInterfaceCode::ON_SET_DATA:
40 OnSetDataStub(data, reply);
41 return UserAuth::SUCCESS;
42 default:
43 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
44 }
45 }
46
OnSetDataStub(MessageParcel & data,MessageParcel & reply)47 void InputerSetDataStub::OnSetDataStub(MessageParcel &data, MessageParcel &reply)
48 {
49 IAM_LOGI("start");
50 int32_t subType;
51 std::vector<uint8_t> param;
52 int32_t errorCode;
53
54 if (!data.ReadInt32(subType)) {
55 IAM_LOGE("failed to read subType");
56 return;
57 }
58 if (!data.ReadUInt8Vector(¶m)) {
59 IAM_LOGE("failed to read param");
60 return;
61 }
62 if (!data.ReadInt32(errorCode)) {
63 IAM_LOGE("failed to read errorCode");
64 return;
65 }
66
67 OnSetData(subType, param, errorCode);
68 }
69 } // namespace PinAuth
70 } // namespace UserIam
71 } // namespace OHOS
72