• 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 "pinauth_proxy.h"
17 #include "pinauth_log_wrapper.h"
18 
19 namespace OHOS {
20 namespace UserIAM {
21 namespace PinAuth {
PinAuthProxy(const sptr<IRemoteObject> & object)22 PinAuthProxy::PinAuthProxy(const sptr<IRemoteObject> &object) : IRemoteProxy<IRemotePinAuth>(object)
23 {
24     PINAUTH_HILOGI(MODULE_FRAMEWORKS, "PinAuthProxy::PinAuthProxy start");
25 }
26 
~PinAuthProxy()27 PinAuthProxy::~PinAuthProxy()
28 {
29     PINAUTH_HILOGI(MODULE_FRAMEWORKS, "PinAuthProxy::~PinAuthProxy start");
30 }
31 
RegisterInputer(sptr<IRemoteInputer> inputer)32 bool PinAuthProxy::RegisterInputer(sptr<IRemoteInputer> inputer)
33 {
34     MessageParcel data;
35     MessageParcel reply;
36 
37     PINAUTH_HILOGI(MODULE_FRAMEWORKS, "PinAuthProxy::RegisterInputer start");
38     if (!data.WriteInterfaceToken(PinAuthProxy::GetDescriptor())) {
39         PINAUTH_HILOGE(MODULE_FRAMEWORKS, "write descriptor failed");
40         return false;
41     }
42 
43     if (!data.WriteRemoteObject(inputer->AsObject())) {
44         PINAUTH_HILOGE(MODULE_FRAMEWORKS, "write inputer failed");
45         return false;
46     }
47 
48     bool ret = SendRequest(static_cast<int32_t>(IRemotePinAuth::REGISTER_INPUTER), data, reply, true);
49     bool result = false;
50     if (!ret) {
51         PINAUTH_HILOGE(MODULE_FRAMEWORKS, "SendRequest is failed, error code: %d", ret);
52     } else {
53         result = reply.ReadBool();
54         PINAUTH_HILOGI(MODULE_FRAMEWORKS, "SendRequest is OK");
55     }
56     return result;
57 }
58 
UnRegisterInputer()59 void PinAuthProxy::UnRegisterInputer()
60 {
61     MessageParcel data;
62     MessageParcel reply;
63 
64     PINAUTH_HILOGI(MODULE_FRAMEWORKS, "PinAuthProxy::UnRegisterInputer start");
65     if (!data.WriteInterfaceToken(PinAuthProxy::GetDescriptor())) {
66         PINAUTH_HILOGE(MODULE_FRAMEWORKS, "write descriptor failed!");
67         return;
68     }
69 
70     bool ret = SendRequest(static_cast<int32_t>(IRemotePinAuth::UNREGISTER_INPUTER), data, reply, false);
71     if (!ret) {
72         PINAUTH_HILOGE(MODULE_FRAMEWORKS, "UnRegisterInputer SendRequest failed!");
73     }
74 }
75 
SendRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,bool isSync)76 bool PinAuthProxy::SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, bool isSync)
77 {
78     PINAUTH_HILOGI(MODULE_FRAMEWORKS, "PinAuthProxy::SendRequest start");
79     sptr<IRemoteObject> remote = Remote();
80     if (remote == nullptr) {
81         PINAUTH_HILOGE(MODULE_FRAMEWORKS, "failed to get remote.");
82         return false;
83     }
84     MessageOption option(isSync ? MessageOption::TF_SYNC : MessageOption::TF_ASYNC);
85     int32_t result = remote->SendRequest(code, data, reply, option);
86     if (result != OHOS::NO_ERROR) {
87         PINAUTH_HILOGE(MODULE_FRAMEWORKS, "failed to SendRequest.result = %{public}d", result);
88         return false;
89     }
90     return true;
91 }
92 } // namespace PinAuth
93 } // namespace UserIAM
94 } // namespace OHOS