1 /*
2 * Copyright (c) 2021-2024 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_mgr_stub.h"
17
18 #include "appexecfwk_errors.h"
19 #include "fms_log_wrapper.h"
20 #include "form_info.h"
21 #include "form_mgr_errors.h"
22 #include "ipc_skeleton.h"
23 #include "ipc_types.h"
24 #include "iremote_object.h"
25 #include <vector>
26
27 namespace OHOS {
28 namespace AppExecFwk {
29 const int32_t LIMIT_PARCEL_SIZE = 1024;
30 constexpr size_t MAX_PARCEL_CAPACITY = 4 * 1024 * 1024; // 4M
31
SplitString(const std::string & source,std::vector<std::string> & strings)32 void SplitString(const std::string &source, std::vector<std::string> &strings)
33 {
34 size_t splitSize = (source.size() / LIMIT_PARCEL_SIZE);
35 if ((source.size() % LIMIT_PARCEL_SIZE) != 0) {
36 splitSize++;
37 }
38 HILOG_DEBUG("the dump string split into %{public}zu size", splitSize);
39 for (size_t i = 0; i < splitSize; i++) {
40 size_t start = LIMIT_PARCEL_SIZE * i;
41 strings.emplace_back(source.substr(start, LIMIT_PARCEL_SIZE));
42 }
43 }
44
FormMgrStub()45 FormMgrStub::FormMgrStub()
46 {}
47
~FormMgrStub()48 FormMgrStub::~FormMgrStub()
49 {}
50
51 /**
52 * @brief handle remote request.
53 * @param code ipc code.
54 * @param data input param.
55 * @param reply output param.
56 * @param option message option.
57 * @return Returns ERR_OK on success, others on failure.
58 */
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)59 int FormMgrStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
60 {
61 HILOG_DEBUG("code= %{public}u,flags= %{public}d", code, option.GetFlags());
62 std::u16string descriptor = FormMgrStub::GetDescriptor();
63 std::u16string remoteDescriptor = data.ReadInterfaceToken();
64 if (descriptor != remoteDescriptor) {
65 HILOG_ERROR("remote not equal to localDescriptor");
66 return ERR_APPEXECFWK_FORM_INVALID_PARAM;
67 }
68
69 return OnRemoteRequestFirst(code, data, reply, option);
70 }
71
72 /**
73 * @brief the first part of handle remote request.
74 * @param code ipc code.
75 * @param data input param.
76 * @param reply output param.
77 * @param option message option.
78 * @return Returns ERR_OK on success, others on failure.
79 */
OnRemoteRequestFirst(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)80 int FormMgrStub::OnRemoteRequestFirst(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
81 {
82 switch (code) {
83 case static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_ADD_FORM):
84 return HandleAddForm(data, reply);
85 case static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_DELETE_FORM):
86 return HandleDeleteForm(data, reply);
87 case static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_RELEASE_FORM):
88 return HandleReleaseForm(data, reply);
89 case static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_UPDATE_FORM):
90 return HandleUpdateForm(data, reply);
91 case static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_REQUEST_FORM):
92 return HandleRequestForm(data, reply);
93 case static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_NOTIFY_FORM_WHETHER_VISIBLE):
94 return HandleNotifyWhetherVisibleForms(data, reply);
95 case static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_CAST_TEMP_FORM):
96 return HandleCastTempForm(data, reply);
97 case static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_STORAGE_FORM_INFOS):
98 return HandleDumpStorageFormInfos(data, reply);
99 case static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_FORM_INFOS_BY_NAME):
100 return HandleDumpFormInfoByBundleName(data, reply);
101 case static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_FORM_INFOS_BY_ID):
102 return HandleDumpFormInfoByFormId(data, reply);
103 case static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_FORM_TIMER_INFO_BY_ID):
104 return HandleDumpFormTimerByFormId(data, reply);
105 case static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_SET_NEXT_REFRESH_TIME):
106 return HandleSetNextRefreshTime(data, reply);
107 case static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_LIFECYCLE_UPDATE):
108 return HandleLifecycleUpdate(data, reply);
109 case static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_MESSAGE_EVENT):
110 return HandleMessageEvent(data, reply);
111 case static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_DELETE_INVALID_FORMS):
112 return HandleDeleteInvalidForms(data, reply);
113 case static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_ACQUIRE_FORM_STATE):
114 return HandleAcquireFormState(data, reply);
115 case static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_NOTIFY_FORMS_VISIBLE):
116 return HandleNotifyFormsVisible(data, reply);
117 case static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_NOTIFY_FORMS_PRIVACY_PROTECTED):
118 return HandleNotifyFormsPrivacyProtected(data, reply);
119 default:
120 return OnRemoteRequestSecond(code, data, reply, option);
121 }
122 }
123
124 /**
125 * @brief the second part of handle remote request.
126 * @param code ipc code.
127 * @param data input param.
128 * @param reply output param.
129 * @param option message option.
130 * @return Returns ERR_OK on success, others on failure.
131 */
OnRemoteRequestSecond(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)132 int FormMgrStub::OnRemoteRequestSecond(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
133 {
134 switch (code) {
135 case static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_NOTIFY_FORMS_ENABLE_UPDATE):
136 return HandleNotifyFormsEnableUpdate(data, reply);
137 case static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_GET_ALL_FORMS_INFO):
138 return HandleGetAllFormsInfo(data, reply);
139 case static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_GET_FORMS_INFO_BY_APP):
140 return HandleGetFormsInfoByApp(data, reply);
141 case static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_GET_FORMS_INFO_BY_MODULE):
142 return HandleGetFormsInfoByModule(data, reply);
143 case static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_GET_FORMS_INFO_BY_FILTER):
144 return HandleGetFormsInfoByFilter(data, reply);
145 case static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_GET_FORMS_INFO):
146 return HandleGetFormsInfo(data, reply);
147 case static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_ROUTER_EVENT):
148 return HandleRouterEvent(data, reply);
149 case static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_BACKGROUND_EVENT):
150 return HandleBackgroundEvent(data, reply);
151 case static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_REQUEST_PUBLISH_FORM):
152 return HandleRequestPublishForm(data, reply);
153 case static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_SHARE_FORM):
154 return HandleShareForm(data, reply);
155 case static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_RECV_FORM_SHARE_INFO_FROM_REMOTE):
156 return HandleRecvFormShareInfoFromRemote(data, reply);
157 case static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_IS_REQUEST_PUBLISH_FORM_SUPPORTED):
158 return HandleIsRequestPublishFormSupported(data, reply);
159 case static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_START_ABILITY):
160 return HandleStartAbility(data, reply);
161 case static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_CHECK_FMS_READY):
162 return HandleCheckFMSReady(data, reply);
163 case static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_STOP_RENDERING_FORM):
164 return HandleStopRenderingForm(data, reply);
165 case static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_REGISTER_FORM_ADD_OBSERVER_BY_BUNDLE):
166 return HandleRegisterFormAddObserverByBundle(data, reply);
167 case static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_REGISTER_FORM_REMOVE_OBSERVER_BY_BUNDLE):
168 return HandleRegisterFormRemoveObserverByBundle(data, reply);
169 default:
170 return OnRemoteRequestThird(code, data, reply, option);
171 }
172 }
173
174 /**
175 * @brief the third part of handle remote request.
176 * @param code ipc code.
177 * @param data input param.
178 * @param reply output param.
179 * @param option message option.
180 * @return Returns ERR_OK on success, others on failure.
181 */
OnRemoteRequestThird(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)182 int FormMgrStub::OnRemoteRequestThird(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
183 {
184 switch (code) {
185 case static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_ACQUIRE_DATA):
186 return HandleAcquireFormData(data, reply);
187 case static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_GET_FORMS_COUNT):
188 return HandleGetFormsCount(data, reply);
189 case static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_GET_HOST_FORMS_COUNT):
190 return HandleGetHostFormsCount(data, reply);
191 case static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_GET_RUNNING_FORM_INFOS):
192 return HandleGetRunningFormInfos(data, reply);
193 case static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_GET_RUNNING_FORM_INFOS_BY_BUNDLE):
194 return HandleGetRunningFormInfosByBundleName(data, reply);
195 case static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_GET_FORM_INSTANCES_FROM_BY_FILTER):
196 return HandleGetFormInstancesByFilter(data, reply);
197 case static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_GET_FORM_INSTANCES_FROM_BY_ID):
198 return HandleGetFormInstanceById(data, reply);
199 case static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_REGISTER_ADD_OBSERVER):
200 return HandleRegisterAddObserver(data, reply);
201 case static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_REGISTER_REMOVE_OBSERVER):
202 return HandleRegisterRemoveObserver(data, reply);
203 case static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_UPDATE_PROXY_FORM):
204 return HandleUpdateProxyForm(data, reply);
205 case static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_REQUEST_PUBLISH_PROXY_FORM):
206 return HandleRequestPublishProxyForm(data, reply);
207 case static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_RELEASE_RENDERER):
208 return HandleReleaseRenderer(data, reply);
209 case static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_REGISTER_PUBLISH_FORM_INTERCEPTOR):
210 return HandleRegisterPublishFormInterceptor(data, reply);
211 case static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_UNREGISTER_PUBLISH_FORM_INTERCEPTOR):
212 return HandleUnregisterPublishFormInterceptor(data, reply);
213 case static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_REGISTER_CLICK_EVENT_OBSERVER):
214 return HandleRegisterClickCallbackEventObserver(data, reply);
215 default:
216 return OnRemoteRequestFourth(code, data, reply, option);
217 }
218 }
219
220 /**
221 * @brief the fourth part of handle remote request.
222 * @param code ipc code.
223 * @param data input param.
224 * @param reply output param.
225 * @param option message option.
226 * @return Returns ERR_OK on success, others on failure.
227 */
OnRemoteRequestFourth(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)228 int FormMgrStub::OnRemoteRequestFourth(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
229 {
230 switch (code) {
231 case static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_UNREGISTER_CLICK_EVENT_OBSERVER):
232 return HandleUnregisterClickCallbackEventObserver(data, reply);
233 case static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_REGISTER_FORM_ROUTER_PROXY):
234 return HandleRegisterFormRouterProxy(data, reply);
235 case static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_UNREGISTER_FORM_ROUTER_PROXY):
236 return HandleUnregisterFormRouterProxy(data, reply);
237 case static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_SET_FORMS_RECYCLABLE):
238 return HandleSetFormsRecyclable(data, reply);
239 case static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_RECYCLE_FORMS):
240 return HandleRecycleForms(data, reply);
241 case static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_RECOVER_FORMS):
242 return HandleRecoverForms(data, reply);
243 case static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_HAS_FORM_VISIBLE_WITH_TOKENID):
244 return HandleHasFormVisible(data, reply);
245 case static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_UPDATE_FORM_LOCATION):
246 return HandleUpdateFormLocation(data, reply);
247 case static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_PUBLISH_FORM_ERRCODE_RESULT):
248 return HandleSetPublishFormResult(data, reply);
249 case static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_ACQUIRE_ADD_FORM_RESULT):
250 return HandleAcquireAddFormResult(data, reply);
251 case static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_CREATE_FORM):
252 return HandleCreateForm(data, reply);
253 case static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_REQUEST_PUBLISH_FORM_WITH_SNAPSHOT):
254 return HandleRequestPublishFormWithSnapshot(data, reply);
255 case static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_BATCH_REFRESH_FORMS):
256 return HandleBatchRefreshForms(data, reply);
257 case static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_ENABLE_FORMS):
258 return HandleEnableForms(data, reply);
259 case static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_IS_SYSTEM_APP_FORM):
260 return HandleIsSystemAppForm(data, reply);
261 case static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_IS_FORM_BUNDLE_FORBIDDEN):
262 return HandleIsFormBundleForbidden(data, reply);
263 default:
264 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
265 }
266 }
267
268 /**
269 * @brief handle AddForm message.
270 * @param data input param.
271 * @param reply output param.
272 * @return Returns ERR_OK on success, others on failure.
273 */
HandleAddForm(MessageParcel & data,MessageParcel & reply)274 int32_t FormMgrStub::HandleAddForm(MessageParcel &data, MessageParcel &reply)
275 {
276 int64_t formId = data.ReadInt64();
277 std::unique_ptr<Want> want(data.ReadParcelable<Want>());
278 if (!want) {
279 HILOG_ERROR("fail ReadParcelable<FormReqInfo>");
280 return ERR_APPEXECFWK_PARCEL_ERROR;
281 }
282
283 sptr<IRemoteObject> client = data.ReadRemoteObject();
284 if (client == nullptr) {
285 HILOG_ERROR("RemoteObject invalidate");
286 return ERR_APPEXECFWK_PARCEL_ERROR;
287 }
288
289 FormJsInfo formJsInfo;
290 int32_t result = AddForm(formId, *want, client, formJsInfo);
291 reply.WriteInt32(result);
292 reply.WriteParcelable(&formJsInfo);
293
294 return result;
295 }
296
297 /**
298 * @brief handle CreateForm message.
299 * @param data input param.
300 * @param reply output param.
301 * @return Returns ERR_OK on success, others on failure.
302 */
HandleCreateForm(MessageParcel & data,MessageParcel & reply)303 int32_t FormMgrStub::HandleCreateForm(MessageParcel &data, MessageParcel &reply)
304 {
305 std::unique_ptr<Want> want(data.ReadParcelable<Want>());
306 if (!want) {
307 HILOG_ERROR("fail ReadParcelable");
308 return ERR_APPEXECFWK_PARCEL_ERROR;
309 }
310
311 RunningFormInfo runningFormInfo;
312 int32_t result = CreateForm(*want, runningFormInfo);
313 reply.WriteInt32(result);
314 reply.WriteParcelable(&runningFormInfo);
315 return result;
316 }
317
318 /**
319 * @brief handle DeleteForm message.
320 * @param data input param.
321 * @param reply output param.
322 * @return Returns ERR_OK on success, others on failure.
323 */
HandleDeleteForm(MessageParcel & data,MessageParcel & reply)324 int32_t FormMgrStub::HandleDeleteForm(MessageParcel &data, MessageParcel &reply)
325 {
326 int64_t formId = data.ReadInt64();
327 sptr<IRemoteObject> client = data.ReadRemoteObject();
328 if (client == nullptr) {
329 return ERR_APPEXECFWK_PARCEL_ERROR;
330 }
331 int32_t result = DeleteForm(formId, client);
332 reply.WriteInt32(result);
333 return result;
334 }
335 /**
336 * @brief handle DeleteFormByCompId message.
337 * @param data input param.
338 * @param reply output param.
339 * @return Returns ERR_OK on success, others on failure.
340 */
HandleStopRenderingForm(MessageParcel & data,MessageParcel & reply)341 int32_t FormMgrStub::HandleStopRenderingForm(MessageParcel &data, MessageParcel &reply)
342 {
343 int64_t formId = data.ReadInt64();
344 std::string compId = data.ReadString();
345 int32_t result = StopRenderingForm(formId, compId);
346 reply.WriteInt32(result);
347 return result;
348 }
349 /**
350 * @brief handle ReleaseForm message.
351 * @param data input param.
352 * @param reply output param.
353 * @return Returns ERR_OK on success, others on failure.
354 */
HandleReleaseForm(MessageParcel & data,MessageParcel & reply)355 int32_t FormMgrStub::HandleReleaseForm(MessageParcel &data, MessageParcel &reply)
356 {
357 int64_t formId = data.ReadInt64();
358 sptr<IRemoteObject> client = data.ReadRemoteObject();
359 if (client == nullptr) {
360 return ERR_APPEXECFWK_PARCEL_ERROR;
361 }
362 bool delCache = data.ReadBool();
363
364 int32_t result = ReleaseForm(formId, client, delCache);
365 reply.WriteInt32(result);
366 return result;
367 }
368 /**
369 * @brief handle UpdateForm message.
370 * @param data input param.
371 * @param reply output param.
372 * @return Returns ERR_OK on success, others on failure.
373 */
HandleUpdateForm(MessageParcel & data,MessageParcel & reply)374 int32_t FormMgrStub::HandleUpdateForm(MessageParcel &data, MessageParcel &reply)
375 {
376 int64_t formId = data.ReadInt64();
377 std::unique_ptr<FormProviderData> formBindingData(data.ReadParcelable<FormProviderData>());
378 if (formBindingData == nullptr) {
379 HILOG_ERROR("fail get formBindingData");
380 return ERR_APPEXECFWK_PARCEL_ERROR;
381 }
382 int32_t result = UpdateForm(formId, *formBindingData);
383 reply.WriteInt32(result);
384 return result;
385 }
386 /**
387 * @brief handle SetNextRefreshTime message.
388 * @param data input param.
389 * @param reply output param.
390 * @return Returns ERR_OK on success, others on failure.
391 */
HandleSetNextRefreshTime(MessageParcel & data,MessageParcel & reply)392 int32_t FormMgrStub::HandleSetNextRefreshTime(MessageParcel &data, MessageParcel &reply)
393 {
394 int64_t formId = data.ReadInt64();
395 int64_t nextTime = data.ReadInt64();
396 int32_t result = SetNextRefreshTime(formId, nextTime);
397 reply.WriteInt32(result);
398 return result;
399 }
400
401 /**
402 * @brief handle ReleaseRenderer message.
403 * @param data input param.
404 * @param reply output param.
405 * @return Returns ERR_OK on success, others on failure.
406 */
HandleReleaseRenderer(MessageParcel & data,MessageParcel & reply)407 int32_t FormMgrStub::HandleReleaseRenderer(MessageParcel &data, MessageParcel &reply)
408 {
409 int64_t formId = data.ReadInt64();
410 std::string compId = data.ReadString();
411 int32_t result = ReleaseRenderer(formId, compId);
412 reply.WriteInt32(result);
413 return result;
414 }
415
416 /**
417 * @brief handle RequestPublishForm message.
418 * @param data input param.
419 * @param reply output param.
420 * @return Returns ERR_OK on success, others on failure.
421 */
HandleRequestPublishForm(MessageParcel & data,MessageParcel & reply)422 ErrCode FormMgrStub::HandleRequestPublishForm(MessageParcel &data, MessageParcel &reply)
423 {
424 std::unique_ptr<Want> want(data.ReadParcelable<Want>());
425 if (want == nullptr) {
426 HILOG_ERROR("get want failed");
427 return ERR_APPEXECFWK_PARCEL_ERROR;
428 }
429
430 bool withFormBindingData = data.ReadBool();
431 std::unique_ptr<FormProviderData> formProviderData = nullptr;
432 if (withFormBindingData) {
433 formProviderData.reset(data.ReadParcelable<FormProviderData>());
434 if (formProviderData == nullptr) {
435 HILOG_ERROR("get formProviderData failed");
436 return ERR_APPEXECFWK_PARCEL_ERROR;
437 }
438 }
439 int64_t formId = 0;
440 ErrCode result = RequestPublishForm(*want, withFormBindingData, formProviderData, formId);
441 reply.WriteInt32(result);
442 if (result == ERR_OK) {
443 reply.WriteInt64(formId);
444 }
445 return result;
446 }
447
HandleSetPublishFormResult(MessageParcel & data,MessageParcel & reply)448 ErrCode FormMgrStub::HandleSetPublishFormResult(MessageParcel &data, MessageParcel &reply)
449 {
450 int64_t formId = data.ReadInt64();
451 Constants::PublishFormResult errorCodeInfo;
452 errorCodeInfo.message = data.ReadString();
453 int32_t err = data.ReadInt32();
454 errorCodeInfo.code = (Constants::PublishFormErrorCode)(err) ;
455 ErrCode result = SetPublishFormResult(formId, errorCodeInfo);
456 reply.WriteInt32(result);
457 return result;
458 }
459
HandleAcquireAddFormResult(MessageParcel & data,MessageParcel & reply)460 ErrCode FormMgrStub::HandleAcquireAddFormResult(MessageParcel &data, MessageParcel &reply)
461 {
462 int64_t formId = data.ReadInt64();
463 ErrCode result = AcquireAddFormResult(formId);
464 reply.WriteInt32(result);
465 return result;
466 }
467 /**
468 * @brief handle LifecycleUpdate message.
469 * @param data input param.
470 * @param reply output param.
471 * @return Returns ERR_OK on success, others on failure.
472 */
HandleLifecycleUpdate(MessageParcel & data,MessageParcel & reply)473 int32_t FormMgrStub::HandleLifecycleUpdate(MessageParcel &data, MessageParcel &reply)
474 {
475 std::vector<int64_t> formIds;
476 bool ret = data.ReadInt64Vector(&formIds);
477 if (!ret) {
478 return ERR_APPEXECFWK_PARCEL_ERROR;
479 }
480 sptr<IRemoteObject> client = data.ReadRemoteObject();
481 if (client == nullptr) {
482 HILOG_ERROR("get remote object failed");
483 return ERR_APPEXECFWK_PARCEL_ERROR;
484 }
485 bool updateType = data.ReadBool();
486 int32_t result = LifecycleUpdate(formIds, client, updateType);
487 reply.WriteInt32(result);
488 return result;
489 }
490 /**
491 * @brief handle RequestForm message.
492 * @param data input param.
493 * @param reply output param.
494 * @return Returns ERR_OK on success, others on failure.
495 */
HandleRequestForm(MessageParcel & data,MessageParcel & reply)496 int32_t FormMgrStub::HandleRequestForm(MessageParcel &data, MessageParcel &reply)
497 {
498 HILOG_INFO("call");
499
500 int64_t formId = data.ReadInt64();
501
502 sptr<IRemoteObject> client = data.ReadRemoteObject();
503 if (client == nullptr) {
504 HILOG_ERROR("get remote object failed");
505 return ERR_APPEXECFWK_PARCEL_ERROR;
506 }
507
508 std::unique_ptr<Want> want(data.ReadParcelable<Want>());
509 if (!want) {
510 HILOG_ERROR("ReadParcelable<Want> failed");
511 return ERR_APPEXECFWK_PARCEL_ERROR;
512 }
513
514 int32_t result = RequestForm(formId, client, *want);
515 reply.WriteInt32(result);
516 return result;
517 }
518 /**
519 * @brief handle NotifyVisibleForms message.
520 * @param data input param.
521 * @param reply output param.
522 * @return Returns ERR_OK on success, others on failure.
523 */
HandleNotifyWhetherVisibleForms(MessageParcel & data,MessageParcel & reply)524 int32_t FormMgrStub::HandleNotifyWhetherVisibleForms(MessageParcel &data, MessageParcel &reply)
525 {
526 std::vector<int64_t> formIds;
527 bool ret = data.ReadInt64Vector(&formIds);
528 if (!ret) {
529 return ERR_APPEXECFWK_PARCEL_ERROR;
530 }
531
532 sptr<IRemoteObject> client = data.ReadRemoteObject();
533 if (client == nullptr) {
534 return ERR_APPEXECFWK_PARCEL_ERROR;
535 }
536 int32_t formVisibleType = data.ReadInt32();
537
538 int32_t result = NotifyWhetherVisibleForms(formIds, client, formVisibleType);
539 reply.WriteInt32(result);
540 return result;
541 }
542
543
544 /**
545 * @brief Handle HasFormVisible message.
546 * @param data input param.
547 * @param reply output param.
548 * @return Returns ERR_OK on success, others on failure.
549 */
HandleHasFormVisible(MessageParcel & data,MessageParcel & reply)550 int32_t FormMgrStub::HandleHasFormVisible(MessageParcel &data, MessageParcel &reply)
551 {
552 HILOG_DEBUG("call");
553 uint32_t tokenId = data.ReadUint32();
554 bool result = HasFormVisible(tokenId);
555 if (!reply.WriteBool(result)) {
556 HILOG_ERROR("write action failed");
557 return ERR_APPEXECFWK_PARCEL_ERROR;
558 }
559
560 return ERR_OK;
561 }
562
563 /**
564 * @brief handle CastTempForm message.
565 * @param data input param.
566 * @param reply output param.
567 * @return Returns ERR_OK on success, others on failure.
568 */
HandleCastTempForm(MessageParcel & data,MessageParcel & reply)569 int32_t FormMgrStub::HandleCastTempForm(MessageParcel &data, MessageParcel &reply)
570 {
571 int64_t formId = data.ReadInt64();
572 sptr<IRemoteObject> client = data.ReadRemoteObject();
573 if (client == nullptr) {
574 return ERR_APPEXECFWK_PARCEL_ERROR;
575 }
576
577 int32_t result = CastTempForm(formId, client);
578 reply.WriteInt32(result);
579 return result;
580 }
581 /**
582 * @brief Handle DumpStorageFormInfos message.
583 * @param data input param.
584 * @param reply output param.
585 * @return Returns ERR_OK on success, others on failure.
586 */
HandleDumpStorageFormInfos(MessageParcel & data,MessageParcel & reply)587 int32_t FormMgrStub::HandleDumpStorageFormInfos(MessageParcel &data, MessageParcel &reply)
588 {
589 std::string formInfos;
590 int32_t result = DumpStorageFormInfos(formInfos);
591 reply.WriteInt32(result);
592 if (result == ERR_OK) {
593 std::vector<std::string> dumpInfos;
594 SplitString(formInfos, dumpInfos);
595 if (!reply.WriteStringVector(dumpInfos)) {
596 HILOG_ERROR("WriteStringVector<dumpInfos> failed");
597 return ERR_APPEXECFWK_PARCEL_ERROR;
598 }
599 }
600
601 return result;
602 }
603 /**
604 * @brief Handle DumpFormInfoByBundleName message.
605 * @param data input param.
606 * @param reply output param.
607 * @return Returns ERR_OK on success, others on failure.
608 */
HandleDumpFormInfoByBundleName(MessageParcel & data,MessageParcel & reply)609 int32_t FormMgrStub::HandleDumpFormInfoByBundleName(MessageParcel &data, MessageParcel &reply)
610 {
611 std::string bundleName = data.ReadString();
612 std::string formInfos;
613 int32_t result = DumpFormInfoByBundleName(bundleName, formInfos);
614 reply.WriteInt32(result);
615 if (result == ERR_OK) {
616 HILOG_DEBUG("formInfos:%{public}s", formInfos.c_str());
617 std::vector<std::string> dumpInfos;
618 SplitString(formInfos, dumpInfos);
619 if (!reply.WriteStringVector(dumpInfos)) {
620 HILOG_ERROR("WriteStringVector<dumpInfos> failed");
621 return ERR_APPEXECFWK_PARCEL_ERROR;
622 }
623 }
624
625 return result;
626 }
627 /**
628 * @brief Handle DumpFormInfoByFormId message.
629 * @param data input param.
630 * @param reply output param.
631 * @return Returns ERR_OK on success, others on failure.
632 */
HandleDumpFormInfoByFormId(MessageParcel & data,MessageParcel & reply)633 int32_t FormMgrStub::HandleDumpFormInfoByFormId(MessageParcel &data, MessageParcel &reply)
634 {
635 int64_t formId = data.ReadInt64();
636 std::string formInfo;
637 int32_t result = DumpFormInfoByFormId(formId, formInfo);
638 reply.WriteInt32(result);
639 if (result == ERR_OK) {
640 std::vector<std::string> dumpInfos;
641 SplitString(formInfo, dumpInfos);
642 if (!reply.WriteStringVector(dumpInfos)) {
643 HILOG_ERROR("WriteStringVector<dumpInfos> failed");
644 return ERR_APPEXECFWK_PARCEL_ERROR;
645 }
646 }
647 return result;
648 }
649 /**
650 * @brief Handle DumpFormTimerByFormId message.
651 * @param data input param.
652 * @param reply output param.
653 * @return Returns ERR_OK on success, others on failure.
654 */
HandleDumpFormTimerByFormId(MessageParcel & data,MessageParcel & reply)655 int32_t FormMgrStub::HandleDumpFormTimerByFormId(MessageParcel &data, MessageParcel &reply)
656 {
657 int64_t formId = data.ReadInt64();
658 std::string isTimingService;
659 int32_t result = DumpFormTimerByFormId(formId, isTimingService);
660 reply.WriteInt32(result);
661 if (result == ERR_OK) {
662 std::vector<std::string> dumpInfos;
663 SplitString(isTimingService, dumpInfos);
664 if (!reply.WriteStringVector(dumpInfos)) {
665 HILOG_ERROR("WriteStringVector<dumpInfos> failed");
666 return ERR_APPEXECFWK_PARCEL_ERROR;
667 }
668 }
669 return result;
670 }
671
672 /**
673 * @brief Handle DumpFormInfoByFormId message.
674 * @param data input param.
675 * @param reply output param.
676 * @return Returns ERR_OK on success, others on failure.
677 */
HandleMessageEvent(MessageParcel & data,MessageParcel & reply)678 int32_t FormMgrStub::HandleMessageEvent(MessageParcel &data, MessageParcel &reply)
679 {
680 HILOG_INFO("call");
681 int64_t formId = data.ReadInt64();
682 std::unique_ptr<Want> want(data.ReadParcelable<Want>());
683 if (!want) {
684 HILOG_ERROR("ReadParcelable<Want> failed");
685 return ERR_APPEXECFWK_PARCEL_ERROR;
686 }
687
688 sptr<IRemoteObject> client = data.ReadRemoteObject();
689 if (client == nullptr) {
690 HILOG_ERROR("get remote object failed");
691 return ERR_APPEXECFWK_PARCEL_ERROR;
692 }
693
694 int32_t result = MessageEvent(formId, *want, client);
695 reply.WriteInt32(result);
696 return result;
697 }
698
699 /**
700 * @brief Handle RouterEvent message.
701 * @param data input param.
702 * @param reply output param.
703 * @return Returns ERR_OK on success, others on failure.
704 */
HandleRouterEvent(MessageParcel & data,MessageParcel & reply)705 int32_t FormMgrStub::HandleRouterEvent(MessageParcel &data, MessageParcel &reply)
706 {
707 HILOG_INFO("call");
708 int64_t formId = data.ReadInt64();
709 std::unique_ptr<Want> want(data.ReadParcelable<Want>());
710 if (!want) {
711 HILOG_ERROR("ReadParcelable<Want> failed");
712 return ERR_APPEXECFWK_PARCEL_ERROR;
713 }
714 sptr<IRemoteObject> client = data.ReadRemoteObject();
715 if (client == nullptr) {
716 HILOG_ERROR("get remote object failed");
717 return ERR_APPEXECFWK_PARCEL_ERROR;
718 }
719
720 int32_t result = RouterEvent(formId, *want, client);
721 reply.WriteInt32(result);
722 return result;
723 }
724
725 /**
726 * @brief Handle Background message.
727 * @param data input param.
728 * @param reply output param.
729 * @return Returns ERR_OK on success, others on failure.
730 */
HandleBackgroundEvent(MessageParcel & data,MessageParcel & reply)731 int32_t FormMgrStub::HandleBackgroundEvent(MessageParcel &data, MessageParcel &reply)
732 {
733 HILOG_INFO("call");
734 int64_t formId = data.ReadInt64();
735 std::unique_ptr<Want> want(data.ReadParcelable<Want>());
736 if (!want) {
737 HILOG_ERROR("ReadParcelable<Want> failed");
738 return ERR_APPEXECFWK_PARCEL_ERROR;
739 }
740 sptr<IRemoteObject> client = data.ReadRemoteObject();
741 if (client == nullptr) {
742 HILOG_ERROR("get remote object failed");
743 return ERR_APPEXECFWK_PARCEL_ERROR;
744 }
745
746 int32_t result = BackgroundEvent(formId, *want, client);
747 reply.WriteInt32(result);
748 return result;
749 }
750
751 /**
752 * @brief Handle DeleteInvalidForms message.
753 * @param data input param.
754 * @param reply output param.
755 * @return Returns ERR_OK on success, others on failure.
756 */
HandleDeleteInvalidForms(MessageParcel & data,MessageParcel & reply)757 int32_t FormMgrStub::HandleDeleteInvalidForms(MessageParcel &data, MessageParcel &reply)
758 {
759 HILOG_INFO("call");
760 std::vector<int64_t> formIds;
761 if (!data.ReadInt64Vector(&formIds)) {
762 HILOG_ERROR("ReadInt64Vector failed");
763 return ERR_APPEXECFWK_PARCEL_ERROR;
764 }
765 sptr<IRemoteObject> callerToken = data.ReadRemoteObject();
766 if (callerToken == nullptr) {
767 HILOG_ERROR("get remote object failed");
768 return ERR_APPEXECFWK_PARCEL_ERROR;
769 }
770 int32_t numFormsDeleted = 0;
771 int32_t result = DeleteInvalidForms(formIds, callerToken, numFormsDeleted);
772 if (!reply.WriteInt32(result)) {
773 HILOG_ERROR("write result failed");
774 return ERR_APPEXECFWK_PARCEL_ERROR;
775 }
776 if (!reply.WriteInt32(numFormsDeleted)) {
777 HILOG_ERROR("fail write numFormsDeleted");
778 return ERR_APPEXECFWK_PARCEL_ERROR;
779 }
780 return result;
781 }
782
783 /**
784 * @brief Handle AcquireFormState message.
785 * @param data input param.
786 * @param reply output param.
787 * @return Returns ERR_OK on success, others on failure.
788 */
HandleAcquireFormState(MessageParcel & data,MessageParcel & reply)789 int32_t FormMgrStub::HandleAcquireFormState(MessageParcel &data, MessageParcel &reply)
790 {
791 HILOG_INFO("call");
792 FormStateInfo stateInfo {};
793 std::unique_ptr<Want> want(data.ReadParcelable<Want>());
794 if (want == nullptr) {
795 HILOG_ERROR("ReadParcelable want failed");
796 return ERR_APPEXECFWK_PARCEL_ERROR;
797 }
798 sptr<IRemoteObject> callerToken = data.ReadRemoteObject();
799 if (callerToken == nullptr) {
800 HILOG_ERROR("get remote object failed");
801 return ERR_APPEXECFWK_PARCEL_ERROR;
802 }
803 int32_t result = AcquireFormState(*want, callerToken, stateInfo);
804 if (!reply.WriteInt32(result)) {
805 HILOG_ERROR("write result failed");
806 return ERR_APPEXECFWK_PARCEL_ERROR;
807 }
808 if (!reply.WriteInt32((int32_t)stateInfo.state)) {
809 HILOG_ERROR("write state failed");
810 return ERR_APPEXECFWK_PARCEL_ERROR;
811 }
812 return result;
813 }
814
815 /**
816 * @brief Handle NotifyFormsVisible message.
817 * @param data input param.
818 * @param reply output param.
819 * @return Returns ERR_OK on success, others on failure.
820 */
HandleNotifyFormsVisible(MessageParcel & data,MessageParcel & reply)821 int32_t FormMgrStub::HandleNotifyFormsVisible(MessageParcel &data, MessageParcel &reply)
822 {
823 HILOG_INFO("call");
824 std::vector<int64_t> formIds;
825 if (!data.ReadInt64Vector(&formIds)) {
826 HILOG_ERROR("ReadInt64Vector failed");
827 return ERR_APPEXECFWK_PARCEL_ERROR;
828 }
829 bool isVisible = false;
830 if (!data.ReadBool(isVisible)) {
831 HILOG_ERROR("ReadBool failed");
832 return ERR_APPEXECFWK_PARCEL_ERROR;
833 }
834 sptr<IRemoteObject> callerToken = data.ReadRemoteObject();
835 if (callerToken == nullptr) {
836 HILOG_ERROR("get remote object failed");
837 return ERR_APPEXECFWK_PARCEL_ERROR;
838 }
839
840 int32_t result = NotifyFormsVisible(formIds, isVisible, callerToken);
841 if (!reply.WriteInt32(result)) {
842 HILOG_ERROR("write result failed");
843 return ERR_APPEXECFWK_PARCEL_ERROR;
844 }
845 return result;
846 }
847
HandleNotifyFormsPrivacyProtected(MessageParcel & data,MessageParcel & reply)848 int32_t FormMgrStub::HandleNotifyFormsPrivacyProtected(MessageParcel &data, MessageParcel &reply)
849 {
850 HILOG_DEBUG("call");
851 std::vector<int64_t> formIds;
852 if (!data.ReadInt64Vector(&formIds)) {
853 HILOG_ERROR("ReadInt64Vector failed");
854 return ERR_APPEXECFWK_PARCEL_ERROR;
855 }
856 bool isProtected = false;
857 if (!data.ReadBool(isProtected)) {
858 HILOG_ERROR("ReadBool failed");
859 return ERR_APPEXECFWK_PARCEL_ERROR;
860 }
861 sptr<IRemoteObject> callerToken = data.ReadRemoteObject();
862 if (callerToken == nullptr) {
863 HILOG_ERROR("get remote object failed");
864 return ERR_APPEXECFWK_PARCEL_ERROR;
865 }
866
867 int32_t result = NotifyFormsPrivacyProtected(formIds, isProtected, callerToken);
868 if (!reply.WriteInt32(result)) {
869 HILOG_ERROR("write result failed");
870 return ERR_APPEXECFWK_PARCEL_ERROR;
871 }
872 return result;
873 }
874
875 /**
876 * @brief Handle NotifyFormsEnableUpdate message.
877 * @param data input param.
878 * @param reply output param.
879 * @return Returns ERR_OK on success, others on failure.
880 */
HandleNotifyFormsEnableUpdate(MessageParcel & data,MessageParcel & reply)881 int32_t FormMgrStub::HandleNotifyFormsEnableUpdate(MessageParcel &data, MessageParcel &reply)
882 {
883 HILOG_INFO("call");
884 std::vector<int64_t> formIds;
885 if (!data.ReadInt64Vector(&formIds)) {
886 HILOG_ERROR("ReadInt64Vector failed");
887 return ERR_APPEXECFWK_PARCEL_ERROR;
888 }
889 bool isEnableUpdate = false;
890 if (!data.ReadBool(isEnableUpdate)) {
891 HILOG_ERROR("ReadBool failed");
892 return ERR_APPEXECFWK_PARCEL_ERROR;
893 }
894 sptr<IRemoteObject> callerToken = data.ReadRemoteObject();
895 if (callerToken == nullptr) {
896 HILOG_ERROR("get remote object failed");
897 return ERR_APPEXECFWK_PARCEL_ERROR;
898 }
899
900 int32_t result = NotifyFormsEnableUpdate(formIds, isEnableUpdate, callerToken);
901 if (!reply.WriteInt32(result)) {
902 HILOG_ERROR("write result failed");
903 return ERR_APPEXECFWK_PARCEL_ERROR;
904 }
905 return result;
906 }
907
908 /**
909 * @brief Handle GetAllFormsInfo message.
910 * @param data input param.
911 * @param reply output param.
912 * @return Returns ERR_OK on success, others on failure.
913 */
HandleGetAllFormsInfo(MessageParcel & data,MessageParcel & reply)914 int32_t FormMgrStub::HandleGetAllFormsInfo(MessageParcel &data, MessageParcel &reply)
915 {
916 HILOG_INFO("max parcel capacity:%{public}zu", MAX_PARCEL_CAPACITY);
917 std::vector<FormInfo> infos;
918 int32_t result = GetAllFormsInfo(infos);
919 (void)reply.SetMaxCapacity(MAX_PARCEL_CAPACITY);
920 reply.WriteInt32(result);
921 if (result == ERR_OK) {
922 if (!WriteParcelableVector(infos, reply)) {
923 HILOG_ERROR("write failed");
924 return ERR_APPEXECFWK_PARCEL_ERROR;
925 }
926 }
927 return result;
928 }
929
930 /**
931 * @brief Handle GetFormsInfoByApp message.
932 * @param data input param.
933 * @param reply output param.
934 * @return Returns ERR_OK on success, others on failure.
935 */
HandleGetFormsInfoByApp(MessageParcel & data,MessageParcel & reply)936 int32_t FormMgrStub::HandleGetFormsInfoByApp(MessageParcel &data, MessageParcel &reply)
937 {
938 HILOG_DEBUG("call");
939 std::string bundleName = data.ReadString();
940 std::vector<FormInfo> infos;
941 int32_t result = GetFormsInfoByApp(bundleName, infos);
942 reply.WriteInt32(result);
943 if (result == ERR_OK) {
944 if (!WriteParcelableVector(infos, reply)) {
945 HILOG_ERROR("write failed");
946 return ERR_APPEXECFWK_PARCEL_ERROR;
947 }
948 }
949 return result;
950 }
951
952 /**
953 * @brief Handle GetFormsInfoByModule message.
954 * @param data input param.
955 * @param reply output param.
956 * @return Returns ERR_OK on success, others on failure.
957 */
HandleGetFormsInfoByModule(MessageParcel & data,MessageParcel & reply)958 int32_t FormMgrStub::HandleGetFormsInfoByModule(MessageParcel &data, MessageParcel &reply)
959 {
960 HILOG_DEBUG("call");
961 std::string bundleName = data.ReadString();
962 std::string moduleName = data.ReadString();
963 std::vector<FormInfo> infos;
964 int32_t result = GetFormsInfoByModule(bundleName, moduleName, infos);
965 reply.WriteInt32(result);
966 if (result == ERR_OK) {
967 if (!WriteParcelableVector(infos, reply)) {
968 HILOG_ERROR("write failed");
969 return ERR_APPEXECFWK_PARCEL_ERROR;
970 }
971 }
972 return result;
973 }
974
HandleGetFormsInfoByFilter(MessageParcel & data,MessageParcel & reply)975 int32_t FormMgrStub::HandleGetFormsInfoByFilter(MessageParcel &data, MessageParcel &reply)
976 {
977 HILOG_DEBUG("call");
978 FormInfoFilter filter;
979 filter.bundleName = data.ReadString();
980 filter.moduleName = data.ReadString();
981 data.ReadInt32Vector(&filter.supportDimensions);
982 data.ReadInt32Vector(&filter.supportShapes);
983
984 std::vector<FormInfo> infos;
985 int32_t result = GetFormsInfoByFilter(filter, infos);
986 reply.WriteInt32(result);
987 if (result == ERR_OK && !WriteParcelableVector(infos, reply)) {
988 HILOG_ERROR("write failed");
989 return ERR_APPEXECFWK_PARCEL_ERROR;
990 }
991 return result;
992 }
993
HandleGetFormsInfo(MessageParcel & data,MessageParcel & reply)994 int32_t FormMgrStub::HandleGetFormsInfo(MessageParcel &data, MessageParcel &reply)
995 {
996 HILOG_INFO("call");
997 // read filter from data.
998 std::unique_ptr<FormInfoFilter> filter(data.ReadParcelable<FormInfoFilter>());
999 if (filter == nullptr) {
1000 HILOG_ERROR("fail get filter");
1001 return ERR_APPEXECFWK_PARCEL_ERROR;
1002 }
1003 // write result of calling FMS into reply.
1004 std::vector<FormInfo> infos;
1005 // call FormMgrService to get formInfos into infos.
1006 int32_t result = GetFormsInfo(*filter, infos);
1007 reply.WriteBool(result);
1008 if (result == ERR_OK) {
1009 // write fetched formInfos into reply.
1010 if (!WriteParcelableVector(infos, reply)) {
1011 HILOG_ERROR("write failed");
1012 return ERR_APPEXECFWK_PARCEL_ERROR;
1013 }
1014 }
1015 return result;
1016 }
1017
HandleShareForm(MessageParcel & data,MessageParcel & reply)1018 int32_t FormMgrStub::HandleShareForm(MessageParcel &data, MessageParcel &reply)
1019 {
1020 HILOG_DEBUG("call");
1021 int64_t formId = data.ReadInt64();
1022 std::string deviceId = data.ReadString();
1023 sptr<IRemoteObject> callerToken = data.ReadRemoteObject();
1024 if (callerToken == nullptr) {
1025 HILOG_ERROR("get remote object failed");
1026 return ERR_APPEXECFWK_PARCEL_ERROR;
1027 }
1028 int64_t requestCode = data.ReadInt64();
1029
1030 auto result = ShareForm(formId, deviceId, callerToken, requestCode);
1031 reply.WriteInt32(result);
1032 return result;
1033 }
1034
HandleAcquireFormData(MessageParcel & data,MessageParcel & reply)1035 int32_t FormMgrStub::HandleAcquireFormData(MessageParcel &data, MessageParcel &reply)
1036 {
1037 HILOG_INFO("call");
1038 int64_t formId = data.ReadInt64();
1039 int64_t requestCode = data.ReadInt64();
1040 sptr<IRemoteObject> callerToken = data.ReadRemoteObject();
1041 if (callerToken == nullptr) {
1042 HILOG_ERROR("get remoteObject failed");
1043 return ERR_APPEXECFWK_PARCEL_ERROR;
1044 }
1045 // write result of calling FMS into reply.
1046 AAFwk::WantParams customizeData;
1047 // call FormMgrService to get formData into data.
1048 int32_t result = AcquireFormData(formId, requestCode, callerToken, customizeData);
1049 reply.WriteInt32(result);
1050 reply.WriteParcelable(&customizeData);
1051 return result;
1052 }
1053
HandleRecvFormShareInfoFromRemote(MessageParcel & data,MessageParcel & reply)1054 int32_t FormMgrStub::HandleRecvFormShareInfoFromRemote(MessageParcel &data, MessageParcel &reply)
1055 {
1056 HILOG_DEBUG("call");
1057 std::unique_ptr<FormShareInfo> info(data.ReadParcelable<FormShareInfo>());
1058 if (!info) {
1059 HILOG_ERROR("fail ReadParcelable<FormShareInfo>");
1060 return ERR_APPEXECFWK_PARCEL_ERROR;
1061 }
1062 auto result = RecvFormShareInfoFromRemote(*info);
1063 reply.WriteInt32(result);
1064 return result;
1065 }
1066
HandleIsRequestPublishFormSupported(MessageParcel & data,MessageParcel & reply)1067 int32_t FormMgrStub::HandleIsRequestPublishFormSupported(MessageParcel &data, MessageParcel &reply)
1068 {
1069 HILOG_INFO("call");
1070 bool result = IsRequestPublishFormSupported();
1071 if (!reply.WriteBool(result)) {
1072 HILOG_ERROR("write action failed");
1073 return ERR_APPEXECFWK_PARCEL_ERROR;
1074 }
1075 return ERR_OK;
1076 }
1077
HandleStartAbility(MessageParcel & data,MessageParcel & reply)1078 int32_t FormMgrStub::HandleStartAbility(MessageParcel &data, MessageParcel &reply)
1079 {
1080 HILOG_INFO("call");
1081 // retrieve want
1082 std::unique_ptr<Want> want(data.ReadParcelable<Want>());
1083 if (want == nullptr) {
1084 HILOG_ERROR("get want failed");
1085 return ERR_APPEXECFWK_PARCEL_ERROR;
1086 }
1087 // retrieve callerToken
1088 sptr<IRemoteObject> callerToken = data.ReadRemoteObject();
1089 if (callerToken == nullptr) {
1090 HILOG_ERROR("get remote object failed");
1091 return ERR_APPEXECFWK_PARCEL_ERROR;
1092 }
1093 int32_t result = StartAbility(*want, callerToken);
1094 if (!reply.WriteInt32(result)) {
1095 HILOG_ERROR("write result failed");
1096 return ERR_APPEXECFWK_PARCEL_ERROR;
1097 }
1098 return result;
1099 }
1100
HandleCheckFMSReady(MessageParcel & data,MessageParcel & reply)1101 int32_t FormMgrStub::HandleCheckFMSReady(MessageParcel &data, MessageParcel &reply)
1102 {
1103 HILOG_DEBUG("call");
1104 bool result = CheckFMSReady();
1105 if (!reply.WriteBool(result)) {
1106 HILOG_ERROR("write action failed");
1107 return ERR_APPEXECFWK_PARCEL_ERROR;
1108 }
1109 return ERR_OK;
1110 }
1111
HandleIsSystemAppForm(MessageParcel & data,MessageParcel & reply)1112 ErrCode FormMgrStub::HandleIsSystemAppForm(MessageParcel &data, MessageParcel &reply)
1113 {
1114 std::string bundleName = data.ReadString();
1115 bool result = IsSystemAppForm(bundleName);
1116 if (!reply.WriteBool(result)) {
1117 HILOG_ERROR("write result failed");
1118 return ERR_APPEXECFWK_PARCEL_ERROR;
1119 }
1120 return ERR_OK;
1121 }
1122
HandleRegisterFormAddObserverByBundle(MessageParcel & data,MessageParcel & reply)1123 int32_t FormMgrStub::HandleRegisterFormAddObserverByBundle(MessageParcel &data, MessageParcel &reply)
1124 {
1125 HILOG_DEBUG("call");
1126
1127 std::string bundleName = data.ReadString();
1128 sptr<IRemoteObject> callerToken = data.ReadRemoteObject();
1129 if (callerToken == nullptr) {
1130 HILOG_ERROR("get remoteObject failed");
1131 return ERR_APPEXECFWK_PARCEL_ERROR;
1132 }
1133 auto result = RegisterFormAddObserverByBundle(bundleName, callerToken);
1134 reply.WriteInt32(result);
1135 return result;
1136 }
1137
HandleRegisterFormRemoveObserverByBundle(MessageParcel & data,MessageParcel & reply)1138 int32_t FormMgrStub::HandleRegisterFormRemoveObserverByBundle(MessageParcel &data, MessageParcel &reply)
1139 {
1140 HILOG_DEBUG("call");
1141
1142 std::string bundleName = data.ReadString();
1143 sptr<IRemoteObject> callerToken = data.ReadRemoteObject();
1144 if (callerToken == nullptr) {
1145 HILOG_ERROR("get remoteObject failed");
1146 return ERR_APPEXECFWK_PARCEL_ERROR;
1147 }
1148 auto result = RegisterFormRemoveObserverByBundle(bundleName, callerToken);
1149 reply.WriteInt32(result);
1150 return result;
1151 }
1152
HandleGetFormsCount(MessageParcel & data,MessageParcel & reply)1153 int32_t FormMgrStub::HandleGetFormsCount(MessageParcel &data, MessageParcel &reply)
1154 {
1155 HILOG_INFO("call");
1156 bool isTempFormFlag = false;
1157 if (!data.ReadBool(isTempFormFlag)) {
1158 HILOG_ERROR("fail read temp flag");
1159 return ERR_APPEXECFWK_PARCEL_ERROR;
1160 }
1161
1162 int32_t formCount = 0;
1163 int32_t result = GetFormsCount(isTempFormFlag, formCount);
1164 if (!reply.WriteInt32(result)) {
1165 HILOG_ERROR("write result failed");
1166 return ERR_APPEXECFWK_PARCEL_ERROR;
1167 }
1168 if (!reply.WriteInt32(formCount)) {
1169 HILOG_ERROR("write formCount failed");
1170 return ERR_APPEXECFWK_PARCEL_ERROR;
1171 }
1172 return result;
1173 }
1174
HandleGetFormInstancesByFilter(MessageParcel & data,MessageParcel & reply)1175 int32_t FormMgrStub::HandleGetFormInstancesByFilter(MessageParcel &data, MessageParcel &reply)
1176 {
1177 HILOG_DEBUG("call");
1178 std::unique_ptr<FormInstancesFilter> filter(data.ReadParcelable<FormInstancesFilter>());
1179 if (filter == nullptr) {
1180 HILOG_ERROR("fail get filter");
1181 return ERR_APPEXECFWK_PARCEL_ERROR;
1182 }
1183 std::vector<FormInstance> infos;
1184 auto result = GetFormInstancesByFilter(*filter, infos);
1185 HILOG_DEBUG("info size = %{public}zu", infos.size());
1186 reply.WriteInt32(result);
1187 if (result == ERR_OK) {
1188 HILOG_INFO("result is ok");
1189 if (!WriteParcelableVector(infos, reply)) {
1190 HILOG_ERROR("write failed");
1191 return ERR_APPEXECFWK_PARCEL_ERROR;
1192 }
1193 }
1194 return ERR_OK;
1195 }
1196
HandleGetFormInstanceById(MessageParcel & data,MessageParcel & reply)1197 int32_t FormMgrStub::HandleGetFormInstanceById(MessageParcel &data, MessageParcel &reply)
1198 {
1199 HILOG_DEBUG("call");
1200 int64_t formId = data.ReadInt64();
1201 bool isUnusedInclude = data.ReadBool();
1202 FormInstance info;
1203 auto result = GetFormInstanceById(formId, isUnusedInclude, info);
1204 reply.WriteInt32(result);
1205 if (result == ERR_OK) {
1206 if (!reply.WriteParcelable(&info)) {
1207 HILOG_ERROR("write failed");
1208 return ERR_APPEXECFWK_PARCEL_ERROR;
1209 }
1210 }
1211 return ERR_OK;
1212 }
1213
HandleGetHostFormsCount(MessageParcel & data,MessageParcel & reply)1214 int32_t FormMgrStub::HandleGetHostFormsCount(MessageParcel &data, MessageParcel &reply)
1215 {
1216 HILOG_INFO("call");
1217 std::string bundleName = data.ReadString();
1218
1219 int32_t formCount = 0;
1220 int32_t result = GetHostFormsCount(bundleName, formCount);
1221 if (!reply.WriteInt32(result)) {
1222 HILOG_ERROR("write result failed");
1223 return ERR_APPEXECFWK_PARCEL_ERROR;
1224 }
1225 if (!reply.WriteInt32(formCount)) {
1226 HILOG_ERROR("write formCount failed");
1227 return ERR_APPEXECFWK_PARCEL_ERROR;
1228 }
1229 return result;
1230 }
1231
HandleGetRunningFormInfos(MessageParcel & data,MessageParcel & reply)1232 ErrCode FormMgrStub::HandleGetRunningFormInfos(MessageParcel &data, MessageParcel &reply)
1233 {
1234 HILOG_DEBUG("call");
1235 bool isUnusedInclude = data.ReadBool();
1236 std::vector<RunningFormInfo> runningFormInfos;
1237 ErrCode result = GetRunningFormInfos(isUnusedInclude, runningFormInfos);
1238 reply.WriteInt32(result);
1239 if (result == ERR_OK) {
1240 if (!WriteParcelableVector(runningFormInfos, reply)) {
1241 HILOG_ERROR("write failed");
1242 return ERR_APPEXECFWK_PARCEL_ERROR;
1243 }
1244 }
1245 return result;
1246 }
1247
HandleGetRunningFormInfosByBundleName(MessageParcel & data,MessageParcel & reply)1248 ErrCode FormMgrStub::HandleGetRunningFormInfosByBundleName(MessageParcel &data, MessageParcel &reply)
1249 {
1250 HILOG_DEBUG("call");
1251 std::string bundleName = data.ReadString();
1252 bool isUnusedInclude = data.ReadBool();
1253 std::vector<RunningFormInfo> runningFormInfos;
1254 ErrCode result = GetRunningFormInfosByBundleName(bundleName, isUnusedInclude, runningFormInfos);
1255 reply.WriteInt32(result);
1256 if (result == ERR_OK) {
1257 if (!WriteParcelableVector(runningFormInfos, reply)) {
1258 HILOG_ERROR("write failed");
1259 return ERR_APPEXECFWK_PARCEL_ERROR;
1260 }
1261 }
1262 return result;
1263 }
1264
HandleRegisterPublishFormInterceptor(MessageParcel & data,MessageParcel & reply)1265 int32_t FormMgrStub::HandleRegisterPublishFormInterceptor(MessageParcel &data, MessageParcel &reply)
1266 {
1267 HILOG_DEBUG("call");
1268 sptr<IRemoteObject> interceptor = data.ReadRemoteObject();
1269 if (interceptor == nullptr) {
1270 HILOG_ERROR("get remoteObject failed");
1271 return ERR_APPEXECFWK_PARCEL_ERROR;
1272 }
1273 int32_t result = RegisterPublishFormInterceptor(interceptor);
1274 if (!reply.WriteInt32(result)) {
1275 HILOG_ERROR("write result failed");
1276 return ERR_APPEXECFWK_PARCEL_ERROR;
1277 }
1278 return result;
1279 }
1280
HandleUnregisterPublishFormInterceptor(MessageParcel & data,MessageParcel & reply)1281 int32_t FormMgrStub::HandleUnregisterPublishFormInterceptor(MessageParcel &data, MessageParcel &reply)
1282 {
1283 HILOG_DEBUG("call");
1284 sptr<IRemoteObject> interceptor = data.ReadRemoteObject();
1285 if (interceptor == nullptr) {
1286 HILOG_ERROR("get remoteObject failed");
1287 return ERR_APPEXECFWK_PARCEL_ERROR;
1288 }
1289 int32_t result = UnregisterPublishFormInterceptor(interceptor);
1290 if (!reply.WriteInt32(result)) {
1291 HILOG_ERROR("write result failed");
1292 return ERR_APPEXECFWK_PARCEL_ERROR;
1293 }
1294 return result;
1295 }
1296
HandleRegisterClickCallbackEventObserver(MessageParcel & data,MessageParcel & reply)1297 int32_t FormMgrStub::HandleRegisterClickCallbackEventObserver(MessageParcel &data, MessageParcel &reply)
1298 {
1299 HILOG_DEBUG("call");
1300 std::string bundleName = data.ReadString();
1301 std::string formEventType = data.ReadString();
1302 sptr<IRemoteObject> callerToken = data.ReadRemoteObject();
1303 if (callerToken == nullptr) {
1304 HILOG_ERROR("get remoteObject failed");
1305 return ERR_APPEXECFWK_PARCEL_ERROR;
1306 }
1307 return RegisterClickEventObserver(bundleName, formEventType, callerToken);
1308 }
1309
HandleUnregisterClickCallbackEventObserver(MessageParcel & data,MessageParcel & reply)1310 int32_t FormMgrStub::HandleUnregisterClickCallbackEventObserver(MessageParcel &data, MessageParcel &reply)
1311 {
1312 HILOG_DEBUG("call");
1313 std::string bundleName = data.ReadString();
1314 std::string formEventType = data.ReadString();
1315 sptr<IRemoteObject> callerToken = data.ReadRemoteObject();
1316 if (callerToken == nullptr) {
1317 HILOG_ERROR("get remoteObject failed");
1318 return ERR_APPEXECFWK_PARCEL_ERROR;
1319 }
1320 return UnregisterClickEventObserver(bundleName, formEventType, callerToken);
1321 }
1322
1323 /**
1324 * @brief Write a parcelabe vector objects to the proxy node.
1325 * @param parcelableVector Indicates the objects to be write.
1326 * @param reply Indicates the reply to be sent;
1327 * @return Returns true if objects send successfully; returns false otherwise.
1328 */
1329 template<typename T>
WriteParcelableVector(std::vector<T> & parcelableVector,Parcel & reply)1330 bool FormMgrStub::WriteParcelableVector(std::vector<T> &parcelableVector, Parcel &reply)
1331 {
1332 if (!reply.WriteInt32(parcelableVector.size())) {
1333 HILOG_ERROR("write ParcelableVector failed");
1334 return false;
1335 }
1336
1337 for (auto &parcelable: parcelableVector) {
1338 if (!reply.WriteParcelable(&parcelable)) {
1339 HILOG_ERROR("write ParcelableVector failed");
1340 return false;
1341 }
1342 }
1343 return true;
1344 }
1345
HandleRegisterAddObserver(MessageParcel & data,MessageParcel & reply)1346 ErrCode FormMgrStub::HandleRegisterAddObserver(MessageParcel &data, MessageParcel &reply)
1347 {
1348 HILOG_DEBUG("call");
1349 std::string bundleName = data.ReadString();
1350 sptr<IRemoteObject> callerToken = data.ReadRemoteObject();
1351 if (callerToken == nullptr) {
1352 HILOG_ERROR("get remoteObject failed");
1353 return ERR_APPEXECFWK_PARCEL_ERROR;
1354 }
1355 auto result = RegisterAddObserver(bundleName, callerToken);
1356 reply.WriteInt32(result);
1357 return result;
1358 }
1359
HandleRegisterRemoveObserver(MessageParcel & data,MessageParcel & reply)1360 ErrCode FormMgrStub::HandleRegisterRemoveObserver(MessageParcel &data, MessageParcel &reply)
1361 {
1362 HILOG_DEBUG("call");
1363 std::string bundleName = data.ReadString();
1364 sptr<IRemoteObject> callerToken = data.ReadRemoteObject();
1365 if (callerToken == nullptr) {
1366 HILOG_ERROR("get remoteObject failed");
1367 return ERR_APPEXECFWK_PARCEL_ERROR;
1368 }
1369 auto result = RegisterRemoveObserver(bundleName, callerToken);
1370 reply.WriteInt32(result);
1371 return result;
1372 }
1373
HandleRegisterFormRouterProxy(MessageParcel & data,MessageParcel & reply)1374 ErrCode FormMgrStub::HandleRegisterFormRouterProxy(MessageParcel &data, MessageParcel &reply)
1375 {
1376 HILOG_DEBUG("call");
1377 std::vector<int64_t> formIds;
1378 if (!data.ReadInt64Vector(&formIds)) {
1379 HILOG_ERROR("ReadInt64Vector failed");
1380 return ERR_APPEXECFWK_PARCEL_ERROR;
1381 }
1382 sptr<IRemoteObject> callerToken = data.ReadRemoteObject();
1383 if (callerToken == nullptr) {
1384 HILOG_ERROR("get remoteObject failed");
1385 return ERR_APPEXECFWK_PARCEL_ERROR;
1386 }
1387 auto result = RegisterFormRouterProxy(formIds, callerToken);
1388 reply.WriteInt32(result);
1389 return result;
1390 }
1391
HandleUnregisterFormRouterProxy(MessageParcel & data,MessageParcel & reply)1392 ErrCode FormMgrStub::HandleUnregisterFormRouterProxy(MessageParcel &data, MessageParcel &reply)
1393 {
1394 HILOG_DEBUG("call");
1395 std::vector<int64_t> formIds;
1396 if (!data.ReadInt64Vector(&formIds)) {
1397 HILOG_ERROR("ReadInt64Vector failed");
1398 return ERR_APPEXECFWK_PARCEL_ERROR;
1399 }
1400 auto result = UnregisterFormRouterProxy(formIds);
1401 reply.WriteInt32(result);
1402 return result;
1403 }
1404
HandleUpdateProxyForm(MessageParcel & data,MessageParcel & reply)1405 ErrCode FormMgrStub::HandleUpdateProxyForm(MessageParcel &data, MessageParcel &reply)
1406 {
1407 int64_t formId = data.ReadInt64();
1408 std::unique_ptr<FormProviderData> formProviderData(data.ReadParcelable<FormProviderData>());
1409 if (formProviderData == nullptr) {
1410 HILOG_ERROR("get formProviderData failed");
1411 return ERR_APPEXECFWK_PARCEL_ERROR;
1412 }
1413 std::vector<FormDataProxy> formDataProxies;
1414 if (!ReadFormDataProxies(data, formDataProxies)) {
1415 HILOG_ERROR("fail get formDataProxies");
1416 return ERR_APPEXECFWK_PARCEL_ERROR;
1417 }
1418 int32_t result = UpdateProxyForm(formId, *formProviderData, formDataProxies);
1419 reply.WriteInt32(result);
1420 return result;
1421 }
1422
HandleRequestPublishProxyForm(MessageParcel & data,MessageParcel & reply)1423 ErrCode FormMgrStub::HandleRequestPublishProxyForm(MessageParcel &data, MessageParcel &reply)
1424 {
1425 std::unique_ptr<Want> want(data.ReadParcelable<Want>());
1426 if (want == nullptr) {
1427 HILOG_ERROR("error to get want");
1428 return ERR_APPEXECFWK_PARCEL_ERROR;
1429 }
1430
1431 bool withFormBindingData = data.ReadBool();
1432 std::unique_ptr<FormProviderData> formProviderData = nullptr;
1433 if (withFormBindingData) {
1434 formProviderData.reset(data.ReadParcelable<FormProviderData>());
1435 if (formProviderData == nullptr) {
1436 HILOG_ERROR("error to get formProviderData");
1437 return ERR_APPEXECFWK_PARCEL_ERROR;
1438 }
1439 }
1440 std::vector<FormDataProxy> formDataProxies;
1441 if (!ReadFormDataProxies(data, formDataProxies)) {
1442 HILOG_ERROR("fail get formDataProxies");
1443 return ERR_APPEXECFWK_PARCEL_ERROR;
1444 }
1445 int64_t formId = 0;
1446 ErrCode result = RequestPublishProxyForm(*want, withFormBindingData, formProviderData, formId, formDataProxies);
1447 reply.WriteInt32(result);
1448 if (result == ERR_OK) {
1449 reply.WriteInt64(formId);
1450 }
1451 return result;
1452 }
ReadFormDataProxies(MessageParcel & data,std::vector<FormDataProxy> & formDataProxies)1453 bool FormMgrStub::ReadFormDataProxies(MessageParcel &data, std::vector<FormDataProxy> &formDataProxies)
1454 {
1455 auto number = data.ReadInt32();
1456 HILOG_DEBUG("proxies number:%{public}d", number);
1457 if (number < 0 || number > INT16_MAX) {
1458 HILOG_ERROR("proxies number over limit:%{public}d", number);
1459 return false;
1460 }
1461
1462 for (int32_t i = 0; i < number; i++) {
1463 FormDataProxy formDataProxy("", "");
1464 formDataProxy.key = Str16ToStr8(data.ReadString16());
1465 formDataProxy.subscribeId = Str16ToStr8(data.ReadString16());
1466 formDataProxies.push_back(formDataProxy);
1467 }
1468 return true;
1469 }
1470
HandleSetFormsRecyclable(MessageParcel & data,MessageParcel & reply)1471 int32_t FormMgrStub::HandleSetFormsRecyclable(MessageParcel &data, MessageParcel &reply)
1472 {
1473 HILOG_DEBUG("call");
1474 std::vector<int64_t> formIds;
1475 if (!data.ReadInt64Vector(&formIds)) {
1476 HILOG_ERROR("ReadInt64Vector failed");
1477 return ERR_APPEXECFWK_PARCEL_ERROR;
1478 }
1479 int32_t result = SetFormsRecyclable(formIds);
1480 if (!reply.WriteInt32(result)) {
1481 HILOG_ERROR("write result failed");
1482 return ERR_APPEXECFWK_PARCEL_ERROR;
1483 }
1484 return result;
1485 }
1486
HandleRecycleForms(MessageParcel & data,MessageParcel & reply)1487 int32_t FormMgrStub::HandleRecycleForms(MessageParcel &data, MessageParcel &reply)
1488 {
1489 HILOG_DEBUG("call");
1490 std::vector<int64_t> formIds;
1491 if (!data.ReadInt64Vector(&formIds)) {
1492 HILOG_ERROR("ReadInt64Vector failed");
1493 return ERR_APPEXECFWK_PARCEL_ERROR;
1494 }
1495 std::unique_ptr<Want> want(data.ReadParcelable<Want>());
1496 if (!want) {
1497 HILOG_ERROR("ReadParcelable<Want> failed");
1498 return ERR_APPEXECFWK_PARCEL_ERROR;
1499 }
1500 int32_t result = RecycleForms(formIds, *want);
1501 if (!reply.WriteInt32(result)) {
1502 HILOG_ERROR("write result failed");
1503 return ERR_APPEXECFWK_PARCEL_ERROR;
1504 }
1505 return result;
1506 }
1507
HandleRecoverForms(MessageParcel & data,MessageParcel & reply)1508 int32_t FormMgrStub::HandleRecoverForms(MessageParcel &data, MessageParcel &reply)
1509 {
1510 HILOG_DEBUG("call");
1511 std::vector<int64_t> formIds;
1512 if (!data.ReadInt64Vector(&formIds)) {
1513 HILOG_ERROR("ReadInt64Vector failed");
1514 return ERR_APPEXECFWK_PARCEL_ERROR;
1515 }
1516 std::unique_ptr<Want> want(data.ReadParcelable<Want>());
1517 if (!want) {
1518 HILOG_ERROR("ReadParcelable<Want> failed");
1519 return ERR_APPEXECFWK_PARCEL_ERROR;
1520 }
1521 int32_t result = RecoverForms(formIds, *want);
1522 if (!reply.WriteInt32(result)) {
1523 HILOG_ERROR("write result failed");
1524 return ERR_APPEXECFWK_PARCEL_ERROR;
1525 }
1526 return result;
1527 }
1528
HandleUpdateFormLocation(MessageParcel & data,MessageParcel & reply)1529 ErrCode FormMgrStub::HandleUpdateFormLocation(MessageParcel &data, MessageParcel &reply)
1530 {
1531 HILOG_DEBUG("call");
1532 int64_t formId = data.ReadInt64();
1533 int32_t formLocation = data.ReadInt32();
1534 ErrCode result = UpdateFormLocation(formId, formLocation);
1535 if (!reply.WriteInt32(result)) {
1536 HILOG_ERROR("write result failed");
1537 return ERR_APPEXECFWK_PARCEL_ERROR;
1538 }
1539 return result;
1540 }
1541
1542 /**
1543 * @brief handle CreateForm message.
1544 * @param data input param.
1545 * @param reply output param.
1546 * @return Returns ERR_OK on success, others on failure.
1547 */
HandleRequestPublishFormWithSnapshot(MessageParcel & data,MessageParcel & reply)1548 ErrCode FormMgrStub::HandleRequestPublishFormWithSnapshot(MessageParcel &data, MessageParcel &reply)
1549 {
1550 std::unique_ptr<Want> want(data.ReadParcelable<Want>());
1551 if (want == nullptr) {
1552 HILOG_ERROR("error to get want");
1553 return ERR_APPEXECFWK_PARCEL_ERROR;
1554 }
1555
1556 bool withFormBindingData = data.ReadBool();
1557 std::unique_ptr<FormProviderData> formBindingData = nullptr;
1558 if (withFormBindingData) {
1559 formBindingData.reset(data.ReadParcelable<FormProviderData>());
1560 if (formBindingData == nullptr) {
1561 HILOG_ERROR("error to get formBindingData");
1562 return ERR_APPEXECFWK_PARCEL_ERROR;
1563 }
1564 }
1565
1566 int64_t formId = 0;
1567 ErrCode result = RequestPublishFormWithSnapshot(*want, withFormBindingData, formBindingData, formId);
1568 if (!reply.WriteInt32(result)) {
1569 HILOG_ERROR("write result failed");
1570 return ERR_APPEXECFWK_PARCEL_ERROR;
1571 } else {
1572 reply.WriteInt64(formId);
1573 }
1574 return result;
1575 }
1576
HandleBatchRefreshForms(MessageParcel & data,MessageParcel & reply)1577 ErrCode FormMgrStub::HandleBatchRefreshForms(MessageParcel &data, MessageParcel &reply)
1578 {
1579 int32_t formRefreshType = data.ReadInt32();
1580 ErrCode result = BatchRefreshForms(formRefreshType);
1581 if (!reply.WriteInt32(result)) {
1582 HILOG_ERROR("write result failed");
1583 return ERR_APPEXECFWK_PARCEL_ERROR;
1584 }
1585 return result;
1586 }
1587
HandleEnableForms(MessageParcel & data,MessageParcel & reply)1588 int32_t FormMgrStub::HandleEnableForms(MessageParcel &data, MessageParcel &reply)
1589 {
1590 HILOG_DEBUG("call");
1591 std::string bundleName = data.ReadString();
1592 if (bundleName.empty()) {
1593 HILOG_ERROR("fail ReadString<bundleName>");
1594 return ERR_APPEXECFWK_PARCEL_ERROR;
1595 }
1596 bool enable = data.ReadBool();
1597 int32_t result = EnableForms(bundleName, enable);
1598 if (!reply.WriteInt32(result)) {
1599 HILOG_ERROR("write result failed");
1600 return ERR_APPEXECFWK_PARCEL_ERROR;
1601 }
1602 return result;
1603 }
1604
HandleIsFormBundleForbidden(MessageParcel & data,MessageParcel & reply)1605 ErrCode FormMgrStub::HandleIsFormBundleForbidden(MessageParcel &data, MessageParcel &reply)
1606 {
1607 HILOG_DEBUG("call");
1608 std::string bundleName = data.ReadString();
1609 bool result = IsFormBundleForbidden(bundleName);
1610 if (!reply.WriteBool(result)) {
1611 HILOG_ERROR("write action failed");
1612 return ERR_APPEXECFWK_PARCEL_ERROR;
1613 }
1614 return ERR_OK;
1615 }
1616 } // namespace AppExecFwk
1617 } // namespace OHOS