1 /*
2 * Copyright (c) 2021-2023 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 "form_supply_stub.h"
17
18 #include "appexecfwk_errors.h"
19 #include "fms_log_wrapper.h"
20 #include "form_constants.h"
21 #include "form_mgr_errors.h"
22 #include "form_supply_stub.h"
23 #include "ipc_skeleton.h"
24 #include "ipc_types.h"
25 #include "iremote_object.h"
26
27 namespace OHOS {
28 namespace AppExecFwk {
FormSupplyStub()29 FormSupplyStub::FormSupplyStub()
30 {}
31
~FormSupplyStub()32 FormSupplyStub::~FormSupplyStub()
33 {}
34 /**
35 * @brief handle remote request.
36 * @param data input param.
37 * @param reply output param.
38 * @param option message option.
39 * @return Returns ERR_OK on success, others on failure.
40 */
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)41 int FormSupplyStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
42 {
43 HILOG_DEBUG("FormSupplyStub::OnReceived,code= %{public}u,flags= %{public}d", code, option.GetFlags());
44 std::u16string descriptor = FormSupplyStub::GetDescriptor();
45 std::u16string remoteDescriptor = data.ReadInterfaceToken();
46 if (descriptor != remoteDescriptor) {
47 HILOG_ERROR("localDescriptor not equal to remote");
48 return ERR_APPEXECFWK_FORM_INVALID_PARAM;
49 }
50
51 switch (code) {
52 case static_cast<uint32_t>(IFormSupply::Message::TRANSACTION_FORM_ACQUIRED):
53 return HandleOnAcquire(data, reply);
54 case static_cast<uint32_t>(IFormSupply::Message::TRANSACTION_EVENT_HANDLE):
55 return HandleOnEventHandle(data, reply);
56 case static_cast<uint32_t>(IFormSupply::Message::TRANSACTION_FORM_STATE_ACQUIRED):
57 return HandleOnAcquireStateResult(data, reply);
58 case static_cast<uint32_t>(IFormSupply::Message::TRANSACTION_FORM_SHARE_ACQUIRED):
59 return HandleOnShareAcquire(data, reply);
60 case static_cast<uint32_t>(IFormSupply::Message::TRANSACTION_FORM_RENDER_TASK_DONE):
61 return HandleOnRenderTaskDone(data, reply);
62 case static_cast<uint32_t>(IFormSupply::Message::TRANSACTION_FORM_STOP_RENDERING_TASK_DONE):
63 return HandleOnStopRenderingTaskDone(data, reply);
64 case static_cast<uint32_t>(IFormSupply::Message::TRANSACTION_FORM_ACQUIRED_DATA):
65 return HandleOnAcquireDataResult(data, reply);
66 case static_cast<uint32_t>(IFormSupply::Message::TRANSACTION_FORM_RENDERING_BLOCK):
67 return HandleOnRenderingBlock(data, reply);
68 case static_cast<uint32_t>(IFormSupply::Message::TRANSACTION_FORM_RECYCLE_FORM):
69 return HandleOnRecycleForm(data, reply);
70 case static_cast<uint32_t>(IFormSupply::Message::TRANSACTION_FORM_RECOVER_FORM_BY_CONFIG_UPDATE):
71 return HandleOnRecoverFormsByConfigUpdate(data, reply);
72 case static_cast<uint32_t>(IFormSupply::Message::TRANSACTION_NOTIFY_REFRESH):
73 return HandleOnNotifyRefreshForm(data, reply);
74 case static_cast<uint32_t>(IFormSupply::Message::TRANSACTION_FORM_RENDER_FORM_DONE):
75 return HandleOnRenderFormDone(data, reply);
76 case static_cast<uint32_t>(IFormSupply::Message::TRANSACTION_FORM_RECOVER_FORM_DONE):
77 return HandleOnRecoverFormDone(data, reply);
78 case static_cast<uint32_t>(IFormSupply::Message::TRANSACTION_FORM_RECYCLE_FORM_DONE):
79 return HandleOnRecycleFormDone(data, reply);
80 case static_cast<uint32_t>(IFormSupply::Message::TRANSACTION_FORM_DELETE_FORM_DONE):
81 return HandleOnDeleteFormDone(data, reply);
82 default:
83 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
84 }
85 }
86 /**
87 * @brief handle OnAcquire message.
88 * @param data input param.
89 * @param reply output param.
90 * @return Returns ERR_OK on success, others on failure.
91 */
HandleOnAcquire(MessageParcel & data,MessageParcel & reply)92 int FormSupplyStub::HandleOnAcquire(MessageParcel &data, MessageParcel &reply)
93 {
94 std::unique_ptr<Want> want(data.ReadParcelable<Want>());
95 if (!want) {
96 HILOG_ERROR("ReadParcelable<Want> failed");
97 reply.WriteInt32(ERR_APPEXECFWK_PARCEL_ERROR);
98 return ERR_APPEXECFWK_PARCEL_ERROR;
99 }
100
101 int errCode = ERR_OK;
102 do {
103 errCode = want->GetIntParam(Constants::PROVIDER_FLAG, ERR_OK);
104 if (errCode != ERR_OK) {
105 HILOG_ERROR("get providerParam failed");
106 break;
107 }
108 std::unique_ptr<FormProviderInfo> formInfo(data.ReadParcelable<FormProviderInfo>());
109 if (formInfo == nullptr) {
110 HILOG_ERROR("fail ReadParcelable<FormProviderInfo>");
111 errCode = ERR_APPEXECFWK_PARCEL_ERROR;
112 break;
113 }
114 int32_t result = OnAcquire(*formInfo, *want);
115 reply.WriteInt32(result);
116 return result;
117 } while (false);
118
119 FormProviderInfo formProviderInfo;
120 want->SetParam(Constants::PROVIDER_FLAG, errCode);
121 OnAcquire(formProviderInfo, *want);
122 reply.WriteInt32(errCode);
123 return errCode;
124 }
125 /**
126 * @brief handle OnEventHandle message.
127 * @param data input param.
128 * @param reply output param.
129 * @return Returns ERR_OK on success, others on failure.
130 */
HandleOnEventHandle(MessageParcel & data,MessageParcel & reply)131 int FormSupplyStub::HandleOnEventHandle(MessageParcel &data, MessageParcel &reply)
132 {
133 std::unique_ptr<Want> want(data.ReadParcelable<Want>());
134 if (!want) {
135 HILOG_ERROR("ReadParcelable<Want> failed");
136 reply.WriteInt32(ERR_APPEXECFWK_PARCEL_ERROR);
137 return ERR_APPEXECFWK_PARCEL_ERROR;
138 }
139
140 int32_t result = OnEventHandle(*want);
141 reply.WriteInt32(result);
142 return result;
143 }
144
145 /**
146 * @brief handle OnAcquireStateResult message.
147 * @param data input param.
148 * @param reply output param.
149 * @return Returns ERR_OK on success, others on failure.
150 */
HandleOnAcquireStateResult(MessageParcel & data,MessageParcel & reply)151 int FormSupplyStub::HandleOnAcquireStateResult(MessageParcel &data, MessageParcel &reply)
152 {
153 auto state = (FormState) data.ReadInt32();
154 std::string provider = data.ReadString();
155 std::unique_ptr<Want> wantArg(data.ReadParcelable<Want>());
156 if (!wantArg) {
157 HILOG_ERROR("ReadParcelable<Want> failed");
158 reply.WriteInt32(ERR_APPEXECFWK_PARCEL_ERROR);
159 return ERR_APPEXECFWK_PARCEL_ERROR;
160 }
161
162 std::unique_ptr<Want> want(data.ReadParcelable<Want>());
163 if (!want) {
164 HILOG_ERROR("ReadParcelable<Want> failed");
165 reply.WriteInt32(ERR_APPEXECFWK_PARCEL_ERROR);
166 return ERR_APPEXECFWK_PARCEL_ERROR;
167 }
168
169 int32_t result = OnAcquireStateResult(state, provider, *wantArg, *want);
170 reply.WriteInt32(result);
171 return result;
172 }
173
HandleOnShareAcquire(MessageParcel & data,MessageParcel & reply)174 int32_t FormSupplyStub::HandleOnShareAcquire(MessageParcel &data, MessageParcel &reply)
175 {
176 auto formId = data.ReadInt64();
177 if (formId <= 0) {
178 HILOG_ERROR("ReadInt64<formId> failed");
179 return ERR_APPEXECFWK_PARCEL_ERROR;
180 }
181
182 auto remoteDeviceId = data.ReadString();
183 if (remoteDeviceId.empty()) {
184 HILOG_ERROR("fail ReadString<DeviceId>");
185 return ERR_APPEXECFWK_PARCEL_ERROR;
186 }
187
188 std::shared_ptr<AAFwk::WantParams> wantParams(data.ReadParcelable<AAFwk::WantParams>());
189 if (wantParams == nullptr) {
190 HILOG_ERROR("error to ReadParcelable<wantParams>");
191 return ERR_APPEXECFWK_PARCEL_ERROR;
192 }
193
194 auto requestCode = data.ReadInt64();
195 if (requestCode <= 0) {
196 HILOG_ERROR("error to ReadInt64<requestCode>");
197 return ERR_APPEXECFWK_PARCEL_ERROR;
198 }
199
200 auto result = data.ReadBool();
201 OnShareAcquire(formId, remoteDeviceId, *wantParams, requestCode, result);
202 return ERR_OK;
203 }
204
HandleOnAcquireDataResult(MessageParcel & data,MessageParcel & reply)205 int32_t FormSupplyStub::HandleOnAcquireDataResult(MessageParcel &data, MessageParcel &reply)
206 {
207 std::shared_ptr<AAFwk::WantParams> wantParams(data.ReadParcelable<AAFwk::WantParams>());
208 if (wantParams == nullptr) {
209 HILOG_ERROR("ReadParcelable<wantParams> failed");
210 return ERR_APPEXECFWK_PARCEL_ERROR;
211 }
212
213 auto requestCode = data.ReadInt64();
214 if (requestCode <= 0) {
215 HILOG_ERROR("fail ReadInt64<requestCode>");
216 return ERR_APPEXECFWK_PARCEL_ERROR;
217 }
218
219 OnAcquireDataResult(*wantParams, requestCode);
220 return ERR_OK;
221 }
222
HandleOnRenderTaskDone(MessageParcel & data,MessageParcel & reply)223 int32_t FormSupplyStub::HandleOnRenderTaskDone(MessageParcel &data, MessageParcel &reply)
224 {
225 auto formId = data.ReadInt64();
226 if (formId <= 0) {
227 HILOG_ERROR("ReadInt64<formId> failed");
228 return ERR_APPEXECFWK_PARCEL_ERROR;
229 }
230
231 std::unique_ptr<Want> want(data.ReadParcelable<Want>());
232 if (!want) {
233 HILOG_ERROR("ReadParcelable<Want> failed");
234 reply.WriteInt32(ERR_APPEXECFWK_PARCEL_ERROR);
235 return ERR_APPEXECFWK_PARCEL_ERROR;
236 }
237
238 int32_t result = OnRenderTaskDone(formId, *want);
239 reply.WriteInt32(result);
240 return result;
241 }
242
HandleOnStopRenderingTaskDone(MessageParcel & data,MessageParcel & reply)243 int32_t FormSupplyStub::HandleOnStopRenderingTaskDone(MessageParcel &data, MessageParcel &reply)
244 {
245 auto formId = data.ReadInt64();
246 if (formId <= 0) {
247 HILOG_ERROR("ReadInt64<formId> failed");
248 return ERR_APPEXECFWK_PARCEL_ERROR;
249 }
250
251 std::unique_ptr<Want> want(data.ReadParcelable<Want>());
252 if (!want) {
253 HILOG_ERROR("ReadParcelable<Want> failed");
254 reply.WriteInt32(ERR_APPEXECFWK_PARCEL_ERROR);
255 return ERR_APPEXECFWK_PARCEL_ERROR;
256 }
257
258 int32_t result = OnStopRenderingTaskDone(formId, *want);
259 reply.WriteInt32(result);
260 return result;
261 }
262
HandleOnRenderingBlock(MessageParcel & data,MessageParcel & reply)263 int32_t FormSupplyStub::HandleOnRenderingBlock(MessageParcel &data, MessageParcel &reply)
264 {
265 auto bundleName = data.ReadString();
266 if (bundleName.empty()) {
267 HILOG_ERROR("fail ReadString<bundleName>");
268 return ERR_APPEXECFWK_PARCEL_ERROR;
269 }
270
271 int32_t result = OnRenderingBlock(bundleName);
272 reply.WriteInt32(result);
273 return result;
274 }
275
HandleOnRecycleForm(MessageParcel & data,MessageParcel & reply)276 int32_t FormSupplyStub::HandleOnRecycleForm(MessageParcel &data, MessageParcel &reply)
277 {
278 int64_t formId = data.ReadInt64();
279 if (formId <= 0) {
280 HILOG_ERROR("ReadInt64<formId> failed");
281 return ERR_APPEXECFWK_PARCEL_ERROR;
282 }
283
284 std::unique_ptr<Want> want(data.ReadParcelable<Want>());
285 if (!want) {
286 HILOG_ERROR("ReadParcelable<Want> failed");
287 reply.WriteInt32(ERR_APPEXECFWK_PARCEL_ERROR);
288 return ERR_APPEXECFWK_PARCEL_ERROR;
289 }
290
291 int32_t result = OnRecycleForm(formId, *want);
292 reply.WriteInt32(result);
293 return result;
294 }
295
HandleOnRecoverFormsByConfigUpdate(MessageParcel & data,MessageParcel & reply)296 int32_t FormSupplyStub::HandleOnRecoverFormsByConfigUpdate(MessageParcel &data, MessageParcel &reply)
297 {
298 std::vector<int64_t> formIds;
299
300 if (!data.ReadInt64Vector(&formIds)) {
301 HILOG_ERROR("ReadInt64Vector failed");
302 return ERR_APPEXECFWK_PARCEL_ERROR;
303 }
304
305 if (formIds.empty()) {
306 HILOG_ERROR("empty formIds");
307 return ERR_APPEXECFWK_PARCEL_ERROR;
308 }
309
310 int32_t result = OnRecoverFormsByConfigUpdate(formIds);
311 reply.WriteInt32(result);
312 return result;
313 }
314
HandleOnNotifyRefreshForm(MessageParcel & data,MessageParcel & reply)315 int32_t FormSupplyStub::HandleOnNotifyRefreshForm(MessageParcel &data, MessageParcel &reply)
316 {
317 int64_t formId = data.ReadInt64();
318 if (formId <= 0) {
319 HILOG_ERROR("ReadInt64<formId> failed");
320 return ERR_APPEXECFWK_PARCEL_ERROR;
321 }
322
323 int32_t result = OnNotifyRefreshForm(formId);
324 reply.WriteInt32(result);
325 return ERR_OK;
326 }
327
HandleOnRenderFormDone(MessageParcel & data,MessageParcel & reply)328 int32_t FormSupplyStub::HandleOnRenderFormDone(MessageParcel &data, MessageParcel &reply)
329 {
330 auto formId = data.ReadInt64();
331 if (formId <= 0) {
332 HILOG_ERROR("ReadInt64<formId> failed");
333 return ERR_APPEXECFWK_PARCEL_ERROR;
334 }
335
336 std::unique_ptr<Want> want(data.ReadParcelable<Want>());
337 if (!want) {
338 HILOG_ERROR("ReadParcelable<Want> failed");
339 reply.WriteInt32(ERR_APPEXECFWK_PARCEL_ERROR);
340 return ERR_APPEXECFWK_PARCEL_ERROR;
341 }
342
343 int32_t result = OnRenderFormDone(formId, *want);
344 reply.WriteInt32(result);
345 return result;
346 }
347
HandleOnRecoverFormDone(MessageParcel & data,MessageParcel & reply)348 int32_t FormSupplyStub::HandleOnRecoverFormDone(MessageParcel &data, MessageParcel &reply)
349 {
350 auto formId = data.ReadInt64();
351 if (formId <= 0) {
352 HILOG_ERROR("ReadInt64<formId> failed");
353 return ERR_APPEXECFWK_PARCEL_ERROR;
354 }
355
356 std::unique_ptr<Want> want(data.ReadParcelable<Want>());
357 if (!want) {
358 HILOG_ERROR("ReadParcelable<Want> failed");
359 reply.WriteInt32(ERR_APPEXECFWK_PARCEL_ERROR);
360 return ERR_APPEXECFWK_PARCEL_ERROR;
361 }
362
363 int32_t result = OnRecoverFormDone(formId, *want);
364 reply.WriteInt32(result);
365 return result;
366 }
367
HandleOnRecycleFormDone(MessageParcel & data,MessageParcel & reply)368 int32_t FormSupplyStub::HandleOnRecycleFormDone(MessageParcel &data, MessageParcel &reply)
369 {
370 auto formId = data.ReadInt64();
371 if (formId <= 0) {
372 HILOG_ERROR("ReadInt64<formId> failed");
373 return ERR_APPEXECFWK_PARCEL_ERROR;
374 }
375
376 std::unique_ptr<Want> want(data.ReadParcelable<Want>());
377 if (!want) {
378 HILOG_ERROR("ReadParcelable<Want> failed");
379 reply.WriteInt32(ERR_APPEXECFWK_PARCEL_ERROR);
380 return ERR_APPEXECFWK_PARCEL_ERROR;
381 }
382
383 int32_t result = OnRecycleFormDone(formId, *want);
384 reply.WriteInt32(result);
385 return result;
386 }
387
HandleOnDeleteFormDone(MessageParcel & data,MessageParcel & reply)388 int32_t FormSupplyStub::HandleOnDeleteFormDone(MessageParcel &data, MessageParcel &reply)
389 {
390 auto formId = data.ReadInt64();
391 if (formId <= 0) {
392 HILOG_ERROR("ReadInt64<formId> failed");
393 return ERR_APPEXECFWK_PARCEL_ERROR;
394 }
395
396 std::unique_ptr<Want> want(data.ReadParcelable<Want>());
397 if (!want) {
398 HILOG_ERROR("ReadParcelable<Want> failed");
399 reply.WriteInt32(ERR_APPEXECFWK_PARCEL_ERROR);
400 return ERR_APPEXECFWK_PARCEL_ERROR;
401 }
402
403 int32_t result = OnDeleteFormDone(formId, *want);
404 reply.WriteInt32(result);
405 return result;
406 }
407 } // namespace AppExecFwk
408 } // namespace OHOS