• 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 "i_inputer_stub.h"
17 #include "inputer_data_impl.h"
18 #include "iremote_inputer.h"
19 #include "iremote_stub.h"
20 #include "pinauth_defines.h"
21 #include "pinauth_log_wrapper.h"
22 
23 namespace OHOS {
24 namespace UserIAM {
25 namespace PinAuth {
IInputerStub(std::shared_ptr<IInputer> inputer)26 IInputerStub::IInputerStub(std::shared_ptr<IInputer> inputer) : inputer_(inputer)
27 {
28 }
29 IInputerStub::~IInputerStub() = default;
30 
HandlerOnGetData(MessageParcel & data,MessageParcel & reply)31 void IInputerStub::HandlerOnGetData(MessageParcel &data, MessageParcel &reply)
32 {
33     int32_t authSubType = data.ReadInt32();
34     PINAUTH_HILOGI(MODULE_SERVICE, "IInputerStub::HandlerOnGetData start %{public}d", authSubType);
35     std::vector<uint8_t> salt;
36     data.ReadUInt8Vector(&salt);
37     sptr<IRemoteObject> remote = data.ReadRemoteObject();
38     if (remote == nullptr) {
39         PINAUTH_HILOGE(MODULE_SERVICE, "IInputerStub::HandlerOnGetData remote is nullptr");
40         return;
41     }
42     sptr<IRemoteInputerData> inputerData = iface_cast<IRemoteInputerData>(remote);
43     if (inputerData == nullptr) {
44         PINAUTH_HILOGE(MODULE_SERVICE, "IInputerStub::HandlerOnGetData inputerData is nullptr");
45         return;
46     }
47     OnGetData(authSubType, salt, inputerData.GetRefPtr());
48 }
49 
OnGetData(int32_t authSubType,std::vector<uint8_t> salt,sptr<IRemoteInputerData> inputerData)50 void IInputerStub::OnGetData(int32_t authSubType, std::vector<uint8_t> salt, sptr<IRemoteInputerData> inputerData)
51 {
52     PINAUTH_HILOGI(MODULE_SERVICE, "IInputerStub::OnGetData start");
53     if (inputerData == nullptr) {
54         PINAUTH_HILOGE(MODULE_SERVICE, "IInputerStub::OnGetData inputerData is nullptr");
55         return;
56     }
57     std::shared_ptr<IInputerData> sharedInputerData = std::make_shared<InputerDataImpl>(salt, inputerData);
58     inputer_->OnGetData(authSubType, sharedInputerData);
59 }
60 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)61 int32_t IInputerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
62 {
63     PINAUTH_HILOGI(MODULE_SERVICE, "IInputerStub::OnRemoteRequest start code:%{public}u", code);
64     std::u16string descripter = IInputerStub::GetDescriptor();
65     std::u16string remoteDescripter = data.ReadInterfaceToken();
66     PINAUTH_HILOGI(MODULE_SERVICE, "IInputerStub::OnRemoteRequest descripter:%s, remoteDescripter:%s",
67         (char *)(descripter.c_str()), (char *)(remoteDescripter.c_str()));
68     if (descripter != remoteDescripter) {
69         PINAUTH_HILOGE(MODULE_SERVICE, "IInputerStub::OnRemoteRequest descripter is not remoteDescripter");
70         return FAIL;
71     }
72 
73     switch (code) {
74         case static_cast<int32_t>(IRemoteInputer::ON_GET_DATA):
75             HandlerOnGetData(data, reply);
76             return SUCCESS;
77         default:
78             PINAUTH_HILOGI(MODULE_SERVICE, "IInputerStub::OnRemoteRequest default");
79             return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
80     }
81     return SUCCESS;
82 }
83 } // namespace PinAuth
84 } // namespace UserIAM
85 } // namespace OHOS
86