• 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 related 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 related 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 Start an ability by cross bundle.
474      * @param want includes ability name, parameters and related info sending to an ability.
475      * @return Returns ERR_OK on success, others on failure.
476      */
477     int32_t StartAbilityByCrossBundle(const Want &want);
478 
479     /**
480      * @brief Share form with formId and remote device id.
481      * @param formId The Id of the forms to share.
482      * @param remoteDeviceId The Id of the remote revice to share.
483      * @param callerToken Indicates the host client.
484      * @param requestCode The request code of this share form.
485      * @return Returns ERR_OK on success, others on failure.
486      */
487     int32_t ShareForm(int64_t formId, const std::string &remoteDeviceId, const sptr<IRemoteObject> &callerToken,
488         int64_t requestCode);
489 
490     /**
491      * @brief Acquire form data by formId.
492      * @param formId The Id of the form to acquire data.
493      * @param requestCode The request code of this acquire form.
494      * @param callerToken Indicates the host client.
495      * @param formData Return the forms' information of customization
496      * @return Returns ERR_OK on success, others on failure.
497      */
498     int32_t AcquireFormData(int64_t formId, int64_t requestCode, const sptr<IRemoteObject> &callerToken,
499          AAFwk::WantParams &formData);
500 
501     /**
502      * @brief Check form manager service ready.
503      *
504      * @return Return true if form manager service ready; returns false otherwise.
505      */
506     bool CheckFMSReady();
507 
508     /**
509      * @brief Check whether the form is system app.
510      * @param bundleName The bundleName of the form.
511      * @return Returns true if the form app is system, others false.
512      */
513     bool IsSystemAppForm(const std::string &bundleName);
514 
515     /**
516      * @brief Registers the callback for publish form. The callback is used to process the publish form request
517      * when the system handler is not found.
518      * @param interceptorCallback The injected callback, should implementation IFormPublishInterceptor.
519      * @return Returns ERR_OK on success, others on failure.
520      */
521     int32_t RegisterPublishFormInterceptor(const sptr<IRemoteObject> &interceptorCallback);
522 
523     /**
524      * @brief Unregisters the callback for publish form. The callback is used to process the publish form request
525      * when the system handler is not found.
526      * @param interceptorCallback The injected callback, should implementation IFormPublishInterceptor.
527      * @return Returns ERR_OK on success, others on failure.
528      */
529     int32_t UnregisterPublishFormInterceptor(const sptr<IRemoteObject> &interceptorCallback);
530 
531     /**
532      * @brief Get external error from innerErrorCode.
533      * @param innerErrorCode innerErrorCode, get from FMS.
534      * @param externalErrorCode output externalErrorCode.
535      * @param errorMsg output errorMsg.
536      */
537     void GetExternalError(int32_t innerErrorCode, int32_t &externalErrorCode, std::string &errorMsg);
538 
539     /**
540      * @brief Get external error message by external error code.
541      *
542      * @param externalErrorCode External error code.
543      * @return External error message.
544      */
545     std::string GetErrorMsgByExternalErrorCode(int32_t externalErrorCode);
546 
547     /**
548      * @brief Register form add observer by bundle.
549      * @param bundleName BundleName of the form host
550      * @param callerToken Caller ability token.
551      * @return Returns ERR_OK on success, others on failure.
552      */
553     ErrCode RegisterFormAddObserverByBundle(const std::string bundleName, const sptr<IRemoteObject> &callerToken);
554 
555     /**
556      * @brief Register form remove observer by bundle.
557      * @param bundleName BundleName of the form host
558      * @param callerToken Caller ability token.
559      * @return Returns ERR_OK on success, others on failure.
560      */
561     ErrCode RegisterFormRemoveObserverByBundle(const std::string bundleName, const sptr<IRemoteObject> &callerToken);
562 
563     /**
564     * @brief get forms count.
565     * @param isTempFormFlag Indicates temp form or not.
566     * @param formCount Returns the number of the cast or temp form.
567     * @return Returns ERR_OK on success, others on failure.
568     */
569     int32_t GetFormsCount(bool isTempFormFlag, int32_t &formCount);
570 
571     /**
572     * @brief get host forms count.
573     * @param bundleName Indicates form host bundleName.
574     * @param formCount Returns the number of the host form.
575     * @return Returns ERR_OK on success, others on failure.
576     */
577     int32_t GetHostFormsCount(std::string &bundleName, int32_t &formCount);
578 
579     /**
580     * @brief Get form instances by filter info.
581     * @param formInstancesFilter includes bundleName, moduleName, formName, abilityName to get formInstances.
582     * @param formInstances return formInstances
583     * @return return ERR_OK on get info success, others on failure.
584     */
585     ErrCode GetFormInstancesByFilter(const FormInstancesFilter &formInstancesFilter,
586         std::vector<FormInstance> &formInstances);
587 
588    /**
589     * @brief Get form instance by formId.
590     * @param formId formId Indicates the unique id of form.
591     * @param formInstance return formInstance
592     * @return return ERR_OK on get info success, others on failure.
593     */
594     ErrCode GetFormInstanceById(const int64_t formId, FormInstance &formInstance);
595 
596     /**
597      * @brief Get form instance by formId, include form store in DB.
598      * @param formId formId Indicates the unique id of form.
599      * @param isUnusedIncluded Indicates whether to include unused form.
600      * @param formInstance return formInstance
601      * @return return ERR_OK on get info success, others on failure.
602      */
603     ErrCode GetFormInstanceById(const int64_t formId, bool isUnusedIncluded, FormInstance &formInstance);
604 
605     /**
606      * @brief Register form add observer.
607      * @param bundleName BundleName of the form host
608      * @param callerToken Caller ability token.
609      * @return Returns ERR_OK on success, others on failure.
610      */
611     ErrCode RegisterAddObserver(const std::string &bundleName, const sptr<IRemoteObject> &callerToken);
612 
613     /**
614      * @brief Register form remove observer.
615      * @param bundleName BundleName of the form host
616      * @param callerToken Caller ability token.
617      * @return Returns ERR_OK on success, others on failure.
618      */
619     ErrCode RegisterRemoveObserver(const std::string &bundleName, const sptr<IRemoteObject> &callerToken);
620 
621     /**
622      * @brief Register form router event proxy.
623      * @param formIds Indicates the ID of the forms.
624      * @param callerToken Router proxy call back client.
625      * @return Returns ERR_OK on success, others on failure.
626      */
627     ErrCode RegisterFormRouterProxy(const std::vector<int64_t> &formIds, const sptr<IRemoteObject> &callerToken);
628 
629     /**
630      * @brief Unregister form router event proxy.
631      * @param formIds Indicates the ID of the forms.
632      * @return Returns ERR_OK on success, others on failure.
633      */
634     ErrCode UnregisterFormRouterProxy(const std::vector<int64_t> &formIds);
635 
636     /**
637      * @brief Set forms recyclable
638      * @param formIds Indicates the id of the forms.
639      * @return Returns ERR_OK on success, others on failure.
640      */
641     int32_t SetFormsRecyclable(const std::vector<int64_t> &formIds);
642 
643     /**
644      * @brief Recycle forms
645      * @param formIds Indicates the id of the forms.
646      * @param want The want of forms to be recycled.
647      * @return Returns ERR_OK on success, others on failure.
648      */
649     int32_t RecycleForms(const std::vector<int64_t> &formIds, const Want &want);
650 
651     /**
652      * @brief Recover recycled forms
653      * @param formIds Indicates the id of the forms.
654      * @param want The want of forms to be recovered.
655      * @return Returns ERR_OK on success, others on failure.
656      */
657     int32_t RecoverForms(const std::vector<int64_t> &formIds, const Want &want);
658 
659     /**
660      * @brief Update formLocation with formId.
661      * @param formId The Id of the form to update.
662      * @param formLocation The FormLocation.
663      * @return Returns ERR_OK on success, others on failure.
664      */
665     ErrCode UpdateFormLocation(const int64_t &formId, const int32_t &formLocation);
666 
667     /**
668     * @brief Request to publish a form to the form host for normal authority.
669     *
670     * @param want The want of the form to publish.
671     * @param withFormBindingData Indicates whether the formBindingData is carried with.
672     * @param formBindingData Indicates the form data.
673     * @param formId Return the form id to be published.
674     * @return Returns ERR_OK on success, others on failure.
675     */
676     ErrCode RequestPublishFormWithSnapshot(Want &want, bool withFormBindingData,
677         std::unique_ptr<FormProviderData> &formBindingData, int64_t &formId,
678         const std::vector<FormDataProxy> &formDataProxies = {});
679 
680     /**
681      * @brief Update form with formRefreshType, send to form manager service.
682      * @param formRefreshType The type of the form to refresh, 0: AllForm 1: 2: AppForm 2: AtomicServiceForm
683      * @return Returns ERR_OK on success, others on failure.
684      */
685     int32_t BatchRefreshForms(const int32_t formRefreshType);
686 
687     /**
688      * @brief enable/disable form update.
689      * @param bundleName BundleName of the form host.
690      * @param enable True for enable form, false for disable form.
691      * @return Returns ERR_OK on success, others on failure.
692      */
693     int32_t EnableForms(const std::string bundleName, const bool enable);
694 
695     /**
696      * @brief Check form bundle is controlled.
697      * @param bundleName The bundle name of form to be check.
698      * @return Returns true for form bundle is controlled.
699      */
700     bool IsFormBundleForbidden(const std::string &bundleName);
701 
702     /**
703      * @brief Check form bundle is protected.
704      * @param bundleName The bundle name of form to be check.
705      * @param formId The Id of the form to query.
706      * @return Returns true for form bundle is protected.
707      */
708     bool IsFormBundleProtected(const std::string &bundleName, int64_t formId);
709 
710     /**
711      * @brief Check form bundle is exempt.
712      * @param formId The Id of the form to query.
713      * @return Returns true for form bundle is exempt.
714      */
715     bool IsFormBundleExempt(int64_t formId);
716 
717     /**
718      * @brief Notify the form is locked or not.
719      * @param formId Indicates the ID of the form.
720      * @param isLocked locked or not.
721      * @return Returns ERR_OK on success, others on failure.
722      */
723     int32_t NotifyFormLocked(const int64_t &formId, bool isLocked);
724 
725     /**
726      * @brief Update form size.
727      * @param formId The Id of the form to update.
728      * @param width The width value to be updated.
729      * @param height The height value to be updated.
730      * @param borderWidth The borderWidth value to be updated.
731      * @return Returns ERR_OK on success, others on failure.
732      */
733     int32_t UpdateFormSize(const int64_t formId, float width, float height, float borderWidth);
734 
735     /**
736      * @brief Open the form edit ability.
737      * @param abilityName The form edit ability name.
738      * @param formId The edit form ID.
739      * @param isMainPage Open the main edit page.
740      * @return Returns ERR_OK on success, others on failure.
741      */
742     ErrCode OpenFormEditAbility(const std::string &abilityName, const int64_t &formId, bool isMainPage);
743 
744     /**
745      * @brief Register overflow proxy in fms
746      * @param callerToken The form host proxy
747      * @return Return true for form register success
748      */
749     bool RegisterOverflowProxy(const sptr<IRemoteObject> &callerToken);
750 
751     /**
752      * @brief Unregister overflow proxy in fms
753      * @return Return true for if unregister success
754      */
755     bool UnregisterOverflowProxy();
756     /**
757      * @brief Request overflow with specific range
758      * @param formId The id of the form to request overflow
759      * @param overflowInfo The overflowInfo to explict overflow area and duration
760      * @param isOverflow True for request overflow, false for cancel overflow, default value is true
761      * @return Return ERR_OK on success, others on failure
762      */
763     ErrCode RequestOverflow(const int64_t formId, const OverflowInfo &overflowInfo, bool isOverflow = true);
764 
765     /**
766      * @brief Register change sceneAnimation state proxy in fms.
767      * @param callerToken The form host proxy.
768      * @return Returns true for change sceneAnimation state proxy register success.
769      */
770     bool RegisterChangeSceneAnimationStateProxy(const sptr<IRemoteObject> &callerToken);
771 
772     /**
773      * @brief Unregister change sceneAnimation state proxy in fms.
774      * @return Returns true for change sceneAnimation state proxy unregister success.
775      */
776     bool UnregisterChangeSceneAnimationStateProxy();
777 
778     /**
779      * @brief Change SceneAnimation State.
780      * @param formId The formId.
781      * @param state 1 for activate SceneAnimation, 0 for deactivate SceneAnimation
782      * @return Return ERR_OK on success, others on failure
783      */
784     ErrCode ChangeSceneAnimationState(const int64_t formId, int32_t state);
785 
786    /**
787      * @brief Register getFormRect proxy in fms.
788      * @param callerToken The form host proxy.
789      * @return Returns true for form register success
790      */
791     bool RegisterGetFormRectProxy(const sptr<IRemoteObject> &callerToken);
792 
793     /**
794      * @brief Unregister get form rect proxy in fms
795      * @return Return true if unregister success
796      */
797     bool UnregisterGetFormRectProxy();
798 
799     /**
800      * @brief Get the form rect.
801      * @param formId The formId.
802      * @param rect The desktop's rect related to the specified formId.
803      * @return Returns error code of method execute, which ERR_OK represents success.
804      */
805     ErrCode GetFormRect(const int64_t formId, Rect &rect);
806 
807     /**
808      * @brief Update form size.
809      * @param formId The Id of the form to update.
810      * @param newDimension The dimension value to be updated.
811      * @param newRect The rect value to be updated.
812      * @return Returns ERR_OK on success, others on failure.
813      */
814     ErrCode UpdateFormSize(const int64_t formId, const int32_t newDimension, const Rect &newRect);
815 
816     /**
817      * @brief Register getLiveFormStatus proxy in fms.
818      * @param callerToken The form host proxy.
819      * @return Returns true for form register success
820      */
821     bool RegisterGetLiveFormStatusProxy(const sptr<IRemoteObject> &callerToken);
822 
823     /**
824      * @brief Unregister get live form status proxy in fms
825      * @return Return true if unregister success
826      */
827     bool UnregisterGetLiveFormStatusProxy();
828 private:
829     /**
830      * @brief Connect form manager service.
831      * @return Returns ERR_OK on success, others on failure.
832      */
833     ErrCode Connect();
834 
835     /**
836     * @brief Reconnect form manager service once per 1000 milliseconds,
837     *        until the connection succeeds or reaching the max retry times.
838     * @return Returns true if execute success, false otherwise.
839     */
840     bool Reconnect();
841     /**
842      * @brief Reset proxy.
843      * @param remote remote object.
844      */
845     void ResetProxy(const wptr<IRemoteObject> &remote);
846 
847     /**
848      * @class FormMgrDeathRecipient
849      * FormMgrDeathRecipient notices IRemoteBroker died.
850      */
851     class FormMgrDeathRecipient : public IRemoteObject::DeathRecipient {
852     public:
853         FormMgrDeathRecipient() = default;
854         ~FormMgrDeathRecipient() = default;
855 
856         /**
857          * @brief Notices IRemoteBroker died.
858          * @param remote remote object.
859          */
860         void OnRemoteDied(const wptr<IRemoteObject> &remote) override;
861     private:
862         DISALLOW_COPY_AND_MOVE(FormMgrDeathRecipient);
863     };
864 
865     // Shared locks are used here, write locks are used for setting remoteProxy_ operations,
866     // and concurrent read locks are used for reading remoteProxy_ operations.
867     std::shared_mutex connectMutex_;
868     sptr<IFormMgr> remoteProxy_;
869 
870     sptr<IRemoteObject::DeathRecipient> deathRecipient_ {nullptr};
871 
872     // True: need to get a new fms remote object,
873     // False: no need to get a new fms remote object.
874     volatile bool resetFlag_ = false;
875 
876     std::vector<std::shared_ptr<FormCallbackInterface>> formDeathCallbacks_;
877 };
878 }  // namespace AppExecFwk
879 }  // namespace OHOS
880 #endif  // OHOS_FORM_FWK_FORM_MGR_H
881