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