• 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 "useridm_callback_proxy.h"
17 #include "useridm_hilog_wrapper.h"
18 
19 namespace OHOS {
20 namespace UserIAM {
21 namespace UserIDM {
OnResult(int32_t result,RequestResult reqRet)22 void UserIDMCallbackProxy::OnResult(int32_t result, RequestResult reqRet)
23 {
24     USERIDM_HILOGD(MODULE_SERVICE, "UserIDMCallbackProxy OnResult start");
25 
26     MessageParcel data;
27     MessageParcel reply;
28 
29     if (!data.WriteInterfaceToken(UserIDMCallbackProxy::GetDescriptor())) {
30         USERIDM_HILOGE(MODULE_SERVICE, "failed to write descriptor");
31         return;
32     }
33 
34     if (!data.WriteInt32(result)) {
35         USERIDM_HILOGE(MODULE_SERVICE, "failed to WriteInt32(result)");
36         return;
37     }
38 
39     if (!data.WriteUint64(reqRet.credentialId)) {
40         USERIDM_HILOGE(MODULE_SERVICE, "failed to WriteUint64(reqRet.credentialId)");
41         return;
42     }
43 
44     bool ret = SendRequest(IDM_CALLBACK_ON_RESULT, data, reply);
45     if (ret) {
46         int32_t result = reply.ReadInt32();
47         USERIDM_HILOGI(MODULE_SERVICE, "result = %{public}d", result);
48     }
49 }
50 
OnAcquireInfo(int32_t module,int32_t acquire,RequestResult reqRet)51 void UserIDMCallbackProxy::OnAcquireInfo(int32_t module, int32_t acquire, RequestResult reqRet)
52 {
53     USERIDM_HILOGD(MODULE_SERVICE, "UserIDMCallbackProxy OnAcquireInfo start");
54 
55     MessageParcel data;
56     MessageParcel reply;
57 
58     if (!data.WriteInterfaceToken(UserIDMCallbackProxy::GetDescriptor())) {
59         USERIDM_HILOGE(MODULE_SERVICE, "failed to write descriptor");
60         return;
61     }
62 
63     if (!data.WriteInt32(module)) {
64         USERIDM_HILOGE(MODULE_SERVICE, "failed to WriteInt32(module)");
65         return;
66     }
67 
68     if (!data.WriteInt32(acquire)) {
69         USERIDM_HILOGE(MODULE_SERVICE, "failed to WriteInt32(acquire)");
70         return;
71     }
72 
73     if (!data.WriteUint64(reqRet.credentialId)) {
74         USERIDM_HILOGE(MODULE_SERVICE, "failed to WriteUint64(reqRet.credentialId)");
75         return;
76     }
77 
78     bool ret = SendRequest(IDM_CALLBACK_ON_ACQUIRE_INFO, data, reply);
79     if (ret) {
80         int32_t result = reply.ReadInt32();
81         USERIDM_HILOGI(MODULE_SERVICE, "result = %{public}d", result);
82     }
83 }
84 
SendRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,bool isSync)85 bool UserIDMCallbackProxy::SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, bool isSync)
86 {
87     USERIDM_HILOGD(MODULE_SERVICE, "UserIDMCallbackProxy SendRequest start");
88 
89     sptr<IRemoteObject> remote = Remote();
90     if (remote == nullptr) {
91         USERIDM_HILOGE(MODULE_SERVICE, "failed to get remote");
92         return false;
93     }
94     MessageOption option(MessageOption::TF_SYNC);
95     if (!isSync) {
96         option.SetFlags(MessageOption::TF_ASYNC);
97     }
98 
99     int32_t result = remote->SendRequest(code, data, reply, option);
100     if (result != OHOS::UserIAM::UserIDM::SUCCESS) {
101         USERIDM_HILOGE(MODULE_SERVICE, "failed to SendRequest.result = %{public}d", result);
102         return false;
103     }
104     return true;
105 }
106 }  // namespace UserIDM
107 }  // namespace UserIAM
108 }  // namespace OHOS
109