• 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 "userauth_async_proxy.h"
17 #include "userauth_hilog_wrapper.h"
18 #include "iuser_auth.h"
19 
20 namespace OHOS {
21 namespace UserIAM {
22 namespace UserAuth {
onAcquireInfo(const int32_t module,const uint32_t acquireInfo,const int32_t extraInfo)23 void UserAuthAsyncProxy::onAcquireInfo(const int32_t module, const uint32_t acquireInfo, const int32_t extraInfo)
24 {
25     USERAUTH_HILOGD(MODULE_SERVICE, "UserAuthAsyncProxy onAcquireInfo start");
26 
27     MessageParcel data;
28     MessageParcel reply;
29 
30     if (!data.WriteInterfaceToken(UserAuthAsyncProxy::GetDescriptor())) {
31         USERAUTH_HILOGE(MODULE_SERVICE, "write descriptor failed");
32         return;
33     }
34     if (!data.WriteInt32(module)) {
35         USERAUTH_HILOGE(MODULE_SERVICE, "failed to write module");
36         return;
37     }
38     if (!data.WriteUint32(acquireInfo)) {
39         USERAUTH_HILOGE(MODULE_SERVICE, "failed to write acquireInfo");
40         return;
41     }
42     if (!data.WriteInt32(extraInfo)) {
43         USERAUTH_HILOGE(MODULE_SERVICE, "failed to write extraInfo");
44         return;
45     }
46 
47     bool ret = SendRequest(IUserAuth::USER_AUTH_ACQUIRENFO, data, reply);
48     if (ret) {
49         int32_t result = reply.ReadInt32();
50         USERAUTH_HILOGE(MODULE_SERVICE, "result = %{public}d", result);
51     }
52 }
53 
onResult(const int32_t result,const AuthResult extraInfo)54 void UserAuthAsyncProxy::onResult(const int32_t result, const AuthResult extraInfo)
55 {
56     USERAUTH_HILOGD(MODULE_SERVICE, "UserAuthAsyncProxy onResult start");
57     MessageParcel data;
58     MessageParcel reply;
59     if (!data.WriteInterfaceToken(UserAuthAsyncProxy::GetDescriptor())) {
60         USERAUTH_HILOGE(MODULE_SERVICE, "write descriptor failed");
61         return;
62     }
63     if (!data.WriteInt32(result)) {
64         USERAUTH_HILOGE(MODULE_SERVICE, "failed to write result");
65         return;
66     }
67     if (!data.WriteUInt8Vector(extraInfo.token)) {
68         USERAUTH_HILOGE(MODULE_SERVICE, "failed to write token");
69         return;
70     }
71     if (!data.WriteUint32(extraInfo.remainTimes)) {
72         USERAUTH_HILOGE(MODULE_SERVICE, "failed to write remainTimes");
73         return;
74     }
75     if (!data.WriteUint32(extraInfo.freezingTime)) {
76         USERAUTH_HILOGE(MODULE_SERVICE, "failed to write freezingTime");
77         return;
78     }
79     bool ret = SendRequest(IUserAuth::USER_AUTH_ONRESULT, data, reply);
80     if (ret) {
81         int32_t result = reply.ReadInt32();
82         USERAUTH_HILOGE(MODULE_SERVICE, "result = %{public}d", result);
83     }
84 }
85 
onExecutorPropertyInfo(const ExecutorProperty result)86 void UserAuthAsyncProxy::onExecutorPropertyInfo(const ExecutorProperty result)
87 {
88     USERAUTH_HILOGD(MODULE_SERVICE, "UserAuthAsyncProxy onExecutorPropertyInfo start");
89     MessageParcel data;
90     MessageParcel reply;
91     if (!data.WriteInterfaceToken(UserAuthAsyncProxy::GetDescriptor())) {
92         USERAUTH_HILOGE(MODULE_SERVICE, "write descriptor failed");
93         return;
94     }
95     if (!data.WriteInt32(result.result)) {
96         USERAUTH_HILOGE(MODULE_SERVICE, "failed to write result");
97         return;
98     }
99     if (!data.WriteUint64(result.authSubType)) {
100         USERAUTH_HILOGE(MODULE_SERVICE, "failed to write authSubType");
101         return;
102     }
103     if (!data.WriteUint32(result.remainTimes)) {
104         USERAUTH_HILOGE(MODULE_SERVICE, "failed to write remainTimes");
105         return;
106     }
107     if (!data.WriteUint32(result.freezingTime)) {
108         USERAUTH_HILOGE(MODULE_SERVICE, "failed to write freezingTime");
109         return;
110     }
111     bool ret = SendRequest(IUserAuth::USER_AUTH_GETEXPORP, data, reply);
112     if (ret) {
113         int32_t result = reply.ReadInt32();
114         USERAUTH_HILOGE(MODULE_SERVICE, "result = %{public}d", result);
115     }
116 }
117 
onSetExecutorProperty(const int32_t result)118 void UserAuthAsyncProxy::onSetExecutorProperty(const int32_t result)
119 {
120     USERAUTH_HILOGD(MODULE_SERVICE, "UserAuthAsyncProxy onSetExecutorProperty start");
121 
122     MessageParcel data;
123     MessageParcel reply;
124     if (!data.WriteInterfaceToken(UserAuthAsyncProxy::GetDescriptor())) {
125         USERAUTH_HILOGE(MODULE_SERVICE, "write descriptor failed");
126         return;
127     }
128     if (!data.WriteInt32(result)) {
129         USERAUTH_HILOGE(MODULE_SERVICE, "failed to write result");
130         return;
131     }
132 
133     bool ret = SendRequest(IUserAuth::USER_AUTH_SETEXPORP, data, reply);
134     if (ret) {
135         int32_t result = reply.ReadInt32();
136         USERAUTH_HILOGE(MODULE_SERVICE, "result = %{public}d", result);
137     }
138 }
139 
SendRequest(uint32_t code,MessageParcel & data,MessageParcel & reply)140 bool UserAuthAsyncProxy::SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply)
141 {
142     USERAUTH_HILOGD(MODULE_SERVICE, "UserAuthAsyncProxy SendRequest start");
143 
144     sptr<IRemoteObject> remote = Remote();
145     if (remote == nullptr) {
146         USERAUTH_HILOGE(MODULE_SERVICE, "failed to get remote");
147         return false;
148     }
149     MessageOption option(MessageOption::TF_SYNC);
150     int32_t result = remote->SendRequest(code, data, reply, option);
151     if (result != OHOS::UserIAM::UserAuth::SUCCESS) {
152         USERAUTH_HILOGE(MODULE_SERVICE, "failed to SendRequest result = %{public}d", result);
153         return false;
154     }
155     USERAUTH_HILOGD(MODULE_SERVICE, "SendRequest end");
156     return true;
157 }
158 }  // namespace UserAuth
159 }  // namespace UserIAM
160 }  // namespace OHOS
161