• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef OHOS_FORM_FWK_FORM_MGR_H
17 #define OHOS_FORM_FWK_FORM_MGR_H
18 
19 #include <mutex>
20 #include <shared_mutex>
21 #include <singleton.h>
22 #include <thread>
23 
24 #include "form_callback_interface.h"
25 #include "form_constants.h"
26 #include "form_errors.h"
27 #include "form_death_callback.h"
28 #include "form_info.h"
29 #include "form_instance.h"
30 #include "form_instances_filter.h"
31 #include "form_js_info.h"
32 #include "form_mgr_interface.h"
33 #include "form_provider_data.h"
34 #include "form_provider_data_proxy.h"
35 #include "form_state_info.h"
36 #include "running_form_info.h"
37 #include "iremote_object.h"
38 #include "want.h"
39 
40 namespace OHOS {
41 namespace AppExecFwk {
42 using OHOS::AAFwk::Want;
43 
44 static volatile int recoverStatus_ = Constants::NOT_IN_RECOVERY;
45 
46 /**
47  * @class FormMgr
48  * FormMgr is used to access form manager services.
49  */
50 class FormMgr final : public DelayedRefSingleton<FormMgr> {
51     DECLARE_DELAYED_REF_SINGLETON(FormMgr)
52 public:
53     DISALLOW_COPY_AND_MOVE(FormMgr);
54 
55     friend class FormMgrDeathRecipient;
56 
57     /**
58      * @brief Register click callback observer.
59      * @param bundleName BundleName of the form host.
60      * @param formEventType Form event type.
61      * @param observer Form click event callback listener.
62      * @return Returns ERR_OK on success, others on failure.
63      */
64     ErrCode RegisterClickEventObserver(
65         const std::string &bundleName, const std::string &formEventType, const sptr<IRemoteObject> &observer);
66 
67     /**
68      * @brief Unregister click callback observer.
69      * @param bundleName BundleName of the form host.
70      * @param formEventType Form event type.
71      * @param observer Form click event callback listener.
72      * @return Returns ERR_OK on success, others on failure.
73      */
74     ErrCode UnregisterClickEventObserver(
75         const std::string &bundleName, const std::string &formEventType, const sptr<IRemoteObject> &observer);
76 
77     /**
78      * @brief Get the error message by error code.
79      * @param errorCode the error code return form fms.
80      * @return Returns the error message detail.
81      */
82     std::string GetErrorMsg(int errorCode);
83 
84     /**
85      * @brief Add form with want, send want to form manager service.
86      * @param formId The Id of the forms to add.
87      * @param want The want of the form to add.
88      * @param callerToken Caller ability token.
89      * @param formInfo Form info.
90      * @return Returns ERR_OK on success, others on failure.
91      */
92     int AddForm(const int64_t formId, const Want &want, const sptr<IRemoteObject> &callerToken,
93         FormJsInfo &formInfo);
94 
95     /**
96      * @brief Add form with want, send want to form manager service.
97      * @param want The want of the form to add.
98      * @param runningFormInfo Running form info.
99      * @return Returns ERR_OK on success, others on failure.
100      */
101     int CreateForm(const Want &want, RunningFormInfo &runningFormInfo);
102 
103     /**
104      * @brief Delete forms with formIds, send formIds to form manager service.
105      * @param formId The Id of the forms to delete.
106      * @param callerToken Caller ability token.
107      * @return Returns ERR_OK on success, others on failure.
108      */
109     int DeleteForm(const int64_t formId, const sptr<IRemoteObject> &callerToken);
110 
111     /**
112      * @brief Stop rendering form.
113      * @param formId The Id of the forms to delete.
114      * @param compId The compId of the forms to delete.
115      * @return Returns ERR_OK on success, others on failure.
116      */
117     int StopRenderingForm(const int64_t formId, const std::string &compId);
118 
119     /**
120      * @brief Release forms with formIds, send formIds to form manager service.
121      * @param formId The Id of the forms to release.
122      * @param callerToken Caller ability token.
123      * @param delCache Delete Cache or not.
124      * @return Returns ERR_OK on success, others on failure.
125      */
126     int ReleaseForm(const int64_t formId, const sptr<IRemoteObject> &callerToken, const bool delCache);
127 
128     /**
129      * @brief Update form with formId, send formId to form manager service.
130      * @param formId The Id of the form to update.
131      * @param formBindingData Form binding data.
132      * @param std::vector<FormDataProxy> Form proxy vector.
133      * @return Returns ERR_OK on success, others on failure.
134      */
135     int UpdateForm(const int64_t formId, const FormProviderData &formBindingData,
136         const std::vector<FormDataProxy> &formDataProxies = {});
137 
138     /**
139      * @brief Notify the form service that the form user's lifecycle is updated.
140      *
141      * This should be called when form user request form.
142      *
143      * @param formId Indicates the unique id of form.
144      * @param callerToken Indicates the callback remote object of specified form user.
145      * @param want information passed to supplier.
146      * @return Returns ERR_OK on success, others on failure.
147      */
148     int RequestForm(const int64_t formId, const sptr<IRemoteObject> &callerToken, const Want &want);
149 
150     /**
151      * @brief Form visible/invisible notify, send formIds to form manager service.
152      * @param formIds The Id list of the forms to notify.
153      * @param callerToken Caller ability token.
154      * @param formVisibleType The form visible type, including FORM_VISIBLE and FORM_INVISIBLE.
155      * @return Returns ERR_OK on success, others on failure.
156      */
157     int NotifyWhetherVisibleForms(const std::vector<int64_t> &formIds, const sptr<IRemoteObject> &callerToken,
158     const int32_t formVisibleType);
159 
160     /**
161      * @brief Query whether has visible form by tokenId.
162      * @param tokenId Unique identification of application.
163      * @return Returns true if has visible form, false otherwise.
164      */
165     bool HasFormVisible(const uint32_t tokenId);
166 
167     /**
168      * @brief Release renderer.
169      * @param formId The Id of the forms to release.
170      * @param compId The compId of the forms to release.
171      * @return Returns ERR_OK on success, others on failure.
172      */
173     int ReleaseRenderer(const int64_t formId, const std::string &compId);
174 
175     /**
176      * @brief temp form to normal form.
177      * @param formId The Id of the form.
178      * @param callerToken Caller ability token.
179      * @return None.
180      */
181     int CastTempForm(const int64_t formId, const sptr<IRemoteObject> &callerToken);
182 
183     /**
184      * @brief Dump all of form storage infos.
185      * @param formInfos All of form storage infos.
186      * @return Returns ERR_OK on success, others on failure.
187      */
188     int DumpStorageFormInfos(std::string &formInfos);
189     /**
190      * @brief Dump form info by a bundle name.
191      * @param bundleName The bundle name of form provider.
192      * @param formInfos Form infos.
193      * @return Returns ERR_OK on success, others on failure.
194      */
195     int DumpFormInfoByBundleName(const std::string bundleName, std::string &formInfos);
196     /**
197      * @brief Dump form info by a bundle name.
198      * @param formId The id of the form.
199      * @param formInfo Form info.
200      * @return Returns ERR_OK on success, others on failure.
201      */
202     int DumpFormInfoByFormId(const std::int64_t formId, std::string &formInfo);
203     /**
204      * @brief Dump form timer by form id.
205      * @param formId The id of the form.
206      * @param formInfo Form timer.
207      * @return Returns ERR_OK on success, others on failure.
208      */
209     int DumpFormTimerByFormId(const std::int64_t formId, std::string &isTimingService);
210     /**
211      * @brief Process js message event.
212      * @param formId Indicates the unique id of form.
213      * @param want information passed to supplier.
214      * @param callerToken Caller ability token.
215      * @return Returns ERR_OK on success, others on failure.
216      */
217     int MessageEvent(const int64_t formId, const Want &want, const sptr<IRemoteObject> &callerToken);
218 
219     /**
220      * @brief Process js router event.
221      * @param formId Indicates the unique id of form.
222      * @param want the want of the ability to start.
223      * @param callerToken Caller ability token.
224      * @return Returns ERR_OK on success, others on failure.
225      */
226     int RouterEvent(const int64_t formId, Want &want, const sptr<IRemoteObject> &callerToken);
227 
228     /**
229      * @brief Process Background event.
230      * @param formId Indicates the unique id of form.
231      * @param want the want of the ability to start.
232      * @param callerToken Caller ability token.
233      * @return Returns true if execute success, false otherwise.
234      */
235     int BackgroundEvent(const int64_t formId, Want &want, const sptr<IRemoteObject> &callerToken);
236 
237     /**
238      * @brief Get fms recoverStatus.
239      *
240      * @return The current recover status.
241      */
242     static int GetRecoverStatus();
243 
244     /**
245      * @brief Register death callback.
246      *
247      * @param formDeathCallback The death callback.
248      */
249     void RegisterDeathCallback(const std::shared_ptr<FormCallbackInterface> &formDeathCallback);
250 
251     /**
252      * @brief UnRegister death callback.
253      *
254      * @param formDeathCallback The death callback.
255      */
256     void UnRegisterDeathCallback(const std::shared_ptr<FormCallbackInterface> &formDeathCallback);
257 
258     /**
259      * @brief Set the next refresh time
260      *
261      * @param formId The id of the form.
262      * @param nextTime Next refresh time
263      * @return Returns ERR_OK on success, others on failure.
264      */
265     int SetNextRefreshTime(const int64_t formId, const int64_t nextTime);
266 
267     /**
268      * @brief Request to publish a form to the form host.
269      *
270      * @param want The want of the form to publish.
271      * @param withFormBindingData Indicates whether the formBindingData is carried with.
272      * @param formBindingData Indicates the form data.
273      * @param formId Return the form id to be published.
274      * @return Returns ERR_OK on success, others on failure.
275      */
276     ErrCode RequestPublishForm(Want &want, bool withFormBindingData,
277         std::unique_ptr<FormProviderData> &formBindingData, int64_t &formId,
278         const std::vector<FormDataProxy> &formDataProxies = {});
279 
280     ErrCode SetPublishFormResult(const int64_t formId, Constants::PublishFormResult &errorCodeInfo);
281 
282     ErrCode AcquireAddFormResult(const int64_t formId);
283 
284     /**
285      * @brief Lifecycle Update.
286      * @param formIds The id of the forms.
287      * @param callerToken Host client.
288      * @param updateType update type, enable if true and disable if false.
289      * @return Returns ERR_OK on success, others on failure.
290      */
291     int LifecycleUpdate(const std::vector<int64_t> &formIds, const sptr<IRemoteObject> &callerToken,
292                         bool updateType);
293 
294     /**
295      * @brief Set fms recoverStatus.
296      *
297      * @param recoverStatus The recover status.
298      */
299     static void SetRecoverStatus(int recoverStatus);
300 
301     /**
302      * @brief Set form mgr service for test.
303      */
304     void SetFormMgrService(sptr<IFormMgr> formMgrService);
305 
306     /**
307      * @brief Get death recipient.
308      * @return deathRecipient_.
309      */
310     sptr<IRemoteObject::DeathRecipient> GetDeathRecipient() const;
311 
312     /**
313      * @brief Check whether the specified death callback is registered in form mgr.
314      * @param formDeathCallback The specified death callback for checking.
315      * @return Return true on success, false on failure.
316      */
317     bool CheckIsDeathCallbackRegistered(const std::shared_ptr<FormCallbackInterface> &formDeathCallback);
318 
319     /**
320      * @brief Get the error message content.
321      *
322      * @param errCode Error code.
323      * @return Message content.
324      */
325     std::string GetErrorMessage(int errCode);
326 
327     /**
328      * @brief Delete the invalid forms.
329      * @param formIds Indicates the ID of the valid forms.
330      * @param callerToken Host client.
331      * @param numFormsDeleted Returns the number of the deleted forms.
332      * @return Returns ERR_OK on success, others on failure.
333      */
334     int DeleteInvalidForms(const std::vector<int64_t> &formIds, const sptr<IRemoteObject> &callerToken,
335                            int32_t &numFormsDeleted);
336 
337     /**
338      * @brief Acquire form state info by passing a set of parameters (using Want) to the form provider.
339      * @param want Indicates a set of parameters to be transparently passed to the form provider.
340      * @param callerToken Host client.
341      * @param stateInfo Returns the form's state info of the specify.
342      * @return Returns ERR_OK on success, others on failure.
343      */
344     int AcquireFormState(const Want &want, const sptr<IRemoteObject> &callerToken, FormStateInfo &stateInfo);
345 
346     /**
347      * @brief Notify the form is visible or not.
348      * @param formIds Indicates the ID of the forms.
349      * @param isVisible Visible or not.
350      * @param callerToken Host client.
351      * @return Returns ERR_OK on success, others on failure.
352      */
353     int NotifyFormsVisible(const std::vector<int64_t> &formIds, bool isVisible, const sptr<IRemoteObject> &callerToken);
354 
355     /**
356      * @brief Notify the form is privacy protected or not.
357      * @param formIds Indicates the ID of the forms.
358      * @param isProtected isProtected or not.
359      * @param callerToken Host client.
360      * @return Returns ERR_OK on success, others on failure.
361      */
362     int NotifyFormsPrivacyProtected(const std::vector<int64_t> &formIds, bool isProtected,
363                                     const sptr<IRemoteObject> &callerToken);
364 
365     /**
366      * @brief Notify the form is enable to be updated or not.
367      * @param formIds Indicates the ID of the forms.
368      * @param isEnableUpdate enable update or not.
369      * @param callerToken Host client.
370      * @return Returns ERR_OK on success, others on failure.
371      */
372     int NotifyFormsEnableUpdate(const std::vector<int64_t> &formIds, bool isEnableUpdate,
373                                 const sptr<IRemoteObject> &callerToken);
374 
375     /**
376      * @brief Get All FormsInfo.
377      * @param formInfos Return the forms' information of all forms provided.
378      * @return Returns ERR_OK on success, others on failure.
379      */
380     int GetAllFormsInfo(std::vector<FormInfo> &formInfos);
381 
382     /**
383      * @brief Get forms info by bundle name .
384      * @param bundleName Application name.
385      * @param formInfos Return the forms' information of the specify application name.
386      * @return Returns ERR_OK on success, others on failure.
387      */
388     int GetFormsInfoByApp(std::string &bundleName, std::vector<FormInfo> &formInfos);
389 
390     /**
391      * @brief Get forms info by bundle name and module name.
392      * @param bundleName bundle name.
393      * @param moduleName Module name of hap.
394      * @param formInfos Return the forms' information of the specify bundle name and module name.
395      * @return Returns ERR_OK on success, others on failure.
396      */
397     int GetFormsInfoByModule(std::string &bundleName, std::string &moduleName, std::vector<FormInfo> &formInfos);
398 
399     /**
400      * @brief Get forms info specified by filter parameters.
401      * @param filter Filter that contains necessary conditions, such as bundle name, module name, dimensions.
402      * @param formInfos Return the forms' information specified by filter.
403      * @return Returns ERR_OK on success, others on failure.
404      */
405     int GetFormsInfoByFilter(const FormInfoFilter &filter, std::vector<FormInfo> &formInfos);
406 
407     /**
408     * @brief This function is called by formProvider and gets forms info by the bundle name of the calling ability.
409     *        The bundle name will be retrieved by form service manager.
410     * @param filter filter that contains attributes that the formInfos have to have.
411     * @param formInfos Return the forms' information of the calling bundle name
412     * @return Returns ERR_OK on success, others on failure.
413     */
414     int32_t GetFormsInfo(const FormInfoFilter &filter, std::vector<FormInfo> &formInfos);
415 
416     /**
417     * @brief This function is called by formProvider and gets form info by the formId of the calling ability.
418     *        The formId will be retrieved by form service manager.
419     * @param formId The formId of the calling ability
420     * @param formInfo Return the form' information of the calling formId
421     * @return Returns ERR_OK on success, others on failure.
422     */
423     int32_t GetPublishedFormInfoById(const int64_t formId, RunningFormInfo &formInfo);
424 
425     /**
426     * @brief This function is called by formProvider and gets forms info by the bundle name of the calling ability.
427     *        The bundle name will be retrieved by form service manager.
428     * @param formInfos Return the forms' information of the calling bundle name
429     * @return Returns ERR_OK on success, others on failure.
430     */
431     int32_t GetPublishedFormInfos(std::vector<RunningFormInfo> &formInfos);
432 
433     /**
434      * @brief Get all running form infos.
435      * @param isUnusedIncluded Indicates whether to include unused forms.
436      * @param runningFormInfos Return the running forms' infos currently.
437      * @return Returns ERR_OK on success, others on failure.
438      */
439     ErrCode GetRunningFormInfos(bool isUnusedIncluded, std::vector<RunningFormInfo> &runningFormInfos);
440 
441     /**
442      * @brief Get the running form infos by bundle name.
443      * @param bundleName Application name.
444      * @param isUnusedIncluded Indicates whether to include unused forms.
445      * @param runningFormInfos Return the running forms' infos of the specify application name.
446      * @return Returns ERR_OK on success, others on failure.
447      */
448     ErrCode GetRunningFormInfosByBundleName(
449         const std::string &bundleName, bool isUnusedIncluded, std::vector<RunningFormInfo> &runningFormInfos);
450 
451     /**
452      * @brief Check if the request of publishing a form is supported by the host.
453      * @return Returns true if the request is supported and false otherwise.
454      */
455     bool IsRequestPublishFormSupported();
456 
457     /**
458      * @brief Start an ability. This function can only be called by a form extension of a system app.
459      * @param want includes ability name, parameters and relative info sending to an ability.
460      * @param callerToken token of the ability that initially calls this function.
461      * @return Returns ERR_OK on success, others on failure.
462      */
463     int32_t StartAbility(const Want &want, const sptr<IRemoteObject> &callerToken);
464 
465     /**
466      * @brief Start an ability by form manager service.
467      * @param want includes ability name, parameters and relative info sending to an ability.
468      * @return Returns ERR_OK on success, others on failure.
469      */
470     int32_t StartAbilityByFms(const Want &want);
471 
472     /**
473      * @brief Share form with formId and remote device id.
474      * @param formId The Id of the forms to share.
475      * @param remoteDeviceId The Id of the remote revice to share.
476      * @param callerToken Indicates the host client.
477      * @param requestCode The request code of this share form.
478      * @return Returns ERR_OK on success, others on failure.
479      */
480     int32_t ShareForm(int64_t formId, const std::string &remoteDeviceId, const sptr<IRemoteObject> &callerToken,
481         int64_t requestCode);
482 
483     /**
484      * @brief Acquire form data by formId.
485      * @param formId The Id of the form to acquire data.
486      * @param requestCode The request code of this acquire form.
487      * @param callerToken Indicates the host client.
488      * @param formData Return the forms' information of customization
489      * @return Returns ERR_OK on success, others on failure.
490      */
491     int32_t AcquireFormData(int64_t formId, int64_t requestCode, const sptr<IRemoteObject> &callerToken,
492          AAFwk::WantParams &formData);
493 
494     /**
495      * @brief Check form manager service ready.
496      *
497      * @return Return true if form manager service ready; returns false otherwise.
498      */
499     bool CheckFMSReady();
500 
501     /**
502      * @brief Check whether the form is system app.
503      * @param bundleName The bundleName of the form.
504      * @return Returns true if the form app is system, others false.
505      */
506     bool IsSystemAppForm(const std::string &bundleName);
507 
508     /**
509      * @brief Registers the callback for publish form. The callback is used to process the publish form request
510      * when the system handler is not found.
511      * @param interceptorCallback The injected callback, should implementation IFormPublishInterceptor.
512      * @return Returns ERR_OK on success, others on failure.
513      */
514     int32_t RegisterPublishFormInterceptor(const sptr<IRemoteObject> &interceptorCallback);
515 
516     /**
517      * @brief Unregisters the callback for publish form. The callback is used to process the publish form request
518      * when the system handler is not found.
519      * @param interceptorCallback The injected callback, should implementation IFormPublishInterceptor.
520      * @return Returns ERR_OK on success, others on failure.
521      */
522     int32_t UnregisterPublishFormInterceptor(const sptr<IRemoteObject> &interceptorCallback);
523 
524     /**
525      * @brief Get external error from innerErrorCode.
526      * @param innerErrorCode innerErrorCode, get from FMS.
527      * @param externalErrorCode output externalErrorCode.
528      * @param errorMsg output errorMsg.
529      */
530     void GetExternalError(int32_t innerErrorCode, int32_t &externalErrorCode, std::string &errorMsg);
531 
532     /**
533      * @brief Get external error message by external error code.
534      *
535      * @param externalErrorCode External error code.
536      * @return External error message.
537      */
538     std::string GetErrorMsgByExternalErrorCode(int32_t externalErrorCode);
539 
540     /**
541      * @brief Register form add observer by bundle.
542      * @param bundleName BundleName of the form host
543      * @param callerToken Caller ability token.
544      * @return Returns ERR_OK on success, others on failure.
545      */
546     ErrCode RegisterFormAddObserverByBundle(const std::string bundleName, const sptr<IRemoteObject> &callerToken);
547 
548     /**
549      * @brief Register form remove observer by bundle.
550      * @param bundleName BundleName of the form host
551      * @param callerToken Caller ability token.
552      * @return Returns ERR_OK on success, others on failure.
553      */
554     ErrCode RegisterFormRemoveObserverByBundle(const std::string bundleName, const sptr<IRemoteObject> &callerToken);
555 
556     /**
557     * @brief get forms count.
558     * @param isTempFormFlag Indicates temp form or not.
559     * @param formCount Returns the number of the cast or temp form.
560     * @return Returns ERR_OK on success, others on failure.
561     */
562     int32_t GetFormsCount(bool isTempFormFlag, int32_t &formCount);
563 
564     /**
565     * @brief get host forms count.
566     * @param bundleName Indicates form host bundleName.
567     * @param formCount Returns the number of the host form.
568     * @return Returns ERR_OK on success, others on failure.
569     */
570     int32_t GetHostFormsCount(std::string &bundleName, int32_t &formCount);
571 
572     /**
573     * @brief Get form instances by filter info.
574     * @param formInstancesFilter includes bundleName, moduleName, formName, abilityName to get formInstances.
575     * @param formInstances return formInstances
576     * @return return ERR_OK on get info success, others on failure.
577     */
578     ErrCode GetFormInstancesByFilter(const FormInstancesFilter &formInstancesFilter,
579         std::vector<FormInstance> &formInstances);
580 
581    /**
582     * @brief Get form instance by formId.
583     * @param formId formId Indicates the unique id of form.
584     * @param formInstance return formInstance
585     * @return return ERR_OK on get info success, others on failure.
586     */
587     ErrCode GetFormInstanceById(const int64_t formId, FormInstance &formInstance);
588 
589     /**
590      * @brief Get form instance by formId, include form store in DB.
591      * @param formId formId Indicates the unique id of form.
592      * @param isUnusedIncluded Indicates whether to include unused form.
593      * @param formInstance return formInstance
594      * @return return ERR_OK on get info success, others on failure.
595      */
596     ErrCode GetFormInstanceById(const int64_t formId, bool isUnusedIncluded, FormInstance &formInstance);
597 
598     /**
599      * @brief Register form add observer.
600      * @param bundleName BundleName of the form host
601      * @param callerToken Caller ability token.
602      * @return Returns ERR_OK on success, others on failure.
603      */
604     ErrCode RegisterAddObserver(const std::string &bundleName, const sptr<IRemoteObject> &callerToken);
605 
606     /**
607      * @brief Register form remove observer.
608      * @param bundleName BundleName of the form host
609      * @param callerToken Caller ability token.
610      * @return Returns ERR_OK on success, others on failure.
611      */
612     ErrCode RegisterRemoveObserver(const std::string &bundleName, const sptr<IRemoteObject> &callerToken);
613 
614     /**
615      * @brief Register form router event proxy.
616      * @param formIds Indicates the ID of the forms.
617      * @param callerToken Router proxy call back client.
618      * @return Returns ERR_OK on success, others on failure.
619      */
620     ErrCode RegisterFormRouterProxy(const std::vector<int64_t> &formIds, const sptr<IRemoteObject> &callerToken);
621 
622     /**
623      * @brief Unregister form router event proxy.
624      * @param formIds Indicates the ID of the forms.
625      * @return Returns ERR_OK on success, others on failure.
626      */
627     ErrCode UnregisterFormRouterProxy(const std::vector<int64_t> &formIds);
628 
629     /**
630      * @brief Set forms recyclable
631      * @param formIds Indicates the id of the forms.
632      * @return Returns ERR_OK on success, others on failure.
633      */
634     int32_t SetFormsRecyclable(const std::vector<int64_t> &formIds);
635 
636     /**
637      * @brief Recycle forms
638      * @param formIds Indicates the id of the forms.
639      * @param want The want of forms to be recycled.
640      * @return Returns ERR_OK on success, others on failure.
641      */
642     int32_t RecycleForms(const std::vector<int64_t> &formIds, const Want &want);
643 
644     /**
645      * @brief Recover recycled forms
646      * @param formIds Indicates the id of the forms.
647      * @param want The want of forms to be recovered.
648      * @return Returns ERR_OK on success, others on failure.
649      */
650     int32_t RecoverForms(const std::vector<int64_t> &formIds, const Want &want);
651 
652     /**
653      * @brief Update formLocation with formId.
654      * @param formId The Id of the form to update.
655      * @param formLocation The FormLocation.
656      * @return Returns ERR_OK on success, others on failure.
657      */
658     ErrCode UpdateFormLocation(const int64_t &formId, const int32_t &formLocation);
659 
660     /**
661     * @brief Request to publish a form to the form host for normal authority.
662     *
663     * @param want The want of the form to publish.
664     * @param withFormBindingData Indicates whether the formBindingData is carried with.
665     * @param formBindingData Indicates the form data.
666     * @param formId Return the form id to be published.
667     * @return Returns ERR_OK on success, others on failure.
668     */
669     ErrCode RequestPublishFormWithSnapshot(Want &want, bool withFormBindingData,
670         std::unique_ptr<FormProviderData> &formBindingData, int64_t &formId,
671         const std::vector<FormDataProxy> &formDataProxies = {});
672 
673     /**
674      * @brief Update form with formRefreshType, send to form manager service.
675      * @param formRefreshType The type of the form to refresh, 0: AllForm 1: 2: AppForm 2: AtomicServiceForm
676      * @return Returns ERR_OK on success, others on failure.
677      */
678     int32_t BatchRefreshForms(const int32_t formRefreshType);
679 
680     /**
681      * @brief enable/disable form update.
682      * @param bundleName BundleName of the form host.
683      * @param enable True for enable form, false for disable form.
684      * @return Returns ERR_OK on success, others on failure.
685      */
686     int32_t EnableForms(const std::string bundleName, const bool enable);
687 
688     /**
689      * @brief Check form bundle is controlled.
690      * @param bundleName The bundle name of form to be check.
691      * @return Returns true for form bundle is controlled.
692      */
693     bool IsFormBundleForbidden(const std::string &bundleName);
694 
695     /**
696      * @brief Check form bundle is protected.
697      * @param bundleName The bundle name of form to be check.
698      * @param formId The Id of the form to query.
699      * @return Returns true for form bundle is protected.
700      */
701     bool IsFormBundleProtected(const std::string &bundleName, int64_t formId);
702 
703     /**
704      * @brief Check form bundle is exempt.
705      * @param formId The Id of the form to query.
706      * @return Returns true for form bundle is exempt.
707      */
708     bool IsFormBundleExempt(int64_t formId);
709 
710     /**
711      * @brief Notify the form is locked or not.
712      * @param formId Indicates the ID of the form.
713      * @param isLocked locked or not.
714      * @return Returns ERR_OK on success, others on failure.
715      */
716     int32_t NotifyFormLocked(const int64_t &formId, bool isLocked);
717 
718     /**
719      * @brief Update form size.
720      * @param formId The Id of the form to update.
721      * @param width The width value to be updated.
722      * @param height The height value to be updated.
723      * @param borderWidth The borderWidth value to be updated.
724      * @return Returns ERR_OK on success, others on failure.
725      */
726     int32_t UpdateFormSize(const int64_t formId, float width, float height, float borderWidth);
727 
728     /**
729      * @brief Open the form edit ability.
730      * @param abilityName The form edit ability name.
731      * @param formId The edit form ID.
732      * @param isMainPage Open the main edit page.
733      * @return Returns ERR_OK on success, others on failure.
734      */
735     ErrCode OpenFormEditAbility(const std::string &abilityName, const int64_t &formId, bool isMainPage);
736 private:
737     /**
738      * @brief Connect form manager service.
739      * @return Returns ERR_OK on success, others on failure.
740      */
741     ErrCode Connect();
742 
743     /**
744     * @brief Reconnect form manager service once per 1000 milliseconds,
745     *        until the connection succeeds or reaching the max retry times.
746     * @return Returns true if execute success, false otherwise.
747     */
748     bool Reconnect();
749     /**
750      * @brief Reset proxy.
751      * @param remote remote object.
752      */
753     void ResetProxy(const wptr<IRemoteObject> &remote);
754 
755     /**
756      * @class FormMgrDeathRecipient
757      * FormMgrDeathRecipient notices IRemoteBroker died.
758      */
759     class FormMgrDeathRecipient : public IRemoteObject::DeathRecipient {
760     public:
761         FormMgrDeathRecipient() = default;
762         ~FormMgrDeathRecipient() = default;
763 
764         /**
765          * @brief Notices IRemoteBroker died.
766          * @param remote remote object.
767          */
768         void OnRemoteDied(const wptr<IRemoteObject> &remote) override;
769     private:
770         DISALLOW_COPY_AND_MOVE(FormMgrDeathRecipient);
771     };
772 
773     // Shared locks are used here, write locks are used for setting remoteProxy_ operations,
774     // and concurrent read locks are used for reading remoteProxy_ operations.
775     std::shared_mutex connectMutex_;
776     sptr<IFormMgr> remoteProxy_;
777 
778     sptr<IRemoteObject::DeathRecipient> deathRecipient_ {nullptr};
779 
780     // True: need to get a new fms remote object,
781     // False: no need to get a new fms remote object.
782     volatile bool resetFlag_ = false;
783 
784     std::vector<std::shared_ptr<FormCallbackInterface>> formDeathCallbacks_;
785 };
786 }  // namespace AppExecFwk
787 }  // namespace OHOS
788 #endif  // OHOS_FORM_FWK_FORM_MGR_H
789