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