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_proxy.h"
17 
18 #include "appexecfwk_errors.h"
19 #include "fms_log_wrapper.h"
20 #include "form_mgr_errors.h"
21 #include "string_ex.h"
22 
23 namespace OHOS {
24 namespace AppExecFwk {
25 namespace {
26     static constexpr int32_t MAX_ALLOW_SIZE = 8 * 1024;
27 }
FormMgrProxy(const sptr<IRemoteObject> & impl)28 FormMgrProxy::FormMgrProxy(const sptr<IRemoteObject> &impl) : IRemoteProxy<IFormMgr>(impl)
29 {}
30 /**
31  * @brief Add form with want, send want to form manager service.
32  * @param formId The Id of the forms to add.
33  * @param want The want of the form to add.
34  * @param callerToken Caller ability token.
35  * @param formInfo Form info.
36  * @return Returns ERR_OK on success, others on failure.
37  */
AddForm(const int64_t formId,const Want & want,const sptr<IRemoteObject> & callerToken,FormJsInfo & formInfo)38 int FormMgrProxy::AddForm(
39     const int64_t formId,
40     const Want &want,
41     const sptr<IRemoteObject> &callerToken,
42     FormJsInfo &formInfo)
43 {
44     MessageParcel data;
45     if (!WriteInterfaceToken(data)) {
46         HILOG_ERROR("write to interface token failed");
47         return ERR_APPEXECFWK_PARCEL_ERROR;
48     }
49     if (!data.WriteInt64(formId)) {
50         HILOG_ERROR("write to formId failed");
51         return ERR_APPEXECFWK_PARCEL_ERROR;
52     }
53     if (!data.WriteParcelable(&want)) {
54         HILOG_ERROR("write to want failed");
55         return ERR_APPEXECFWK_PARCEL_ERROR;
56     }
57 
58     if (!data.WriteRemoteObject(callerToken)) {
59         HILOG_ERROR("write to callerTokenfailed");
60         return ERR_APPEXECFWK_PARCEL_ERROR;
61     }
62 
63     int error = GetParcelableInfo<FormJsInfo>(IFormMgr::Message::FORM_MGR_ADD_FORM, data, formInfo);
64     if (error != ERR_OK) {
65         HILOG_ERROR("SendRequest:%{public}d failed", error);
66     }
67 
68     return error;
69 }
70 
71 /**
72  * @brief Add form with want, send want to form manager service.
73  * @param want The want of the form to add.
74  * @param runningFormInfo Running form info.
75  * @return Returns ERR_OK on success, others on failure.
76  */
CreateForm(const Want & want,RunningFormInfo & runningFormInfo)77 int FormMgrProxy::CreateForm(const Want &want, RunningFormInfo &runningFormInfo)
78 {
79     MessageParcel data;
80     if (!WriteInterfaceToken(data)) {
81         HILOG_ERROR("write to interface token failed");
82         return ERR_APPEXECFWK_PARCEL_ERROR;
83     }
84     if (!data.WriteParcelable(&want)) {
85         HILOG_ERROR("write to want failed");
86         return ERR_APPEXECFWK_PARCEL_ERROR;
87     }
88     int ret = GetParcelableInfo<RunningFormInfo>(IFormMgr::Message::FORM_MGR_CREATE_FORM, data, runningFormInfo);
89     if (ret != ERR_OK) {
90         HILOG_ERROR("fail SendRequest:%{public}d", ret);
91     }
92     return ret;
93 }
94 
95 /**
96  * @brief Delete forms with formIds, send formIds to form manager service.
97  * @param formId The Id of the forms to delete.
98  * @param callerToken Caller ability token.
99  * @return Returns ERR_OK on success, others on failure.
100  */
DeleteForm(const int64_t formId,const sptr<IRemoteObject> & callerToken)101 int FormMgrProxy::DeleteForm(const int64_t formId, const sptr<IRemoteObject> &callerToken)
102 {
103     MessageParcel data;
104     if (!WriteInterfaceToken(data)) {
105         HILOG_ERROR("write interface token failed");
106         return ERR_APPEXECFWK_PARCEL_ERROR;
107     }
108     if (!data.WriteInt64(formId)) {
109         HILOG_ERROR("write want failed");
110         return ERR_APPEXECFWK_PARCEL_ERROR;
111     }
112     if (!data.WriteRemoteObject(callerToken)) {
113         HILOG_ERROR("write callerToken failed");
114         return ERR_APPEXECFWK_PARCEL_ERROR;
115     }
116     MessageParcel reply;
117     MessageOption option;
118     int error = SendTransactCmd(
119         IFormMgr::Message::FORM_MGR_DELETE_FORM,
120         data,
121         reply,
122         option);
123     if (error != ERR_OK) {
124         HILOG_ERROR("SendRequest:%{public}d failed", error);
125         return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
126     }
127     return reply.ReadInt32();
128 }
129 
StopRenderingForm(const int64_t formId,const std::string & compId)130 int FormMgrProxy::StopRenderingForm(const int64_t formId, const std::string &compId)
131 {
132     MessageParcel data;
133     if (!WriteInterfaceToken(data)) {
134         HILOG_ERROR("write interface token failed");
135         return ERR_APPEXECFWK_PARCEL_ERROR;
136     }
137     if (!data.WriteInt64(formId)) {
138         HILOG_ERROR("write want failed");
139         return ERR_APPEXECFWK_PARCEL_ERROR;
140     }
141     if (!data.WriteString(compId)) {
142         HILOG_ERROR("write compId failed");
143         return ERR_APPEXECFWK_PARCEL_ERROR;
144     }
145     MessageParcel reply;
146     MessageOption option;
147     int error = SendTransactCmd(
148         IFormMgr::Message::FORM_MGR_STOP_RENDERING_FORM,
149         data,
150         reply,
151         option);
152     if (error != ERR_OK) {
153         HILOG_ERROR("SendRequest:%{public}d failed", error);
154         return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
155     }
156     return reply.ReadInt32();
157 }
158 
159 /**
160  * @brief Release forms with formIds, send formIds to form manager service.
161  * @param formId The Id of the forms to release.
162  * @param callerToken Caller ability token.
163  * @param delCache Delete Cache or not.
164  * @return Returns ERR_OK on success, others on failure.
165  */
ReleaseForm(const int64_t formId,const sptr<IRemoteObject> & callerToken,const bool delCache)166 int FormMgrProxy::ReleaseForm(const int64_t formId, const sptr<IRemoteObject> &callerToken, const bool delCache)
167 {
168     MessageParcel data;
169     if (!WriteInterfaceToken(data)) {
170         HILOG_ERROR("write interface token failed");
171         return ERR_APPEXECFWK_PARCEL_ERROR;
172     }
173     if (!data.WriteInt64(formId)) {
174         HILOG_ERROR("write want failed");
175         return ERR_APPEXECFWK_PARCEL_ERROR;
176     }
177     if (!data.WriteRemoteObject(callerToken)) {
178         HILOG_ERROR("write callerToken failed");
179         return ERR_APPEXECFWK_PARCEL_ERROR;
180     }
181     if (!data.WriteBool(delCache)) {
182         HILOG_ERROR("write delCache failed");
183         return ERR_APPEXECFWK_PARCEL_ERROR;
184     }
185 
186     MessageParcel reply;
187     MessageOption option;
188     int error = SendTransactCmd(
189         IFormMgr::Message::FORM_MGR_RELEASE_FORM,
190         data,
191         reply,
192         option);
193     if (error != ERR_OK) {
194         HILOG_ERROR("SendRequest:%{public}d failed", error);
195         return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
196     }
197     return reply.ReadInt32();
198 }
199 
200 /**
201  * @brief Update form with formId, send formId to form manager service.
202  * @param formId The Id of the form to update.
203  * @param bundleName Provider ability bundleName.
204  * @param FormProviderData Form binding data.
205  * @return Returns ERR_OK on success, others on failure.
206  */
UpdateForm(const int64_t formId,const FormProviderData & FormProviderData)207 int FormMgrProxy::UpdateForm(const int64_t formId, const FormProviderData &FormProviderData)
208 {
209     MessageParcel data;
210     if (!WriteInterfaceToken(data)) {
211         HILOG_ERROR("write interface token failed");
212         return ERR_APPEXECFWK_PARCEL_ERROR;
213     }
214     if (!data.WriteInt64(formId)) {
215         HILOG_ERROR("write formId failed");
216         return ERR_APPEXECFWK_PARCEL_ERROR;
217     }
218     if (!data.WriteParcelable(&FormProviderData)) {
219         HILOG_ERROR("write formBindingData failed");
220         return ERR_APPEXECFWK_PARCEL_ERROR;
221     }
222     MessageParcel reply;
223     MessageOption option;
224     int error = SendTransactCmd(
225         IFormMgr::Message::FORM_MGR_UPDATE_FORM,
226         data,
227         reply,
228         option);
229     if (error != ERR_OK) {
230         HILOG_ERROR("SendRequest:%{public}d failed", error);
231         return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
232     }
233     return reply.ReadInt32();
234 }
235 
236 /**
237  * @brief Set next refresh time.
238  * @param formId The Id of the form to update.
239  * @param bundleName Provider ability bundleName.
240  * @param nextTime Next refresh time.
241  * @return Returns ERR_OK on success, others on failure.
242  */
SetNextRefreshTime(const int64_t formId,const int64_t nextTime)243 int FormMgrProxy::SetNextRefreshTime(const int64_t formId, const int64_t nextTime)
244 {
245     MessageParcel data;
246     MessageParcel reply;
247 
248     if (!WriteInterfaceToken(data)) {
249         HILOG_ERROR("write interface token failed");
250         return ERR_APPEXECFWK_PARCEL_ERROR;
251     }
252     if (!data.WriteInt64(formId)) {
253         HILOG_ERROR("write formId failed");
254         return ERR_APPEXECFWK_PARCEL_ERROR;
255     }
256     if (!data.WriteInt64(nextTime)) {
257         HILOG_ERROR("write nextTime failed");
258         return ERR_APPEXECFWK_PARCEL_ERROR;
259     }
260     MessageOption option;
261     int error = SendTransactCmd(
262         IFormMgr::Message::FORM_MGR_SET_NEXT_REFRESH_TIME,
263         data,
264         reply,
265         option);
266     if (error != ERR_OK) {
267         HILOG_ERROR("SendRequest:%{public}d failed", error);
268         return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
269     }
270     return reply.ReadInt32();
271 }
272 
ReleaseRenderer(int64_t formId,const std::string & compId)273 int FormMgrProxy::ReleaseRenderer(int64_t formId, const std::string &compId)
274 {
275     MessageParcel data;
276     MessageParcel reply;
277 
278     if (!WriteInterfaceToken(data)) {
279         HILOG_ERROR("write interface token failed");
280         return ERR_APPEXECFWK_PARCEL_ERROR;
281     }
282     if (!data.WriteInt64(formId)) {
283         HILOG_ERROR("write formId failed");
284         return ERR_APPEXECFWK_PARCEL_ERROR;
285     }
286     if (!data.WriteString(compId)) {
287         HILOG_ERROR("write compId failed");
288         return ERR_APPEXECFWK_PARCEL_ERROR;
289     }
290     MessageOption option;
291     int error = SendTransactCmd(
292         IFormMgr::Message::FORM_MGR_RELEASE_RENDERER,
293         data,
294         reply,
295         option);
296     if (error != ERR_OK) {
297         HILOG_ERROR("SendRequest:%{public}d failed", error);
298         return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
299     }
300     return reply.ReadInt32();
301 }
302 
RequestPublishForm(Want & want,bool withFormBindingData,std::unique_ptr<FormProviderData> & formBindingData,int64_t & formId)303 ErrCode FormMgrProxy::RequestPublishForm(Want &want, bool withFormBindingData,
304                                          std::unique_ptr<FormProviderData> &formBindingData, int64_t &formId)
305 {
306     MessageParcel data;
307     MessageParcel reply;
308 
309     if (!WriteInterfaceToken(data)) {
310         HILOG_ERROR("write interface token failed");
311         return ERR_APPEXECFWK_PARCEL_ERROR;
312     }
313     if (!data.WriteParcelable(&want)) {
314         HILOG_ERROR("write want failed");
315         return ERR_APPEXECFWK_PARCEL_ERROR;
316     }
317     if (!data.WriteBool(withFormBindingData)) {
318         HILOG_ERROR("write withFormBindingData failed");
319         return ERR_APPEXECFWK_PARCEL_ERROR;
320     }
321     if (withFormBindingData) {
322         if (!data.WriteParcelable(formBindingData.get())) {
323             HILOG_ERROR("write formBindingData failed");
324             return ERR_APPEXECFWK_PARCEL_ERROR;
325         }
326     }
327     MessageOption option;
328     int32_t error = SendTransactCmd(
329         IFormMgr::Message::FORM_MGR_REQUEST_PUBLISH_FORM,
330         data,
331         reply,
332         option);
333     if (error != ERR_OK) {
334         HILOG_ERROR("SendRequest:%{public}d failed", error);
335         return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
336     }
337     ErrCode errCode = reply.ReadInt32();
338     if (errCode == ERR_OK) {
339         formId = reply.ReadInt64();
340     }
341     return errCode;
342 }
343 
SetPublishFormResult(const int64_t formId,Constants::PublishFormResult & errorCodeInfo)344 ErrCode FormMgrProxy::SetPublishFormResult(const int64_t formId, Constants::PublishFormResult &errorCodeInfo)
345 {
346     MessageParcel data;
347     MessageParcel reply;
348 
349     if (!WriteInterfaceToken(data)) {
350         HILOG_ERROR("write interface token failed");
351         return ERR_APPEXECFWK_PARCEL_ERROR;
352     }
353     if (!data.WriteInt64(formId)) {
354         HILOG_ERROR("write want failed");
355         return ERR_APPEXECFWK_PARCEL_ERROR;
356     }
357 
358     if (!data.WriteString(errorCodeInfo.message)) {
359         HILOG_ERROR("fail write ErrorCode message");
360         return ERR_APPEXECFWK_PARCEL_ERROR;
361     }
362 
363     if (!data.WriteInt32(static_cast<int32_t>(errorCodeInfo.code))) {
364         HILOG_ERROR("write ErrorCode failed");
365         return ERR_APPEXECFWK_PARCEL_ERROR;
366     }
367 
368     MessageOption option;
369     int32_t error = SendTransactCmd(
370         IFormMgr::Message::FORM_MGR_PUBLISH_FORM_ERRCODE_RESULT,
371         data,
372         reply,
373         option);
374     if (error != ERR_OK) {
375         HILOG_ERROR("SendRequest:%{public}d failed", error);
376         return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
377     }
378     return reply.ReadInt32();
379 }
380 
AcquireAddFormResult(const int64_t formId)381 ErrCode FormMgrProxy::AcquireAddFormResult(const int64_t formId)
382 {
383     MessageParcel data;
384     MessageParcel reply;
385 
386     if (!WriteInterfaceToken(data)) {
387         HILOG_ERROR("write interface token failed");
388         return ERR_APPEXECFWK_PARCEL_ERROR;
389     }
390     if (!data.WriteInt64(formId)) {
391         HILOG_ERROR("write want failed");
392         return ERR_APPEXECFWK_PARCEL_ERROR;
393     }
394 
395     MessageOption option(MessageOption::TF_SYNC);
396     int32_t error = SendTransactCmd(
397         IFormMgr::Message::FORM_MGR_ACQUIRE_ADD_FORM_RESULT,
398         data,
399         reply,
400         option);
401     if (error != ERR_OK) {
402         HILOG_ERROR("SendRequest:%{public}d failed", error);
403         return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
404     }
405     return reply.ReadInt32();
406 }
407 
LifecycleUpdate(const std::vector<int64_t> & formIds,const sptr<IRemoteObject> & callerToken,bool updateType)408 int FormMgrProxy::LifecycleUpdate(
409     const std::vector<int64_t> &formIds,
410     const sptr<IRemoteObject> &callerToken,
411     bool updateType)
412 {
413     MessageParcel data;
414     MessageParcel reply;
415 
416     if (!WriteInterfaceToken(data)) {
417         HILOG_ERROR("write interface token failed");
418         return ERR_APPEXECFWK_PARCEL_ERROR;
419     }
420     if (!data.WriteInt64Vector(formIds)) {
421         HILOG_ERROR("write formId failed");
422         return ERR_APPEXECFWK_PARCEL_ERROR;
423     }
424     if (!data.WriteRemoteObject(callerToken)) {
425         HILOG_ERROR("write bundleName failed");
426         return ERR_APPEXECFWK_PARCEL_ERROR;
427     }
428     if (!data.WriteBool(updateType)) {
429         HILOG_ERROR("write nextTime failed");
430         return ERR_APPEXECFWK_PARCEL_ERROR;
431     }
432     MessageOption option;
433     int error = SendTransactCmd(
434         IFormMgr::Message::FORM_MGR_LIFECYCLE_UPDATE,
435         data,
436         reply,
437         option);
438     if (error != ERR_OK) {
439         HILOG_ERROR("SendRequest:%{public}d failed", error);
440         return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
441     }
442 
443     return reply.ReadInt32();
444 }
445 /**
446  * @brief Request form with formId and want, send formId and want to form manager service.
447  * @param formId The Id of the form to update.
448  * @param callerToken Caller ability token.
449  * @param want The want of the form to add.
450  * @return Returns ERR_OK on success, others on failure.
451  */
RequestForm(const int64_t formId,const sptr<IRemoteObject> & callerToken,const Want & want)452 int FormMgrProxy::RequestForm(const int64_t formId, const sptr<IRemoteObject> &callerToken, const Want &want)
453 {
454     HILOG_INFO("call");
455 
456     MessageParcel data;
457     if (!WriteInterfaceToken(data)) {
458         HILOG_ERROR("write interface token failed");
459         return ERR_APPEXECFWK_PARCEL_ERROR;
460     }
461     if (!data.WriteInt64(formId)) {
462         HILOG_ERROR("write formId failed");
463         return ERR_APPEXECFWK_PARCEL_ERROR;
464     }
465     if (!data.WriteRemoteObject(callerToken)) {
466         HILOG_ERROR("write callerToken failed");
467         return ERR_APPEXECFWK_PARCEL_ERROR;
468     }
469     if (!data.WriteParcelable(&want)) {
470         HILOG_ERROR("write want failed");
471         return ERR_APPEXECFWK_PARCEL_ERROR;
472     }
473 
474     MessageParcel reply;
475     MessageOption option;
476     int error = SendTransactCmd(
477         IFormMgr::Message::FORM_MGR_REQUEST_FORM,
478         data,
479         reply,
480         option);
481     if (error != ERR_OK) {
482         HILOG_ERROR("SendRequest:%{public}d failed", error);
483         return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
484     }
485     return reply.ReadInt32();
486 }
487 
488 /**
489  * @brief Form visible/invisible notify, send formIds to form manager service.
490  * @param formIds The Id list of the forms to notify.
491  * @param callerToken Caller ability token.
492  * @param formVisibleType The form visible type, including FORM_VISIBLE and FORM_INVISIBLE.
493  * @return Returns ERR_OK on success, others on failure.
494  */
NotifyWhetherVisibleForms(const std::vector<int64_t> & formIds,const sptr<IRemoteObject> & callerToken,const int32_t formVisibleType)495 int FormMgrProxy::NotifyWhetherVisibleForms(
496     const std::vector<int64_t> &formIds,
497     const sptr<IRemoteObject> &callerToken,
498     const int32_t formVisibleType)
499 {
500     MessageParcel data;
501     if (!WriteInterfaceToken(data)) {
502         HILOG_ERROR("write interface token failed");
503         return ERR_APPEXECFWK_PARCEL_ERROR;
504     }
505 
506     if (!data.WriteInt64Vector(formIds)) {
507         HILOG_ERROR("write formIds failed");
508         return ERR_APPEXECFWK_PARCEL_ERROR;
509     }
510 
511     if (!data.WriteRemoteObject(callerToken)) {
512         HILOG_ERROR("write callerToken failed");
513         return ERR_APPEXECFWK_PARCEL_ERROR;
514     }
515 
516     if (!data.WriteInt32(formVisibleType)) {
517         HILOG_ERROR("fail write formVisibleType");
518         return ERR_APPEXECFWK_PARCEL_ERROR;
519     }
520 
521     MessageParcel reply;
522     MessageOption option;
523     int error = SendTransactCmd(
524         IFormMgr::Message::FORM_MGR_NOTIFY_FORM_WHETHER_VISIBLE,
525         data,
526         reply,
527         option);
528     if (error != ERR_OK) {
529         HILOG_ERROR("SendRequest:%{public}d failed", error);
530         return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
531     }
532     return reply.ReadInt32();
533 }
534 
535 /**
536  * @brief Query whether has visible form by tokenId.
537  * @param tokenId Unique identification of application.
538  * @return Returns true if has visible form, false otherwise.
539  */
HasFormVisible(const uint32_t tokenId)540 bool FormMgrProxy::HasFormVisible(const uint32_t tokenId)
541 {
542     HILOG_DEBUG("call");
543 
544     MessageParcel data;
545     if (!WriteInterfaceToken(data)) {
546         HILOG_ERROR("error to write interface token");
547         return false;
548     }
549     if (!data.WriteUint32(tokenId)) {
550         HILOG_ERROR("fail write tokenId");
551         return false;
552     }
553 
554     // send request
555     MessageParcel reply;
556     MessageOption option;
557     int error = SendTransactCmd(
558         IFormMgr::Message::FORM_MGR_HAS_FORM_VISIBLE_WITH_TOKENID,
559         data,
560         reply,
561         option);
562     if (error != ERR_OK) {
563         HILOG_ERROR("SendRequest:%{public}d failed", error);
564         return false;
565     }
566 
567     // retrieve and return result.
568     return reply.ReadBool();
569 }
570 
571 /**
572  * @brief temp form to normal form.
573  * @param formId The Id of the form.
574  * @param callerToken Caller ability token.
575  * @return Returns ERR_OK on success, others on failure.
576  */
CastTempForm(const int64_t formId,const sptr<IRemoteObject> & callerToken)577 int FormMgrProxy::CastTempForm(const int64_t formId, const sptr<IRemoteObject> &callerToken)
578 {
579     MessageParcel data;
580     if (!WriteInterfaceToken(data)) {
581         HILOG_ERROR("write interface token failed");
582         return ERR_APPEXECFWK_PARCEL_ERROR;
583     }
584     if (!data.WriteInt64(formId)) {
585         HILOG_ERROR("write want failed");
586         return ERR_APPEXECFWK_PARCEL_ERROR;
587     }
588     if (!data.WriteRemoteObject(callerToken)) {
589         HILOG_ERROR("callerToken is write failed");
590         return ERR_APPEXECFWK_PARCEL_ERROR;
591     }
592 
593     MessageParcel reply;
594     MessageOption option;
595     int error = SendTransactCmd(
596         IFormMgr::Message::FORM_MGR_CAST_TEMP_FORM,
597         data,
598         reply,
599         option);
600     if (error != ERR_OK) {
601         HILOG_ERROR("SendRequest:%{public}d failed", error);
602         return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
603     }
604     return reply.ReadInt32();
605 }
606 /**
607  * @brief Dump all of form storage infos.
608  * @param formInfos All of form storage infos.
609  * @return Returns ERR_OK on success, others on failure.
610  */
DumpStorageFormInfos(std::string & formInfos)611 int FormMgrProxy::DumpStorageFormInfos(std::string &formInfos)
612 {
613     MessageParcel data;
614     if (!WriteInterfaceToken(data)) {
615         HILOG_ERROR("write interface token failed");
616         return ERR_APPEXECFWK_PARCEL_ERROR;
617     }
618 
619     int error = GetStringInfo(IFormMgr::Message::FORM_MGR_STORAGE_FORM_INFOS, data, formInfos);
620     if (error != ERR_OK) {
621         HILOG_ERROR("GetStringInfo:%{public}d failed", error);
622     }
623 
624     return error;
625 }
626 /**
627  * @brief Dump form info by a bundle name.
628  * @param bundleName The bundle name of form provider.
629  * @param formInfos Form infos.
630  * @return Returns ERR_OK on success, others on failure.
631  */
DumpFormInfoByBundleName(const std::string & bundleName,std::string & formInfos)632 int FormMgrProxy::DumpFormInfoByBundleName(const std::string &bundleName, std::string &formInfos)
633 {
634     MessageParcel data;
635     if (!WriteInterfaceToken(data)) {
636         HILOG_ERROR("write interface token failed");
637         return ERR_APPEXECFWK_PARCEL_ERROR;
638     }
639 
640     if (!data.WriteString(bundleName)) {
641         HILOG_ERROR("write bundleName failed");
642         return ERR_APPEXECFWK_PARCEL_ERROR;
643     }
644 
645     int error = GetStringInfo(IFormMgr::Message::FORM_MGR_FORM_INFOS_BY_NAME, data, formInfos);
646     if (error != ERR_OK) {
647         HILOG_ERROR("GetStringInfo:%{public}d failed", error);
648     }
649 
650     return error;
651 }
652 /**
653  * @brief Dump form info by a bundle name.
654  * @param formId The id of the form.
655  * @param formInfo Form info.
656  * @return Returns ERR_OK on success, others on failure.
657  */
DumpFormInfoByFormId(const std::int64_t formId,std::string & formInfo)658 int FormMgrProxy::DumpFormInfoByFormId(const std::int64_t formId, std::string &formInfo)
659 {
660     MessageParcel data;
661     if (!WriteInterfaceToken(data)) {
662         HILOG_ERROR("write interface token failed");
663         return ERR_APPEXECFWK_PARCEL_ERROR;
664     }
665     if (!data.WriteInt64(formId)) {
666         HILOG_ERROR("write formId failed");
667         return ERR_APPEXECFWK_PARCEL_ERROR;
668     }
669 
670     int error = GetStringInfo(IFormMgr::Message::FORM_MGR_FORM_INFOS_BY_ID, data, formInfo);
671     if (error != ERR_OK) {
672         HILOG_ERROR("GetStringInfo:%{public}d failed", error);
673     }
674 
675     return error;
676 }
677 /**
678  * @brief Dump timer info by form id.
679  * @param formId The id of the form.
680  * @param formInfo Form timer info.
681  * @return Returns ERR_OK on success, others on failure.
682  */
DumpFormTimerByFormId(const std::int64_t formId,std::string & isTimingService)683 int FormMgrProxy::DumpFormTimerByFormId(const std::int64_t formId, std::string &isTimingService)
684 {
685     MessageParcel data;
686     if (!WriteInterfaceToken(data)) {
687         HILOG_ERROR("write interface token failed");
688         return ERR_APPEXECFWK_PARCEL_ERROR;
689     }
690     if (!data.WriteInt64(formId)) {
691         HILOG_ERROR("write formId failed");
692         return ERR_APPEXECFWK_PARCEL_ERROR;
693     }
694 
695     int error = GetStringInfo(IFormMgr::Message::FORM_MGR_FORM_TIMER_INFO_BY_ID, data, isTimingService);
696     if (error != ERR_OK) {
697         HILOG_ERROR("GetStringInfo:%{public}d failed", error);
698     }
699 
700     return error;
701 }
702 /**
703  * @brief Process js message event.
704  * @param formId Indicates the unique id of form.
705  * @param want information passed to supplier.
706  * @param callerToken Caller ability token.
707  * @return Returns true if execute success, false otherwise.
708  */
MessageEvent(const int64_t formId,const Want & want,const sptr<IRemoteObject> & callerToken)709 int FormMgrProxy::MessageEvent(const int64_t formId, const Want &want, const sptr<IRemoteObject> &callerToken)
710 {
711     MessageParcel data;
712     if (!WriteInterfaceToken(data)) {
713         HILOG_ERROR("write interface token failed");
714         return ERR_APPEXECFWK_PARCEL_ERROR;
715     }
716     if (!data.WriteInt64(formId)) {
717         HILOG_ERROR("write formId failed");
718         return ERR_APPEXECFWK_PARCEL_ERROR;
719     }
720     if (!data.WriteParcelable(&want)) {
721         HILOG_ERROR("error to write want");
722         return ERR_APPEXECFWK_PARCEL_ERROR;
723     }
724 
725     if (!data.WriteRemoteObject(callerToken)) {
726         HILOG_ERROR("error to write callerToken");
727         return ERR_APPEXECFWK_PARCEL_ERROR;
728     }
729 
730     MessageParcel reply;
731     MessageOption option;
732     int error = SendTransactCmd(IFormMgr::Message::FORM_MGR_MESSAGE_EVENT,
733         data, reply, option);
734     if (error != ERR_OK) {
735         HILOG_ERROR("SendRequest:%{public}d failed", error);
736         return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
737     }
738     return reply.ReadInt32();
739 }
740 
741 /**
742  * @brief Process Background event.
743  * @param formId Indicates the unique id of form.
744  * @param want the want of the ability to start.
745  * @param callerToken Caller ability token.
746  * @return Returns true if execute success, false otherwise.
747  */
BackgroundEvent(const int64_t formId,Want & want,const sptr<IRemoteObject> & callerToken)748 int FormMgrProxy::BackgroundEvent(const int64_t formId, Want &want, const sptr<IRemoteObject> &callerToken)
749 {
750     MessageParcel data;
751     if (!WriteInterfaceToken(data)) {
752         HILOG_ERROR("write interfaceToken failed");
753         return ERR_APPEXECFWK_PARCEL_ERROR;
754     }
755     if (!data.WriteInt64(formId)) {
756         HILOG_ERROR("write formId failed");
757         return ERR_APPEXECFWK_PARCEL_ERROR;
758     }
759     if (!data.WriteParcelable(&want)) {
760         HILOG_ERROR("write want failed");
761         return ERR_APPEXECFWK_PARCEL_ERROR;
762     }
763 
764     if (!data.WriteRemoteObject(callerToken)) {
765         HILOG_ERROR("write callerToken failed");
766         return ERR_APPEXECFWK_PARCEL_ERROR;
767     }
768 
769     MessageParcel reply;
770     MessageOption option;
771     int error = SendTransactCmd(IFormMgr::Message::FORM_MGR_BACKGROUND_EVENT,
772         data, reply, option);
773     if (error != ERR_OK) {
774         HILOG_ERROR("SendRequest:%{public}d failed", error);
775         return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
776     }
777     return reply.ReadInt32();
778 }
779 
780 /**
781  * @brief Process js router event.
782  * @param formId Indicates the unique id of form.
783  * @param want the want of the ability to start.
784  * @param callerToken Caller ability token.
785  * @return Returns true if execute success, false otherwise.
786  */
RouterEvent(const int64_t formId,Want & want,const sptr<IRemoteObject> & callerToken)787 int FormMgrProxy::RouterEvent(const int64_t formId, Want &want, const sptr<IRemoteObject> &callerToken)
788 {
789     MessageParcel data;
790     if (!WriteInterfaceToken(data)) {
791         HILOG_ERROR("write to interface token error");
792         return ERR_APPEXECFWK_PARCEL_ERROR;
793     }
794     if (!data.WriteInt64(formId)) {
795         HILOG_ERROR("write to formId error");
796         return ERR_APPEXECFWK_PARCEL_ERROR;
797     }
798     if (!data.WriteParcelable(&want)) {
799         HILOG_ERROR("write to want error");
800         return ERR_APPEXECFWK_PARCEL_ERROR;
801     }
802 
803     if (!data.WriteRemoteObject(callerToken)) {
804         HILOG_ERROR("write to callerToken error");
805         return ERR_APPEXECFWK_PARCEL_ERROR;
806     }
807 
808     MessageParcel reply;
809     MessageOption option;
810     int error = SendTransactCmd(IFormMgr::Message::FORM_MGR_ROUTER_EVENT,
811         data, reply, option);
812     if (error != ERR_OK) {
813         HILOG_ERROR("SendRequest:%{public}d failed", error);
814         return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
815     }
816     return reply.ReadInt32();
817 }
818 
819 template<typename T>
GetParcelableInfos(MessageParcel & reply,std::vector<T> & parcelableInfos)820 int  FormMgrProxy::GetParcelableInfos(MessageParcel &reply, std::vector<T> &parcelableInfos)
821 {
822     int32_t infoSize = reply.ReadInt32();
823     if (infoSize < 0 || infoSize > MAX_ALLOW_SIZE) {
824         HILOG_ERROR("invalid size = %{public}d", infoSize);
825         return ERR_APPEXECFWK_PARCEL_ERROR;
826     }
827     for (int32_t i = 0; i < infoSize; i++) {
828         std::unique_ptr<T> info(reply.ReadParcelable<T>());
829         if (!info) {
830             HILOG_ERROR("error to Read Parcelable infos");
831             return ERR_APPEXECFWK_PARCEL_ERROR;
832         }
833         parcelableInfos.emplace_back(*info);
834     }
835     HILOG_DEBUG("get parcelable infos success");
836     return ERR_OK;
837 }
WriteInterfaceToken(MessageParcel & data)838 bool FormMgrProxy::WriteInterfaceToken(MessageParcel &data)
839 {
840     if (!data.WriteInterfaceToken(IFormMgr::GetDescriptor())) {
841         HILOG_ERROR("write interface token failed");
842         return false;
843     }
844     return true;
845 }
GetStringInfo(IFormMgr::Message code,MessageParcel & data,std::string & stringInfo)846 int FormMgrProxy::GetStringInfo(IFormMgr::Message code, MessageParcel &data, std::string &stringInfo)
847 {
848     HILOG_DEBUG("GetStringInfo start");
849     int error;
850     MessageParcel reply;
851     MessageOption option(MessageOption::TF_SYNC);
852     error = SendTransactCmd(code, data, reply, option);
853     if (error != ERR_OK) {
854         return error;
855     }
856 
857     error = reply.ReadInt32();
858     if (error != ERR_OK) {
859         HILOG_ERROR("error to read reply result");
860         return error;
861     }
862     std::vector<std::string> stringInfoList;
863     if (!reply.ReadStringVector(&stringInfoList)) {
864         HILOG_ERROR("fail read string vector from reply");
865         return false;
866     }
867     if (stringInfoList.empty()) {
868         HILOG_INFO("No string info");
869         return ERR_APPEXECFWK_FORM_COMMON_CODE;
870     }
871     for (const auto &info : stringInfoList) {
872         stringInfo += info;
873     }
874     HILOG_DEBUG("get string info success");
875     return ERR_OK;
876 }
GetFormsInfo(IFormMgr::Message code,MessageParcel & data,std::vector<FormInfo> & formInfos)877 int FormMgrProxy::GetFormsInfo(IFormMgr::Message code, MessageParcel &data, std::vector<FormInfo> &formInfos)
878 {
879     HILOG_DEBUG("GetFormsInfo start");
880     int error;
881     MessageParcel reply;
882     MessageOption option(MessageOption::TF_SYNC);
883     error = SendTransactCmd(code, data, reply, option);
884     if (error != ERR_OK) {
885         return error;
886     }
887 
888     error = reply.ReadInt32();
889     if (error != ERR_OK) {
890         HILOG_ERROR("read reply result fail");
891         return error;
892     }
893 
894     return GetParcelableInfos<FormInfo>(reply, formInfos);
895 }
896 
GetRunningFormInfos(IFormMgr::Message code,MessageParcel & data,std::vector<RunningFormInfo> & runningFormInfos)897 ErrCode FormMgrProxy::GetRunningFormInfos(IFormMgr::Message code, MessageParcel &data,
898     std::vector<RunningFormInfo> &runningFormInfos)
899 {
900     ErrCode error;
901     MessageParcel reply;
902     MessageOption option(MessageOption::TF_SYNC);
903     error = SendTransactCmd(code, data, reply, option);
904     if (error != ERR_OK) {
905         return error;
906     }
907 
908     error = reply.ReadInt32();
909     if (error != ERR_OK) {
910         HILOG_ERROR("read replyResult failed");
911         return error;
912     }
913     return GetParcelableInfos<RunningFormInfo>(reply, runningFormInfos);
914 }
915 
916 template<typename T>
GetParcelableInfo(IFormMgr::Message code,MessageParcel & data,T & parcelableInfo)917 int FormMgrProxy::GetParcelableInfo(IFormMgr::Message code, MessageParcel &data, T &parcelableInfo)
918 {
919     int error;
920     MessageParcel reply;
921     MessageOption option(MessageOption::TF_SYNC);
922     error = SendTransactCmd(code, data, reply, option);
923     if (error != ERR_OK) {
924         return error;
925     }
926 
927     error = reply.ReadInt32();
928     if (error != ERR_OK) {
929         HILOG_ERROR("read reply result failed");
930         return error;
931     }
932 
933     std::unique_ptr<T> info(reply.ReadParcelable<T>());
934     if (!info) {
935         HILOG_ERROR("readParcelableInfo failed");
936         return ERR_APPEXECFWK_PARCEL_ERROR;
937     }
938     parcelableInfo = *info;
939     HILOG_DEBUG("get parcelable info success");
940     return ERR_OK;
941 }
942 
SendTransactCmd(IFormMgr::Message code,MessageParcel & data,MessageParcel & reply,MessageOption & option)943 int FormMgrProxy::SendTransactCmd(IFormMgr::Message code, MessageParcel &data,
944                                   MessageParcel &reply, MessageOption &option)
945 {
946     sptr<IRemoteObject> remote = Remote();
947     if (!remote) {
948         HILOG_ERROR("error to get remote object, cmd:%{public}d", code);
949         return ERR_APPEXECFWK_SERVICE_NOT_CONNECTED;
950     }
951     int32_t result = remote->SendRequest(static_cast<uint32_t>(code), data, reply, option);
952     if (result != ERR_OK) {
953         HILOG_ERROR("error to SendRequest:%{public}d,cmd:%{public}d", result, code);
954         return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
955     }
956     return ERR_OK;
957 }
958 
959 /**
960  * @brief Delete the invalid forms.
961  * @param formIds Indicates the ID of the valid forms.
962  * @param callerToken Caller ability token.
963  * @param numFormsDeleted Returns the number of the deleted forms.
964  * @return Returns ERR_OK on success, others on failure.
965  */
DeleteInvalidForms(const std::vector<int64_t> & formIds,const sptr<IRemoteObject> & callerToken,int32_t & numFormsDeleted)966 int FormMgrProxy::DeleteInvalidForms(const std::vector<int64_t> &formIds, const sptr<IRemoteObject> &callerToken,
967                                      int32_t &numFormsDeleted)
968 {
969     MessageParcel data;
970     if (!WriteInterfaceToken(data)) {
971         HILOG_ERROR("write interface token failed");
972         return ERR_APPEXECFWK_PARCEL_ERROR;
973     }
974     if (!data.WriteInt64Vector(formIds)) {
975         HILOG_ERROR("write vector formIds failed");
976         return ERR_APPEXECFWK_PARCEL_ERROR;
977     }
978     if (!data.WriteRemoteObject(callerToken)) {
979         HILOG_ERROR("error to write callerToken");
980         return ERR_APPEXECFWK_PARCEL_ERROR;
981     }
982 
983     MessageParcel reply;
984     MessageOption option;
985     int error = SendTransactCmd(
986         IFormMgr::Message::FORM_MGR_DELETE_INVALID_FORMS,
987         data,
988         reply,
989         option);
990     if (error != ERR_OK) {
991         HILOG_ERROR("SendRequest:%{public}d failed", error);
992         return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
993     }
994 
995     int32_t result = reply.ReadInt32();
996     if (result != ERR_OK) {
997         HILOG_ERROR("read reply result failed");
998         return result;
999     }
1000     numFormsDeleted = reply.ReadInt32();
1001     return result;
1002 }
1003 
1004 /**
1005  * @brief Acquire form state info by passing a set of parameters (using Want) to the form provider.
1006  * @param want Indicates a set of parameters to be transparently passed to the form provider.
1007  * @param callerToken Caller ability token.
1008  * @param stateInfo Returns the form's state info of the specify.
1009  * @return Returns ERR_OK on success, others on failure.
1010  */
AcquireFormState(const Want & want,const sptr<IRemoteObject> & callerToken,FormStateInfo & stateInfo)1011 int FormMgrProxy::AcquireFormState(const Want &want, const sptr<IRemoteObject> &callerToken, FormStateInfo &stateInfo)
1012 {
1013     MessageParcel data;
1014     if (!WriteInterfaceToken(data)) {
1015         HILOG_ERROR("write interface token failed");
1016         return ERR_APPEXECFWK_PARCEL_ERROR;
1017     }
1018     if (!data.WriteParcelable(&want)) {
1019         HILOG_ERROR("write want failed");
1020         return ERR_APPEXECFWK_PARCEL_ERROR;
1021     }
1022     if (!data.WriteRemoteObject(callerToken)) {
1023         HILOG_ERROR("write callerToken failed");
1024         return ERR_APPEXECFWK_PARCEL_ERROR;
1025     }
1026 
1027     MessageParcel reply;
1028     MessageOption option;
1029     int error = SendTransactCmd(
1030         IFormMgr::Message::FORM_MGR_ACQUIRE_FORM_STATE,
1031         data,
1032         reply,
1033         option);
1034     if (error != ERR_OK) {
1035         HILOG_ERROR("SendRequest:%{public}d failed", error);
1036         return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
1037     }
1038 
1039     int32_t result = reply.ReadInt32();
1040     if (result != ERR_OK) {
1041         HILOG_ERROR("read reply result failed");
1042         return result;
1043     }
1044     stateInfo.state = (FormState)reply.ReadInt32();
1045     stateInfo.want = want;
1046     return result;
1047 }
1048 
1049 /**
1050  * @brief Notify the form is visible or not.
1051  * @param formIds Indicates the ID of the forms.
1052  * @param isVisible Visible or not.
1053  * @param callerToken Host client.
1054  * @return Returns ERR_OK on success, others on failure.
1055  */
NotifyFormsVisible(const std::vector<int64_t> & formIds,bool isVisible,const sptr<IRemoteObject> & callerToken)1056 int FormMgrProxy::NotifyFormsVisible(const std::vector<int64_t> &formIds, bool isVisible,
1057                                      const sptr<IRemoteObject> &callerToken)
1058 {
1059     MessageParcel data;
1060     if (!WriteInterfaceToken(data)) {
1061         HILOG_ERROR("error to write interface token");
1062         return ERR_APPEXECFWK_PARCEL_ERROR;
1063     }
1064     if (!data.WriteInt64Vector(formIds)) {
1065         HILOG_ERROR("error to write vector formIds");
1066         return ERR_APPEXECFWK_PARCEL_ERROR;
1067     }
1068     if (!data.WriteBool(isVisible)) {
1069         HILOG_ERROR("fail write bool isVisible");
1070         return ERR_APPEXECFWK_PARCEL_ERROR;
1071     }
1072     if (!data.WriteRemoteObject(callerToken)) {
1073         HILOG_ERROR("write to callerToken failed ");
1074         return ERR_APPEXECFWK_PARCEL_ERROR;
1075     }
1076 
1077     MessageParcel reply;
1078     MessageOption option;
1079     int error = SendTransactCmd(
1080         IFormMgr::Message::FORM_MGR_NOTIFY_FORMS_VISIBLE,
1081         data,
1082         reply,
1083         option);
1084     if (error != ERR_OK) {
1085         HILOG_ERROR("SendRequest:%{public}d failed", error);
1086         return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
1087     }
1088 
1089     int32_t result = reply.ReadInt32();
1090     if (result != ERR_OK) {
1091         HILOG_ERROR("read reply result failed");
1092         return result;
1093     }
1094     return result;
1095 }
1096 
NotifyFormsPrivacyProtected(const std::vector<int64_t> & formIds,bool isProtected,const sptr<IRemoteObject> & callerToken)1097 int FormMgrProxy::NotifyFormsPrivacyProtected(const std::vector<int64_t> &formIds, bool isProtected,
1098                                               const sptr<IRemoteObject> &callerToken)
1099 {
1100     MessageParcel data;
1101     if (!WriteInterfaceToken(data)) {
1102         HILOG_ERROR("write interface token failed");
1103         return ERR_APPEXECFWK_PARCEL_ERROR;
1104     }
1105     if (!data.WriteInt64Vector(formIds)) {
1106         HILOG_ERROR("write vector formIds failed");
1107         return ERR_APPEXECFWK_PARCEL_ERROR;
1108     }
1109     if (!data.WriteBool(isProtected)) {
1110         HILOG_ERROR("fail write bool isProtected");
1111         return ERR_APPEXECFWK_PARCEL_ERROR;
1112     }
1113     if (!data.WriteRemoteObject(callerToken)) {
1114         HILOG_ERROR("write callerToken error");
1115         return ERR_APPEXECFWK_PARCEL_ERROR;
1116     }
1117 
1118     MessageParcel reply;
1119     MessageOption option;
1120     int error = SendTransactCmd(
1121         IFormMgr::Message::FORM_MGR_NOTIFY_FORMS_PRIVACY_PROTECTED,
1122         data,
1123         reply,
1124         option);
1125     if (error != ERR_OK) {
1126         HILOG_ERROR("SendRequest:%{public}d failed", error);
1127         return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
1128     }
1129 
1130     int32_t result = reply.ReadInt32();
1131     if (result != ERR_OK) {
1132         HILOG_ERROR("read reply result failed");
1133         return result;
1134     }
1135     return result;
1136 }
1137 
1138 /**
1139  * @brief Notify the form is enable to be updated or not.
1140  * @param formIds Indicates the ID of the forms.
1141  * @param isEnableUpdate enable update or not.
1142  * @param callerToken Host client.
1143  * @return Returns ERR_OK on success, others on failure.
1144  */
NotifyFormsEnableUpdate(const std::vector<int64_t> & formIds,bool isEnableUpdate,const sptr<IRemoteObject> & callerToken)1145 int FormMgrProxy::NotifyFormsEnableUpdate(const std::vector<int64_t> &formIds, bool isEnableUpdate,
1146                                           const sptr<IRemoteObject> &callerToken)
1147 {
1148     MessageParcel data;
1149     if (!WriteInterfaceToken(data)) {
1150         HILOG_ERROR("write interface token failed");
1151         return ERR_APPEXECFWK_PARCEL_ERROR;
1152     }
1153     if (!data.WriteInt64Vector(formIds)) {
1154         HILOG_ERROR("write vector formIds failed");
1155         return ERR_APPEXECFWK_PARCEL_ERROR;
1156     }
1157     if (!data.WriteBool(isEnableUpdate)) {
1158         HILOG_ERROR("write bool isEnableUpdate failed");
1159         return ERR_APPEXECFWK_PARCEL_ERROR;
1160     }
1161     if (!data.WriteRemoteObject(callerToken)) {
1162         HILOG_ERROR("write error to callerToken");
1163         return ERR_APPEXECFWK_PARCEL_ERROR;
1164     }
1165 
1166     MessageParcel reply;
1167     MessageOption option;
1168     int error = SendTransactCmd(
1169         IFormMgr::Message::FORM_MGR_NOTIFY_FORMS_ENABLE_UPDATE,
1170         data,
1171         reply,
1172         option);
1173     if (error != ERR_OK) {
1174         HILOG_ERROR("SendRequest:%{public}d failed", error);
1175         return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
1176     }
1177 
1178     int32_t result = reply.ReadInt32();
1179     if (result != ERR_OK) {
1180         HILOG_ERROR("read reply result failed");
1181         return result;
1182     }
1183     return result;
1184 }
1185 
1186 /**
1187  * @brief Get All FormsInfo.
1188  * @param formInfos Return the forms' information of all forms provided.
1189  * @return Returns ERR_OK on success, others on failure.
1190  */
GetAllFormsInfo(std::vector<FormInfo> & formInfos)1191 int FormMgrProxy::GetAllFormsInfo(std::vector<FormInfo> &formInfos)
1192 {
1193     MessageParcel data;
1194     if (!WriteInterfaceToken(data)) {
1195         HILOG_ERROR("write interface token failed");
1196         return ERR_APPEXECFWK_PARCEL_ERROR;
1197     }
1198 
1199     int error = GetFormsInfo(IFormMgr::Message::FORM_MGR_GET_ALL_FORMS_INFO, data, formInfos);
1200     if (error != ERR_OK) {
1201         HILOG_ERROR("fail GetAllFormsInfo:%{public}d", error);
1202     }
1203 
1204     return error;
1205 }
1206 
1207 /**
1208  * @brief Get forms info by bundle name .
1209  * @param bundleName Application name.
1210  * @param formInfos Return the forms' information of the specify application name.
1211  * @return Returns ERR_OK on success, others on failure.
1212  */
GetFormsInfoByApp(std::string & bundleName,std::vector<FormInfo> & formInfos)1213 int FormMgrProxy::GetFormsInfoByApp(std::string &bundleName, std::vector<FormInfo> &formInfos)
1214 {
1215     HILOG_INFO("bundleName:%{public}s", bundleName.c_str());
1216     MessageParcel data;
1217     if (!WriteInterfaceToken(data)) {
1218         HILOG_ERROR("write interface token failed");
1219         return ERR_APPEXECFWK_PARCEL_ERROR;
1220     }
1221 
1222     if (!data.WriteString(bundleName)) {
1223         HILOG_ERROR("write bundleName failed");
1224         return ERR_APPEXECFWK_PARCEL_ERROR;
1225     }
1226 
1227     int error = GetFormsInfo(IFormMgr::Message::FORM_MGR_GET_FORMS_INFO_BY_APP, data, formInfos);
1228     if (error != ERR_OK) {
1229         HILOG_ERROR("fail GetFormsInfoByApp:%{public}d", error);
1230     }
1231 
1232     return error;
1233 }
1234 
1235 /**
1236  * @brief Get forms info by bundle name and module name.
1237  * @param bundleName bundle name.
1238  * @param moduleName Module name of hap.
1239  * @param formInfos Return the forms' information of the specify bundle name and module name.
1240  * @return Returns ERR_OK on success, others on failure.
1241  */
GetFormsInfoByModule(std::string & bundleName,std::string & moduleName,std::vector<FormInfo> & formInfos)1242 int FormMgrProxy::GetFormsInfoByModule(std::string &bundleName, std::string &moduleName,
1243                                        std::vector<FormInfo> &formInfos)
1244 {
1245     MessageParcel data;
1246     if (!WriteInterfaceToken(data)) {
1247         HILOG_ERROR("write interface token failed");
1248         return ERR_APPEXECFWK_PARCEL_ERROR;
1249     }
1250 
1251     if (!data.WriteString(bundleName)) {
1252         HILOG_ERROR("write bundleName failed");
1253         return ERR_APPEXECFWK_PARCEL_ERROR;
1254     }
1255 
1256     if (!data.WriteString(moduleName)) {
1257         HILOG_ERROR("fail write moduleName");
1258         return ERR_APPEXECFWK_PARCEL_ERROR;
1259     }
1260 
1261     int error = GetFormsInfo(IFormMgr::Message::FORM_MGR_GET_FORMS_INFO_BY_MODULE, data, formInfos);
1262     if (error != ERR_OK) {
1263         HILOG_ERROR("fail GetFormsInfoByModule:%{public}d", error);
1264     }
1265 
1266     return error;
1267 }
1268 
GetFormsInfoByFilter(const FormInfoFilter & filter,std::vector<FormInfo> & formInfos)1269 int FormMgrProxy::GetFormsInfoByFilter(const FormInfoFilter &filter, std::vector<FormInfo> &formInfos)
1270 {
1271     MessageParcel data;
1272     if (!WriteInterfaceToken(data)) {
1273         HILOG_ERROR("write interface token failed");
1274         return ERR_APPEXECFWK_PARCEL_ERROR;
1275     }
1276 
1277     if (!data.WriteString(filter.bundleName)) {
1278         HILOG_ERROR("write bundleName failed");
1279         return ERR_APPEXECFWK_PARCEL_ERROR;
1280     }
1281 
1282     if (!data.WriteString(filter.moduleName)) {
1283         HILOG_ERROR("write moduleName failed");
1284         return ERR_APPEXECFWK_PARCEL_ERROR;
1285     }
1286 
1287     if (!data.WriteInt32Vector(filter.supportDimensions)) {
1288         HILOG_ERROR("fail write vector supportDimensions");
1289         return ERR_APPEXECFWK_PARCEL_ERROR;
1290     }
1291 
1292     if (!data.WriteInt32Vector(filter.supportShapes)) {
1293         HILOG_ERROR("fail write vector supportShapes");
1294         return ERR_APPEXECFWK_PARCEL_ERROR;
1295     }
1296 
1297     int error = GetFormsInfo(IFormMgr::Message::FORM_MGR_GET_FORMS_INFO_BY_FILTER, data, formInfos);
1298     if (error != ERR_OK) {
1299         HILOG_ERROR("fail GetFormsInfoByFilter:%{public}d", error);
1300     }
1301 
1302     return error;
1303 }
1304 
GetRunningFormInfos(bool isUnusedInclude,std::vector<RunningFormInfo> & runningFormInfos)1305 ErrCode FormMgrProxy::GetRunningFormInfos(bool isUnusedInclude, std::vector<RunningFormInfo> &runningFormInfos)
1306 {
1307     MessageParcel data;
1308     if (!WriteInterfaceToken(data)) {
1309         HILOG_ERROR("write interface token failed");
1310         return ERR_APPEXECFWK_PARCEL_ERROR;
1311     }
1312 
1313     if (!data.WriteBool(isUnusedInclude)) {
1314         HILOG_ERROR("write isUnusedInclude failed");
1315         return ERR_APPEXECFWK_PARCEL_ERROR;
1316     }
1317 
1318     ErrCode error = GetRunningFormInfos(IFormMgr::Message::FORM_MGR_GET_RUNNING_FORM_INFOS, data, runningFormInfos);
1319     if (error != ERR_OK) {
1320         HILOG_ERROR("fail GetRunningFormInfos:%{public}d", error);
1321     }
1322     return error;
1323 }
1324 
GetRunningFormInfosByBundleName(const std::string & bundleName,bool isUnusedInclude,std::vector<RunningFormInfo> & runningFormInfos)1325 ErrCode FormMgrProxy::GetRunningFormInfosByBundleName(
1326     const std::string &bundleName, bool isUnusedInclude, std::vector<RunningFormInfo> &runningFormInfos)
1327 {
1328     MessageParcel data;
1329     if (!WriteInterfaceToken(data)) {
1330         HILOG_ERROR("write interface token failed");
1331         return ERR_APPEXECFWK_PARCEL_ERROR;
1332     }
1333 
1334     if (!data.WriteString(bundleName)) {
1335         HILOG_ERROR("write bundleName failed");
1336         return ERR_APPEXECFWK_PARCEL_ERROR;
1337     }
1338 
1339     if (!data.WriteBool(isUnusedInclude)) {
1340         HILOG_ERROR("write isUnusedInclude failed");
1341         return ERR_APPEXECFWK_PARCEL_ERROR;
1342     }
1343 
1344     ErrCode error = GetRunningFormInfos(IFormMgr::Message::FORM_MGR_GET_RUNNING_FORM_INFOS_BY_BUNDLE,
1345         data, runningFormInfos);
1346     if (error != ERR_OK) {
1347         HILOG_ERROR("fail GetRunningFormInfosByBundleName:%{public}d", error);
1348     }
1349     return error;
1350 }
1351 
GetFormsInfo(const FormInfoFilter & filter,std::vector<FormInfo> & formInfos)1352 int32_t FormMgrProxy::GetFormsInfo(const FormInfoFilter &filter, std::vector<FormInfo> &formInfos)
1353 {
1354     HILOG_INFO("start");
1355     MessageParcel data;
1356     // write in token to help identify which stub to be called.
1357     if (!WriteInterfaceToken(data)) {
1358         HILOG_ERROR("write interface token failed");
1359         return ERR_APPEXECFWK_PARCEL_ERROR;
1360     }
1361     if (!data.WriteParcelable(&filter)) {
1362         HILOG_ERROR("fail write FormInfoFilter");
1363         return ERR_APPEXECFWK_PARCEL_ERROR;
1364     }
1365     // call private GetFormsInfo with Message which will send request to tell stub which handle function to be used.
1366     int error = GetFormsInfo(IFormMgr::Message::FORM_MGR_GET_FORMS_INFO, data, formInfos);
1367     // formInfos should have been fulfilled at this point.
1368     if (error != ERR_OK) {
1369         HILOG_ERROR("fail GetAllFormsInfo:%{public}d", error);
1370     }
1371 
1372     return error;
1373 }
1374 
IsRequestPublishFormSupported()1375 bool FormMgrProxy::IsRequestPublishFormSupported()
1376 {
1377     HILOG_INFO("start");
1378     MessageParcel data;
1379     // write in token to help identify which stub to be called.
1380     if (!WriteInterfaceToken(data)) {
1381         HILOG_ERROR("error to write interface token");
1382         return false;
1383     }
1384     // send request.
1385     MessageParcel reply;
1386     MessageOption option;
1387     int error = SendTransactCmd(
1388         IFormMgr::Message::FORM_MGR_IS_REQUEST_PUBLISH_FORM_SUPPORTED,
1389         data,
1390         reply,
1391         option);
1392     if (error != ERR_OK) {
1393         HILOG_ERROR("SendRequest:%{public}d failed", error);
1394         return false;
1395     }
1396     // retrieve and return result.
1397     return reply.ReadBool();
1398 }
1399 
StartAbility(const Want & want,const sptr<IRemoteObject> & callerToken)1400 int32_t FormMgrProxy::StartAbility(const Want &want, const sptr<IRemoteObject> &callerToken)
1401 {
1402     HILOG_INFO("start");
1403     MessageParcel data;
1404     // write in token to help identify which stub to be called.
1405     if (!WriteInterfaceToken(data)) {
1406         HILOG_ERROR("write interface token failed");
1407         return ERR_APPEXECFWK_PARCEL_ERROR;
1408     }
1409     // write in want
1410     if (!data.WriteParcelable(&want)) {
1411         HILOG_ERROR("write want failed");
1412         return ERR_APPEXECFWK_PARCEL_ERROR;
1413     }
1414     // write in callerToken
1415     if (!data.WriteRemoteObject(callerToken)) {
1416         HILOG_ERROR("write callerToken failed");
1417         return ERR_APPEXECFWK_PARCEL_ERROR;
1418     }
1419     // send request.
1420     MessageParcel reply;
1421     MessageOption option;
1422     int error = SendTransactCmd(
1423         IFormMgr::Message::FORM_MGR_START_ABILITY,
1424         data,
1425         reply,
1426         option);
1427     if (error != ERR_OK) {
1428         HILOG_ERROR("SendRequest:%{public}d failed", error);
1429         return error;
1430     }
1431     // retrieve and return result.
1432     return reply.ReadInt32();
1433 }
1434 
ShareForm(int64_t formId,const std::string & deviceId,const sptr<IRemoteObject> & callerToken,int64_t requestCode)1435 int32_t FormMgrProxy::ShareForm(int64_t formId, const std::string &deviceId, const sptr<IRemoteObject> &callerToken,
1436     int64_t requestCode)
1437 {
1438     MessageParcel data;
1439     if (!WriteInterfaceToken(data)) {
1440         HILOG_ERROR("error to write interface token");
1441         return ERR_APPEXECFWK_PARCEL_ERROR;
1442     }
1443 
1444     if (!data.WriteInt64(formId)) {
1445         HILOG_ERROR("error to write formId");
1446         return ERR_APPEXECFWK_PARCEL_ERROR;
1447     }
1448 
1449     if (!data.WriteString(deviceId)) {
1450         HILOG_ERROR("fail write deviceId");
1451         return ERR_APPEXECFWK_PARCEL_ERROR;
1452     }
1453 
1454     if (!data.WriteRemoteObject(callerToken)) {
1455         HILOG_ERROR("write callerToken failed");
1456         return ERR_APPEXECFWK_PARCEL_ERROR;
1457     }
1458 
1459     if (!data.WriteInt64(requestCode)) {
1460         HILOG_ERROR("write requestCode failed");
1461         return ERR_APPEXECFWK_PARCEL_ERROR;
1462     }
1463 
1464     MessageParcel reply;
1465     MessageOption option;
1466     auto error = SendTransactCmd(
1467         IFormMgr::Message::FORM_MGR_SHARE_FORM, data, reply, option);
1468     if (error != ERR_OK) {
1469         HILOG_ERROR("SendRequest:%{public}d failed", error);
1470         return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
1471     }
1472     return reply.ReadInt32();
1473 }
1474 
AcquireFormData(int64_t formId,int64_t requestCode,const sptr<IRemoteObject> & callerToken,AAFwk::WantParams & formData)1475 int32_t FormMgrProxy::AcquireFormData(int64_t formId, int64_t requestCode, const sptr<IRemoteObject> &callerToken,
1476     AAFwk::WantParams &formData)
1477 {
1478     MessageParcel data;
1479     if (!WriteInterfaceToken(data)) {
1480         HILOG_ERROR("write interface token failed");
1481         return ERR_APPEXECFWK_PARCEL_ERROR;
1482     }
1483 
1484     if (!data.WriteInt64(formId)) {
1485         HILOG_ERROR("write formId failed");
1486         return ERR_APPEXECFWK_PARCEL_ERROR;
1487     }
1488 
1489     if (!data.WriteInt64(requestCode)) {
1490         HILOG_ERROR("write requestCode failed");
1491         return ERR_APPEXECFWK_PARCEL_ERROR;
1492     }
1493 
1494     if (!data.WriteRemoteObject(callerToken)) {
1495         HILOG_ERROR("write callerToken failed");
1496         return ERR_APPEXECFWK_PARCEL_ERROR;
1497     }
1498 
1499     int error;
1500     MessageParcel reply;
1501     MessageOption option(MessageOption::TF_SYNC);
1502     error = SendTransactCmd(IFormMgr::Message::FORM_MGR_ACQUIRE_DATA, data, reply, option);
1503     if (error != ERR_OK) {
1504         return error;
1505     }
1506 
1507     error = reply.ReadInt32();
1508     if (error != ERR_OK) {
1509         HILOG_ERROR("read replyResult failed");
1510         return error;
1511     }
1512     std::shared_ptr<AAFwk::WantParams> wantParams(reply.ReadParcelable<AAFwk::WantParams>());
1513     if (wantParams == nullptr) {
1514         HILOG_ERROR("ReadParcelable<wantParams> failed");
1515         return ERR_APPEXECFWK_PARCEL_ERROR;
1516     }
1517     formData = *wantParams;
1518     return ERR_OK;
1519 }
1520 
RecvFormShareInfoFromRemote(const FormShareInfo & info)1521 int32_t FormMgrProxy::RecvFormShareInfoFromRemote(const FormShareInfo &info)
1522 {
1523     MessageParcel data;
1524     if (!WriteInterfaceToken(data)) {
1525         HILOG_ERROR("write interface token failed");
1526         return ERR_APPEXECFWK_PARCEL_ERROR;
1527     }
1528 
1529     if (!data.WriteParcelable(&info)) {
1530         HILOG_ERROR("fail write form share info");
1531         return ERR_APPEXECFWK_PARCEL_ERROR;
1532     }
1533 
1534     MessageParcel reply;
1535     MessageOption option;
1536     auto error = SendTransactCmd(
1537         IFormMgr::Message::FORM_MGR_RECV_FORM_SHARE_INFO_FROM_REMOTE, data, reply, option);
1538     if (error != ERR_OK) {
1539         HILOG_ERROR("SendRequest:%{public}d failed", error);
1540         return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
1541     }
1542     return reply.ReadInt32();
1543 }
1544 
CheckFMSReady()1545 bool FormMgrProxy::CheckFMSReady()
1546 {
1547     HILOG_DEBUG("start");
1548     MessageParcel data;
1549     // write in token to help identify which stub to be called
1550     if (!WriteInterfaceToken(data)) {
1551         HILOG_ERROR("write interface token failed");
1552         return false;
1553     }
1554     // send request
1555     MessageParcel reply;
1556     MessageOption option;
1557     int error = SendTransactCmd(
1558         IFormMgr::Message::FORM_MGR_CHECK_FMS_READY, data, reply, option);
1559     if (error != ERR_OK) {
1560         HILOG_ERROR("SendRequest:%{public}d failed", error);
1561         return false;
1562     }
1563     // retrieve and return result;
1564     return reply.ReadBool();
1565 }
1566 
IsSystemAppForm(const std::string & bundleName)1567 bool FormMgrProxy::IsSystemAppForm(const std::string &bundleName)
1568 {
1569     MessageParcel data;
1570     // write in token to help identify which stub to be called
1571     if (!WriteInterfaceToken(data)) {
1572         HILOG_ERROR("write interface token failed");
1573         return false;
1574     }
1575     if (!data.WriteString(bundleName)) {
1576         HILOG_ERROR("write bundleName failed");
1577         return false;
1578     }
1579     MessageParcel reply;
1580     MessageOption option;
1581     int error = SendTransactCmd(IFormMgr::Message::FORM_MGR_IS_SYSTEM_APP_FORM, data, reply, option);
1582     if (error != ERR_OK) {
1583         HILOG_ERROR("SendTransactCmd:%{public}d failed", error);
1584         return false;
1585     }
1586     return reply.ReadBool();
1587 }
1588 
SetBackgroundFunction(const std::string funcName,const std::string params)1589 int32_t FormMgrProxy::SetBackgroundFunction(const std::string funcName, const std::string params)
1590 {
1591     HILOG_DEBUG("start");
1592     MessageParcel data;
1593     // write in token to help identify which stub to be called
1594     if (!data.WriteString16(Str8ToStr16(funcName))) {
1595         HILOG_ERROR("write funcName failed");
1596         return ERR_APPEXECFWK_PARCEL_ERROR;
1597     }
1598     if (!data.WriteString16(Str8ToStr16(params))) {
1599         HILOG_ERROR("write params failed");
1600         return ERR_APPEXECFWK_PARCEL_ERROR;
1601     }
1602     // send request
1603     MessageParcel reply;
1604     MessageOption option;
1605     sptr<IRemoteObject> remote = Remote();
1606     if (!remote) {
1607         HILOG_ERROR("get remoteObject failed");
1608         return ERR_APPEXECFWK_SERVICE_NOT_CONNECTED;
1609     }
1610     int error = remote->SendRequest(Constants::EVENT_CALL_NOTIFY, data, reply, option);
1611     if (error != ERR_OK) {
1612         HILOG_ERROR("SendRequest:%{public}d failed", error);
1613         return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
1614     }
1615     // retrieve and return result;
1616     return reply.ReadInt32();
1617 }
1618 
GetFormsCount(bool isTempFormFlag,int32_t & formCount)1619 int32_t FormMgrProxy::GetFormsCount(bool isTempFormFlag, int32_t &formCount)
1620 {
1621     HILOG_INFO("start");
1622     MessageParcel data;
1623     if (!WriteInterfaceToken(data)) {
1624         HILOG_ERROR("write interface token failed");
1625         return ERR_APPEXECFWK_PARCEL_ERROR;
1626     }
1627     if (!data.WriteBool(isTempFormFlag)) {
1628         HILOG_ERROR("write bool isEnableUpdate failed");
1629         return ERR_APPEXECFWK_PARCEL_ERROR;
1630     }
1631     MessageParcel reply;
1632     MessageOption option;
1633     int error = SendTransactCmd(
1634         IFormMgr::Message::FORM_MGR_GET_FORMS_COUNT, data, reply, option);
1635     if (error != ERR_OK) {
1636         HILOG_ERROR("SendRequest:%{public}d failed", error);
1637         return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
1638     }
1639     int32_t result = reply.ReadInt32();
1640     formCount = reply.ReadInt32();
1641     return result;
1642 }
1643 
RegisterFormAddObserverByBundle(const std::string bundleName,const sptr<IRemoteObject> & callerToken)1644 ErrCode FormMgrProxy::RegisterFormAddObserverByBundle(const std::string bundleName,
1645     const sptr<IRemoteObject> &callerToken)
1646 {
1647     HILOG_DEBUG("RegisterFormAddObserverByBundle start");
1648     MessageParcel data;
1649     if (!WriteInterfaceToken(data)) {
1650         HILOG_ERROR("write interface token failed");
1651         return ERR_APPEXECFWK_PARCEL_ERROR;
1652     }
1653 
1654     if (!data.WriteString(bundleName)) {
1655         HILOG_ERROR("error to write bundleName");
1656         return ERR_APPEXECFWK_PARCEL_ERROR;
1657     }
1658 
1659     if (!data.WriteRemoteObject(callerToken)) {
1660         HILOG_ERROR("write callerToken failed");
1661         return ERR_APPEXECFWK_PARCEL_ERROR;
1662     }
1663 
1664     MessageParcel reply;
1665     MessageOption option(MessageOption::TF_ASYNC);
1666     auto error = SendTransactCmd(
1667         IFormMgr::Message::FORM_MGR_REGISTER_FORM_ADD_OBSERVER_BY_BUNDLE, data, reply, option);
1668     if (error != ERR_OK) {
1669         HILOG_ERROR("SendRequest:%{public}d failed", error);
1670         return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
1671     }
1672     return reply.ReadInt32();
1673 }
1674 
RegisterFormRemoveObserverByBundle(const std::string bundleName,const sptr<IRemoteObject> & callerToken)1675 ErrCode FormMgrProxy::RegisterFormRemoveObserverByBundle(const std::string bundleName,
1676     const sptr<IRemoteObject> &callerToken)
1677 {
1678     HILOG_DEBUG("start");
1679     MessageParcel data;
1680     if (!WriteInterfaceToken(data)) {
1681         HILOG_ERROR("write interface token failed");
1682         return ERR_APPEXECFWK_PARCEL_ERROR;
1683     }
1684 
1685     if (!data.WriteString(bundleName)) {
1686         HILOG_ERROR("write bundleName failed");
1687         return ERR_APPEXECFWK_PARCEL_ERROR;
1688     }
1689 
1690     if (!data.WriteRemoteObject(callerToken)) {
1691         HILOG_ERROR("write callerToken failed");
1692         return ERR_APPEXECFWK_PARCEL_ERROR;
1693     }
1694 
1695     MessageParcel reply;
1696     MessageOption option(MessageOption::TF_ASYNC);
1697     auto error = SendTransactCmd(
1698         IFormMgr::Message::FORM_MGR_REGISTER_FORM_REMOVE_OBSERVER_BY_BUNDLE,
1699         data, reply, option);
1700     if (error != ERR_OK) {
1701         HILOG_ERROR("SendRequest:%{public}d failed", error);
1702         return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
1703     }
1704     return reply.ReadInt32();
1705 }
1706 
GetHostFormsCount(std::string & bundleName,int32_t & formCount)1707 int32_t FormMgrProxy::GetHostFormsCount(std::string &bundleName, int32_t &formCount)
1708 {
1709     HILOG_INFO("start");
1710     MessageParcel data;
1711     if (!WriteInterfaceToken(data)) {
1712         HILOG_ERROR("write interface token failed");
1713         return ERR_APPEXECFWK_PARCEL_ERROR;
1714     }
1715     if (!data.WriteString(bundleName)) {
1716         HILOG_ERROR("write bundleName failed");
1717         return ERR_APPEXECFWK_PARCEL_ERROR;
1718     }
1719     MessageParcel reply;
1720     MessageOption option;
1721     int error = SendTransactCmd(
1722         IFormMgr::Message::FORM_MGR_GET_HOST_FORMS_COUNT, data, reply, option);
1723     if (error != ERR_OK) {
1724         HILOG_ERROR("SendRequest:%{public}d failed", error);
1725         return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
1726     }
1727     int32_t result = reply.ReadInt32();
1728     formCount = reply.ReadInt32();
1729     return result;
1730 }
1731 
GetFormInstancesByFilter(const FormInstancesFilter & formInstancesFilter,std::vector<FormInstance> & formInstances)1732 int32_t FormMgrProxy::GetFormInstancesByFilter(const FormInstancesFilter &formInstancesFilter,
1733     std::vector<FormInstance> &formInstances)
1734 {
1735     HILOG_DEBUG("start");
1736     MessageParcel data;
1737     // write in token to help identify which stub to be called.
1738     if (!WriteInterfaceToken(data)) {
1739         HILOG_ERROR("write interface token failed");
1740         return ERR_APPEXECFWK_PARCEL_ERROR;
1741     }
1742     if (!data.WriteParcelable(&formInstancesFilter)) {
1743         HILOG_ERROR("fail write formInstancesFilter");
1744         return ERR_APPEXECFWK_PARCEL_ERROR;
1745     }
1746     auto error = GetFormInstance(IFormMgr::Message::FORM_MGR_GET_FORM_INSTANCES_FROM_BY_FILTER, data, formInstances);
1747     if (error != ERR_OK) {
1748         HILOG_ERROR("fail get form instances by filter:%{public}d", error);
1749     }
1750 
1751     return error;
1752 }
1753 
GetFormInstanceById(const int64_t formId,FormInstance & formInstance)1754 ErrCode FormMgrProxy::GetFormInstanceById(const int64_t formId, FormInstance &formInstance)
1755 {
1756     HILOG_DEBUG("GetFormInstanceById start");
1757     MessageParcel data;
1758     // write in token to help identify which stub to be called.
1759     if (!WriteInterfaceToken(data)) {
1760         HILOG_ERROR("error to write interface token");
1761         return ERR_APPEXECFWK_PARCEL_ERROR;
1762     }
1763     if (!data.WriteInt64(formId)) {
1764         HILOG_ERROR("error to write formId");
1765         return ERR_APPEXECFWK_PARCEL_ERROR;
1766     }
1767     auto error = GetParcelableInfo<FormInstance>(IFormMgr::Message::FORM_MGR_GET_FORM_INSTANCES_FROM_BY_ID,
1768         data, formInstance);
1769     if (error != ERR_OK) {
1770         HILOG_ERROR("get parcelable info failed");
1771     }
1772 
1773     return error;
1774 }
1775 
GetFormInstanceById(const int64_t formId,bool isUnusedInclude,FormInstance & formInstance)1776 ErrCode FormMgrProxy::GetFormInstanceById(const int64_t formId, bool isUnusedInclude, FormInstance &formInstance)
1777 {
1778     HILOG_DEBUG("start");
1779     MessageParcel data;
1780     // write in token to help identify which stub to be called.
1781     if (!WriteInterfaceToken(data)) {
1782         HILOG_ERROR("write interface token failed");
1783         return ERR_APPEXECFWK_PARCEL_ERROR;
1784     }
1785     if (!data.WriteInt64(formId)) {
1786         HILOG_ERROR("write formId failed");
1787         return ERR_APPEXECFWK_PARCEL_ERROR;
1788     }
1789     if (!data.WriteBool(isUnusedInclude)) {
1790         HILOG_ERROR("write isUnusedInclude failed");
1791         return ERR_APPEXECFWK_PARCEL_ERROR;
1792     }
1793 
1794     auto error = GetParcelableInfo<FormInstance>(IFormMgr::Message::FORM_MGR_GET_FORM_INSTANCES_FROM_BY_ID,
1795         data, formInstance);
1796     if (error != ERR_OK) {
1797         HILOG_ERROR("get parcelable info failed");
1798     }
1799 
1800     return error;
1801 }
1802 
GetFormInstance(IFormMgr::Message code,MessageParcel & data,std::vector<FormInstance> & formInstances)1803 ErrCode FormMgrProxy::GetFormInstance(IFormMgr::Message code, MessageParcel &data,
1804     std::vector<FormInstance> &formInstances)
1805 {
1806     HILOG_DEBUG("GetFormInstance start");
1807     int error;
1808     MessageParcel reply;
1809     MessageOption option(MessageOption::TF_SYNC);
1810     error = SendTransactCmd(code, data, reply, option);
1811     if (error != ERR_OK) {
1812         return error;
1813     }
1814     error = reply.ReadInt32();
1815     if (error != ERR_OK) {
1816         HILOG_ERROR("read replyResult failed");
1817         return error;
1818     }
1819     auto ret = GetParcelableInfos<FormInstance>(reply, formInstances);
1820     if (ret != ERR_OK) {
1821         HILOG_ERROR("fail get parcelable infos");
1822         return ERR_APPEXECFWK_PARCEL_ERROR;
1823     }
1824     return ret;
1825 }
1826 
RegisterAddObserver(const std::string & bundleName,const sptr<IRemoteObject> & callerToken)1827 ErrCode FormMgrProxy::RegisterAddObserver(const std::string &bundleName, const sptr<IRemoteObject> &callerToken)
1828 {
1829     HILOG_DEBUG("start");
1830     MessageParcel data;
1831     if (!WriteInterfaceToken(data)) {
1832         HILOG_ERROR("error to write interface token");
1833         return ERR_APPEXECFWK_PARCEL_ERROR;
1834     }
1835     if (!data.WriteString(bundleName)) {
1836         HILOG_ERROR("error to write bundleName");
1837         return ERR_APPEXECFWK_PARCEL_ERROR;
1838     }
1839     if (!data.WriteRemoteObject(callerToken)) {
1840         HILOG_ERROR("error to write callerToken");
1841         return ERR_APPEXECFWK_PARCEL_ERROR;
1842     }
1843     MessageParcel reply;
1844     MessageOption option(MessageOption::TF_ASYNC);
1845     auto error = SendTransactCmd(
1846         IFormMgr::Message::FORM_MGR_REGISTER_ADD_OBSERVER, data, reply, option);
1847     if (error != ERR_OK) {
1848         HILOG_ERROR("error to SendRequest:%{public}d", error);
1849         return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
1850     }
1851     return reply.ReadInt32();
1852 }
1853 
RegisterRemoveObserver(const std::string & bundleName,const sptr<IRemoteObject> & callerToken)1854 ErrCode FormMgrProxy::RegisterRemoveObserver(const std::string &bundleName, const sptr<IRemoteObject> &callerToken)
1855 {
1856     HILOG_DEBUG("call");
1857     MessageParcel data;
1858     if (!WriteInterfaceToken(data)) {
1859         HILOG_ERROR("write interface token failed");
1860         return ERR_APPEXECFWK_PARCEL_ERROR;
1861     }
1862     if (!data.WriteString(bundleName)) {
1863         HILOG_ERROR("write bundleName failed");
1864         return ERR_APPEXECFWK_PARCEL_ERROR;
1865     }
1866     if (!data.WriteRemoteObject(callerToken)) {
1867         HILOG_ERROR("write callerToken failed");
1868         return ERR_APPEXECFWK_PARCEL_ERROR;
1869     }
1870     MessageParcel reply;
1871     MessageOption option(MessageOption::TF_ASYNC);
1872     int error = SendTransactCmd(
1873         IFormMgr::Message::FORM_MGR_REGISTER_REMOVE_OBSERVER, data, reply, option);
1874     if (error != ERR_OK) {
1875         HILOG_ERROR("SendRequest:%{public}d failed", error);
1876         return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
1877     }
1878     return reply.ReadInt32();
1879 }
1880 
RegisterFormRouterProxy(const std::vector<int64_t> & formIds,const sptr<IRemoteObject> & callerToken)1881 ErrCode FormMgrProxy::RegisterFormRouterProxy(const std::vector<int64_t> &formIds,
1882     const sptr<IRemoteObject> &callerToken)
1883 {
1884     HILOG_DEBUG("call");
1885     MessageParcel data;
1886     if (!WriteInterfaceToken(data)) {
1887         HILOG_ERROR("write interface token failed");
1888         return ERR_APPEXECFWK_PARCEL_ERROR;
1889     }
1890     if (!data.WriteInt64Vector(formIds)) {
1891         HILOG_ERROR("write vector formIds failed");
1892         return ERR_APPEXECFWK_PARCEL_ERROR;
1893     }
1894     if (!data.WriteRemoteObject(callerToken)) {
1895         HILOG_ERROR("write callerToken failed");
1896         return ERR_APPEXECFWK_PARCEL_ERROR;
1897     }
1898     MessageParcel reply;
1899     MessageOption option;
1900     int error = SendTransactCmd(
1901         IFormMgr::Message::FORM_MGR_REGISTER_FORM_ROUTER_PROXY, data, reply, option);
1902     if (error != ERR_OK) {
1903         HILOG_ERROR("SendRequest:%{public}d failed", error);
1904         return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
1905     }
1906     return reply.ReadInt32();
1907 }
1908 
UnregisterFormRouterProxy(const std::vector<int64_t> & formIds)1909 ErrCode FormMgrProxy::UnregisterFormRouterProxy(const std::vector<int64_t> &formIds)
1910 {
1911     HILOG_DEBUG("call");
1912     MessageParcel data;
1913     if (!WriteInterfaceToken(data)) {
1914         HILOG_ERROR("write interface token failed");
1915         return ERR_APPEXECFWK_PARCEL_ERROR;
1916     }
1917     if (!data.WriteInt64Vector(formIds)) {
1918         HILOG_ERROR("write vector formIds failed");
1919         return ERR_APPEXECFWK_PARCEL_ERROR;
1920     }
1921     MessageParcel reply;
1922     MessageOption option;
1923     int error = SendTransactCmd(
1924         IFormMgr::Message::FORM_MGR_UNREGISTER_FORM_ROUTER_PROXY, data, reply, option);
1925     if (error != ERR_OK) {
1926         HILOG_ERROR("SendRequest:%{public}d failed", error);
1927         return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
1928     }
1929     return reply.ReadInt32();
1930 }
1931 
UpdateProxyForm(int64_t formId,const FormProviderData & FormProviderData,const std::vector<FormDataProxy> & formDataProxies)1932 ErrCode FormMgrProxy::UpdateProxyForm(int64_t formId, const FormProviderData &FormProviderData,
1933     const std::vector<FormDataProxy> &formDataProxies)
1934 {
1935     MessageParcel data;
1936     if (!WriteInterfaceToken(data)) {
1937         HILOG_ERROR("write interface token failed");
1938         return ERR_APPEXECFWK_PARCEL_ERROR;
1939     }
1940     if (!data.WriteInt64(formId)) {
1941         HILOG_ERROR("write formId failed");
1942         return ERR_APPEXECFWK_PARCEL_ERROR;
1943     }
1944     if (!data.WriteParcelable(&FormProviderData)) {
1945         HILOG_ERROR("write formBindingData failed");
1946         return ERR_APPEXECFWK_PARCEL_ERROR;
1947     }
1948     if (!WriteFormDataProxies(data, formDataProxies)) {
1949         HILOG_ERROR("write formDataProxies failed");
1950         return ERR_APPEXECFWK_PARCEL_ERROR;
1951     }
1952     MessageParcel reply;
1953     MessageOption option(MessageOption::TF_SYNC);
1954     int32_t error = SendTransactCmd(IFormMgr::Message::FORM_MGR_UPDATE_PROXY_FORM, data, reply, option);
1955     if (error != ERR_OK) {
1956         HILOG_ERROR("fail SendTransactCmd");
1957         return error;
1958     }
1959     return reply.ReadInt32();
1960 }
1961 
RequestPublishProxyForm(Want & want,bool withFormBindingData,std::unique_ptr<FormProviderData> & formBindingData,int64_t & formId,const std::vector<FormDataProxy> & formDataProxies)1962 ErrCode FormMgrProxy::RequestPublishProxyForm(Want &want, bool withFormBindingData,
1963     std::unique_ptr<FormProviderData> &formBindingData, int64_t &formId,
1964     const std::vector<FormDataProxy> &formDataProxies)
1965 {
1966     MessageParcel data;
1967 
1968     if (!WriteInterfaceToken(data)) {
1969         HILOG_ERROR("write interface token failed");
1970         return ERR_APPEXECFWK_PARCEL_ERROR;
1971     }
1972     if (!data.WriteParcelable(&want)) {
1973         HILOG_ERROR("write want failed");
1974         return ERR_APPEXECFWK_PARCEL_ERROR;
1975     }
1976     if (!data.WriteBool(withFormBindingData)) {
1977         HILOG_ERROR("write withFormBindingData failed");
1978         return ERR_APPEXECFWK_PARCEL_ERROR;
1979     }
1980     if (withFormBindingData) {
1981         if (!data.WriteParcelable(formBindingData.get())) {
1982             HILOG_ERROR("write formBindingData failed");
1983             return ERR_APPEXECFWK_PARCEL_ERROR;
1984         }
1985     }
1986     if (!WriteFormDataProxies(data, formDataProxies)) {
1987         HILOG_ERROR("write formDataProxies failed");
1988         return ERR_APPEXECFWK_PARCEL_ERROR;
1989     }
1990 
1991     MessageParcel reply;
1992     MessageOption option(MessageOption::TF_SYNC);
1993     int32_t error = SendTransactCmd(IFormMgr::Message::FORM_MGR_REQUEST_PUBLISH_PROXY_FORM, data, reply, option);
1994     if (error != ERR_OK) {
1995         HILOG_ERROR("fail SendTransactCmd");
1996         return error;
1997     }
1998     ErrCode errCode = reply.ReadInt32();
1999     if (errCode == ERR_OK) {
2000         formId = reply.ReadInt64();
2001     }
2002     return errCode;
2003 }
2004 
WriteFormDataProxies(MessageParcel & data,const std::vector<FormDataProxy> & formDataProxies)2005 bool FormMgrProxy::WriteFormDataProxies(MessageParcel &data, const std::vector<FormDataProxy> &formDataProxies)
2006 {
2007     HILOG_DEBUG("proxies size:%{public}zu", formDataProxies.size());
2008     if (!data.WriteInt32(formDataProxies.size())) {
2009         HILOG_ERROR("fail marshalling form data proxies size");
2010         return false;
2011     }
2012     for (const auto &formDataProxy : formDataProxies) {
2013         if (!data.WriteString16(Str8ToStr16(formDataProxy.key))) {
2014             HILOG_ERROR("fail marshalling formDataProxy key:%{public}s", formDataProxy.key.c_str());
2015             return false;
2016         }
2017         if (!data.WriteString16(Str8ToStr16(formDataProxy.subscribeId))) {
2018             HILOG_ERROR("fail marshalling formDataProxy subscribeId:%{public}s",
2019                 formDataProxy.subscribeId.c_str());
2020             return false;
2021         }
2022     }
2023     return true;
2024 }
2025 
RegisterPublishFormInterceptor(const sptr<IRemoteObject> & interceptorCallback)2026 int32_t FormMgrProxy::RegisterPublishFormInterceptor(const sptr<IRemoteObject> &interceptorCallback)
2027 {
2028     HILOG_DEBUG("start");
2029     MessageParcel data;
2030     // write in token to help identify which stub to be called.
2031     if (!WriteInterfaceToken(data)) {
2032         HILOG_ERROR("error to write interface token");
2033         return ERR_APPEXECFWK_PARCEL_ERROR;
2034     }
2035     // write in interceptor
2036     if (!data.WriteRemoteObject(interceptorCallback)) {
2037         HILOG_ERROR("error to write interceptor");
2038         return ERR_APPEXECFWK_PARCEL_ERROR;
2039     }
2040     // send request.
2041     MessageParcel reply;
2042     MessageOption option;
2043     int error = SendTransactCmd(
2044         IFormMgr::Message::FORM_MGR_REGISTER_PUBLISH_FORM_INTERCEPTOR,
2045         data,
2046         reply,
2047         option);
2048     if (error != ERR_OK) {
2049         HILOG_ERROR("SendRequest:%{public}d failed", error);
2050         return error;
2051     }
2052     // retrieve and return result.
2053     return reply.ReadInt32();
2054 }
2055 
UnregisterPublishFormInterceptor(const sptr<IRemoteObject> & interceptorCallback)2056 int32_t FormMgrProxy::UnregisterPublishFormInterceptor(const sptr<IRemoteObject> &interceptorCallback)
2057 {
2058     HILOG_DEBUG("start");
2059     MessageParcel data;
2060     // write in token to help identify which stub to be called.
2061     if (!WriteInterfaceToken(data)) {
2062         HILOG_ERROR("write interface token failed");
2063         return ERR_APPEXECFWK_PARCEL_ERROR;
2064     }
2065     // write in interceptor
2066     if (!data.WriteRemoteObject(interceptorCallback)) {
2067         HILOG_ERROR("fail write interceptor");
2068         return ERR_APPEXECFWK_PARCEL_ERROR;
2069     }
2070 
2071     MessageParcel reply;
2072     MessageOption option;
2073     int error = SendTransactCmd(
2074         IFormMgr::Message::FORM_MGR_UNREGISTER_PUBLISH_FORM_INTERCEPTOR,
2075         data,
2076         reply,
2077         option);
2078     if (error != ERR_OK) {
2079         HILOG_ERROR("SendRequest:%{public}d failed", error);
2080         return error;
2081     }
2082     return reply.ReadInt32();
2083 }
2084 
RegisterClickEventObserver(const std::string & bundleName,const std::string & formEventType,const sptr<IRemoteObject> & observer)2085 ErrCode FormMgrProxy::RegisterClickEventObserver(
2086     const std::string &bundleName, const std::string &formEventType, const sptr<IRemoteObject> &observer)
2087 {
2088     HILOG_DEBUG("Click callback event start");
2089     MessageParcel data;
2090     if (!WriteInterfaceToken(data)) {
2091         HILOG_ERROR("write interface token failed");
2092         return ERR_APPEXECFWK_PARCEL_ERROR;
2093     }
2094 
2095     if (!data.WriteString(bundleName)) {
2096         HILOG_ERROR("write bundleName failed");
2097         return ERR_APPEXECFWK_PARCEL_ERROR;
2098     }
2099 
2100     if (!data.WriteString(formEventType)) {
2101         HILOG_ERROR("write formEventType failed");
2102         return ERR_APPEXECFWK_PARCEL_ERROR;
2103     }
2104 
2105     if (!data.WriteRemoteObject(observer)) {
2106         HILOG_ERROR("fail write observer");
2107         return ERR_APPEXECFWK_PARCEL_ERROR;
2108     }
2109 
2110     MessageParcel reply;
2111     MessageOption option(MessageOption::TF_ASYNC);
2112     int error = SendTransactCmd(
2113         IFormMgr::Message::FORM_MGR_REGISTER_CLICK_EVENT_OBSERVER, data, reply, option);
2114     if (error != ERR_OK) {
2115         HILOG_ERROR("SendRequest:%{public}d failed", error);
2116         return error;
2117     }
2118     return ERR_OK;
2119 }
2120 
UnregisterClickEventObserver(const std::string & bundleName,const std::string & formEventType,const sptr<IRemoteObject> & observer)2121 ErrCode FormMgrProxy::UnregisterClickEventObserver(
2122     const std::string &bundleName, const std::string &formEventType, const sptr<IRemoteObject> &observer)
2123 {
2124     HILOG_DEBUG("Click callback event start");
2125     MessageParcel data;
2126     if (!WriteInterfaceToken(data)) {
2127         HILOG_ERROR("write interface token failed");
2128         return ERR_APPEXECFWK_PARCEL_ERROR;
2129     }
2130 
2131     if (!data.WriteString(bundleName)) {
2132         HILOG_ERROR("write bundleName failed");
2133         return ERR_APPEXECFWK_PARCEL_ERROR;
2134     }
2135 
2136     if (!data.WriteString(formEventType)) {
2137         HILOG_ERROR("write formEventType failed");
2138         return ERR_APPEXECFWK_PARCEL_ERROR;
2139     }
2140 
2141     if (!data.WriteRemoteObject(observer)) {
2142         HILOG_ERROR("fail write observer");
2143         return ERR_APPEXECFWK_PARCEL_ERROR;
2144     }
2145 
2146     MessageParcel reply;
2147     MessageOption option(MessageOption::TF_ASYNC);
2148     int error = SendTransactCmd(
2149         IFormMgr::Message::FORM_MGR_UNREGISTER_CLICK_EVENT_OBSERVER, data, reply, option);
2150     if (error != ERR_OK) {
2151         HILOG_ERROR("SendRequest:%{public}d failed", error);
2152         return error;
2153     }
2154     return ERR_OK;
2155 }
2156 
SetFormsRecyclable(const std::vector<int64_t> & formIds)2157 int32_t FormMgrProxy::SetFormsRecyclable(const std::vector<int64_t> &formIds)
2158 {
2159     HILOG_DEBUG("start");
2160     MessageParcel data;
2161     if (!WriteInterfaceToken(data)) {
2162         HILOG_ERROR("write interface token failed");
2163         return ERR_APPEXECFWK_PARCEL_ERROR;
2164     }
2165     if (!data.WriteInt64Vector(formIds)) {
2166         HILOG_ERROR("write vector formIds failed");
2167         return ERR_APPEXECFWK_PARCEL_ERROR;
2168     }
2169     MessageParcel reply;
2170     MessageOption option(MessageOption::TF_SYNC);
2171     int32_t error = SendTransactCmd(IFormMgr::Message::FORM_MGR_SET_FORMS_RECYCLABLE, data, reply, option);
2172     if (error != ERR_OK) {
2173         HILOG_ERROR("SendTransactCmd:%{public}d failed", error);
2174         return error;
2175     }
2176     return reply.ReadInt32();
2177 }
2178 
RecycleForms(const std::vector<int64_t> & formIds,const Want & want)2179 int32_t FormMgrProxy::RecycleForms(const std::vector<int64_t> &formIds, const Want &want)
2180 {
2181     HILOG_DEBUG("start");
2182     MessageParcel data;
2183     if (!WriteInterfaceToken(data)) {
2184         HILOG_ERROR("write interface token failed");
2185         return ERR_APPEXECFWK_PARCEL_ERROR;
2186     }
2187     if (!data.WriteInt64Vector(formIds)) {
2188         HILOG_ERROR("write vector formIds failed");
2189         return ERR_APPEXECFWK_PARCEL_ERROR;
2190     }
2191     if (!data.WriteParcelable(&want)) {
2192         HILOG_ERROR("write want failed");
2193         return ERR_APPEXECFWK_PARCEL_ERROR;
2194     }
2195     MessageParcel reply;
2196     MessageOption option(MessageOption::TF_SYNC);
2197     int32_t error = SendTransactCmd(IFormMgr::Message::FORM_MGR_RECYCLE_FORMS, data, reply, option);
2198     if (error != ERR_OK) {
2199         HILOG_ERROR("SendTransactCmd:%{public}d failed", error);
2200         return error;
2201     }
2202     return reply.ReadInt32();
2203 }
2204 
RecoverForms(const std::vector<int64_t> & formIds,const Want & want)2205 int32_t FormMgrProxy::RecoverForms(const std::vector<int64_t> &formIds, const Want &want)
2206 {
2207     HILOG_DEBUG("start");
2208     MessageParcel data;
2209     if (!WriteInterfaceToken(data)) {
2210         HILOG_ERROR("write interface token failed");
2211         return ERR_APPEXECFWK_PARCEL_ERROR;
2212     }
2213     if (!data.WriteInt64Vector(formIds)) {
2214         HILOG_ERROR("write vector formIds failed");
2215         return ERR_APPEXECFWK_PARCEL_ERROR;
2216     }
2217     if (!data.WriteParcelable(&want)) {
2218         HILOG_ERROR("write want failed");
2219         return ERR_APPEXECFWK_PARCEL_ERROR;
2220     }
2221     MessageParcel reply;
2222     MessageOption option(MessageOption::TF_SYNC);
2223     int32_t error = SendTransactCmd(IFormMgr::Message::FORM_MGR_RECOVER_FORMS, data, reply, option);
2224     if (error != ERR_OK) {
2225         HILOG_ERROR("SendTransactCmd:%{public}d failed", error);
2226         return error;
2227     }
2228     return reply.ReadInt32();
2229 }
2230 
UpdateFormLocation(const int64_t & formId,const int32_t & formLocation)2231 ErrCode FormMgrProxy::UpdateFormLocation(const int64_t &formId, const int32_t &formLocation)
2232 {
2233     HILOG_DEBUG("start");
2234     MessageParcel data;
2235     if (!WriteInterfaceToken(data)) {
2236         HILOG_ERROR("write interface token failed");
2237         return ERR_APPEXECFWK_PARCEL_ERROR;
2238     }
2239     if (!data.WriteInt64(formId)) {
2240         HILOG_ERROR("write formId failed");
2241         return ERR_APPEXECFWK_PARCEL_ERROR;
2242     }
2243     if (!data.WriteInt32(formLocation)) {
2244         HILOG_ERROR("fail write formLocation");
2245         return ERR_APPEXECFWK_PARCEL_ERROR;
2246     }
2247     MessageParcel reply;
2248     MessageOption option(MessageOption::TF_SYNC);
2249     int32_t error = SendTransactCmd(IFormMgr::Message::FORM_MGR_UPDATE_FORM_LOCATION, data, reply, option);
2250     if (error != ERR_OK) {
2251         HILOG_ERROR("SendTransactCmd:%{public}d failed", error);
2252         return error;
2253     }
2254     return reply.ReadInt32();
2255 }
2256 
RequestPublishFormWithSnapshot(Want & want,bool withFormBindingData,std::unique_ptr<FormProviderData> & formBindingData,int64_t & formId)2257 ErrCode FormMgrProxy::RequestPublishFormWithSnapshot(Want &want, bool withFormBindingData,
2258     std::unique_ptr<FormProviderData> &formBindingData, int64_t &formId)
2259 {
2260     MessageParcel data;
2261     MessageParcel reply;
2262 
2263     if (!WriteInterfaceToken(data)) {
2264         HILOG_ERROR("write interface token failed");
2265         return ERR_APPEXECFWK_PARCEL_ERROR;
2266     }
2267     if (!data.WriteParcelable(&want)) {
2268         HILOG_ERROR("write want failed");
2269         return ERR_APPEXECFWK_PARCEL_ERROR;
2270     }
2271     if (!data.WriteBool(withFormBindingData)) {
2272         HILOG_ERROR("write withFormBindingData failed");
2273         return ERR_APPEXECFWK_PARCEL_ERROR;
2274     }
2275     if (withFormBindingData) {
2276         if (!data.WriteParcelable(formBindingData.get())) {
2277             HILOG_ERROR("write formBindingData failed");
2278             return ERR_APPEXECFWK_PARCEL_ERROR;
2279         }
2280     }
2281 
2282     MessageOption option;
2283     int32_t error = SendTransactCmd(
2284         IFormMgr::Message::FORM_MGR_REQUEST_PUBLISH_FORM_WITH_SNAPSHOT,
2285         data,
2286         reply,
2287         option);
2288     if (error != ERR_OK) {
2289         HILOG_ERROR("SendRequest:%{public}d failed", error);
2290         return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
2291     }
2292     ErrCode errCode = reply.ReadInt32();
2293     if (errCode == ERR_OK) {
2294         formId = reply.ReadInt64();
2295     }
2296     return errCode;
2297 }
2298 
BatchRefreshForms(const int32_t formRefreshType)2299 int32_t FormMgrProxy::BatchRefreshForms(const int32_t formRefreshType)
2300 {
2301     MessageParcel data;
2302     if (!WriteInterfaceToken(data)) {
2303         HILOG_ERROR("write interface token failed");
2304         return ERR_APPEXECFWK_PARCEL_ERROR;
2305     }
2306     if (!data.WriteInt32(formRefreshType)) {
2307         HILOG_ERROR("fail write formRefreshType");
2308         return ERR_APPEXECFWK_PARCEL_ERROR;
2309     }
2310     MessageParcel reply;
2311     MessageOption option(MessageOption::TF_SYNC);
2312     int32_t error = SendTransactCmd(IFormMgr::Message::FORM_MGR_BATCH_REFRESH_FORMS, data, reply, option);
2313     if (error != ERR_OK) {
2314         HILOG_ERROR("SendTransactCmd:%{public}d failed", error);
2315         return error;
2316     }
2317     return reply.ReadInt32();
2318 }
2319 
EnableForms(const std::string bundleName,const bool enable)2320 int32_t FormMgrProxy::EnableForms(const std::string bundleName, const bool enable)
2321 {
2322     HILOG_DEBUG("EnableForms start.%{public}s", bundleName.c_str());
2323     MessageParcel data;
2324     if (!WriteInterfaceToken(data)) {
2325         HILOG_ERROR("write interface token failed");
2326         return ERR_APPEXECFWK_PARCEL_ERROR;
2327     }
2328 
2329     if (!data.WriteString(bundleName)) {
2330         HILOG_ERROR("write bundleName failed");
2331         return ERR_APPEXECFWK_PARCEL_ERROR;
2332     }
2333 
2334     if (!data.WriteBool(enable)) {
2335         HILOG_ERROR("fail write enable");
2336         return ERR_APPEXECFWK_PARCEL_ERROR;
2337     }
2338 
2339     MessageParcel reply;
2340     MessageOption option(MessageOption::TF_SYNC);
2341     int error = SendTransactCmd(IFormMgr::Message::FORM_MGR_ENABLE_FORMS, data, reply, option);
2342     if (error != ERR_OK) {
2343         HILOG_ERROR("SendRequest:%{public}d failed", error);
2344         return error;
2345     }
2346     return ERR_OK;
2347 }
2348 
IsFormBundleForbidden(const std::string & bundleName)2349 bool FormMgrProxy::IsFormBundleForbidden(const std::string &bundleName)
2350 {
2351     MessageParcel data;
2352     if (!WriteInterfaceToken(data)) {
2353         HILOG_ERROR("write interface token failed");
2354         return ERR_APPEXECFWK_PARCEL_ERROR;
2355     }
2356 
2357     if (!data.WriteString(bundleName)) {
2358         HILOG_ERROR("write bundleName failed");
2359         return ERR_APPEXECFWK_PARCEL_ERROR;
2360     }
2361 
2362     MessageParcel reply;
2363     MessageOption option;
2364     int error = SendTransactCmd(
2365         IFormMgr::Message::FORM_MGR_IS_FORM_BUNDLE_FORBIDDEN, data, reply, option);
2366     if (error != ERR_OK) {
2367         HILOG_ERROR("SendRequest:%{public}d failed", error);
2368         return false;
2369     }
2370     return reply.ReadBool();
2371 }
2372 
UpdateFormSize(const int64_t & formId,float width,float height,float borderWidth)2373 ErrCode FormMgrProxy::UpdateFormSize(const int64_t &formId, float width, float height, float borderWidth)
2374 {
2375     HILOG_DEBUG("start");
2376     MessageParcel data;
2377     if (!WriteInterfaceToken(data)) {
2378         HILOG_ERROR("write interface token failed");
2379         return ERR_APPEXECFWK_PARCEL_ERROR;
2380     }
2381     if (!data.WriteInt64(formId)) {
2382         HILOG_ERROR("fail write formId ");
2383         return ERR_APPEXECFWK_PARCEL_ERROR;
2384     }
2385     if (!data.WriteFloat(width)) {
2386         HILOG_ERROR("fail write width");
2387         return ERR_APPEXECFWK_PARCEL_ERROR;
2388     }
2389     if (!data.WriteFloat(height)) {
2390         HILOG_ERROR("fail write height");
2391         return ERR_APPEXECFWK_PARCEL_ERROR;
2392     }
2393     if (!data.WriteFloat(borderWidth)) {
2394         HILOG_ERROR("fail write borderWidth");
2395         return ERR_APPEXECFWK_PARCEL_ERROR;
2396     }
2397     MessageParcel reply;
2398     MessageOption option(MessageOption::TF_SYNC);
2399     int32_t error = SendTransactCmd(IFormMgr::Message::FORM_MGR_UPDATE_FORM_SIZE, data, reply, option);
2400     if (error != ERR_OK) {
2401         HILOG_ERROR("SendTransactCmd:%{public}d failed", error);
2402         return error;
2403     }
2404     return reply.ReadInt32();
2405 }
2406 }  // namespace AppExecFwk
2407 }  // namespace OHOS
2408