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 "pin_auth_stub.h"
17
18 #include "iam_logger.h"
19 #include "iam_common_defines.h"
20
21 #define LOG_LABEL UserIam::Common::LABEL_PIN_AUTH_SA
22
23 namespace OHOS {
24 namespace UserIam {
25 namespace PinAuth {
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)26 int32_t PinAuthStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
27 {
28 IAM_LOGI("cmd = %{public}u, flags = %{public}d", code, option.GetFlags());
29 if (PinAuthStub::GetDescriptor() != data.ReadInterfaceToken()) {
30 IAM_LOGE("descriptor is not matched");
31 return UserAuth::GENERAL_ERROR;
32 }
33 switch (code) {
34 case PinAuthInterface::REGISTER_INPUTER:
35 RegisterInputerStub(data, reply);
36 return UserAuth::SUCCESS;
37 case PinAuthInterface::UNREGISTER_INPUTER:
38 UnRegisterInputerStub(data, reply);
39 return UserAuth::SUCCESS;
40 default:
41 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
42 }
43 }
44
RegisterInputerStub(MessageParcel & data,MessageParcel & reply)45 void PinAuthStub::RegisterInputerStub(MessageParcel &data, MessageParcel &reply)
46 {
47 IAM_LOGI("start");
48 sptr<IRemoteObject> obj = data.ReadRemoteObject();
49 if (obj == nullptr) {
50 IAM_LOGE("failed to read remote object");
51 return;
52 }
53 sptr<InputerGetData> inputer = iface_cast<InputerGetData>(obj);
54 if (inputer == nullptr) {
55 IAM_LOGE("inputer is nullptr");
56 return;
57 }
58 bool ret = RegisterInputer(inputer);
59 if (!reply.WriteBool(ret)) {
60 IAM_LOGE("failed to write result");
61 }
62 }
63
UnRegisterInputerStub(MessageParcel & data,MessageParcel & reply)64 void PinAuthStub::UnRegisterInputerStub(MessageParcel &data, MessageParcel &reply)
65 {
66 (void)data;
67 (void)reply;
68 IAM_LOGI("start");
69 UnRegisterInputer();
70 }
71 } // namespace PinAuth
72 } // namespace UserIam
73 } // namespace OHOS