• 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_ADAPTER_H
17 #define OHOS_FORM_FWK_FORM_MGR_ADAPTER_H
18 
19 #include <singleton.h>
20 
21 #include "app_mgr_interface.h"
22 #include "bundle_info.h"
23 #include "bundle_mgr_interface.h"
24 #include "form_constants.h"
25 #include "form_info.h"
26 #include "form_info_filter.h"
27 #include "form_instance.h"
28 #include "form_instances_filter.h"
29 #include "data_center/form_info/form_item_info.h"
30 #include "form_js_info.h"
31 #include "form_provider_data.h"
32 #include "form_publish_interceptor_interface.h"
33 #include "common/util/form_serial_queue.h"
34 #include "form_state_info.h"
35 #include "iremote_object.h"
36 #include "running_form_info.h"
37 #include "want.h"
38 #ifdef THEME_MGR_ENABLE
39 #include "theme_manager_client.h"
40 #endif
41 #include "configuration.h"
42 
43 namespace OHOS {
44 namespace AppExecFwk {
45 using Want = OHOS::AAFwk::Want;
46 using WantParams = OHOS::AAFwk::WantParams;
47 
48 enum class AddFormResultErrorCode : int8_t {
49     UNKNOWN = 0,
50     SUCCESS,
51     FAILED,
52     TIMEOUT
53 };
54 
55 /**
56  * @class FormMgrAdapter
57  * Form request handler from form host.
58  */
59 class FormMgrAdapter  final : public DelayedRefSingleton<FormMgrAdapter> {
60 DECLARE_DELAYED_REF_SINGLETON(FormMgrAdapter)
61 public:
62     DISALLOW_COPY_AND_MOVE(FormMgrAdapter);
63 
64     /**
65      * @brief Init properties like visibleNotifyDelayTime.
66      */
67     void Init();
68 
69     /**
70      * @brief Query the request host.
71      * @param want The want of the form to publish.
72      * @return Returns ERR_OK on success, others on failure.
73      */
74     ErrCode QueryPublishFormToHost(Want &want);
75 
76     /**
77      * @brief Add form with want, send want to form manager service.
78      * @param formId The Id of the forms to add.
79      * @param want The want of the form to add.
80      * @param callerToken Caller ability token.
81      * @param formInfo Form info.
82      * @return Returns ERR_OK on success, others on failure.
83      */
84     int AddForm(const int64_t formId, const Want &want, const sptr<IRemoteObject> &callerToken, FormJsInfo &formInfo);
85 
86     /**
87      * @brief Add form with want, send want to form manager service.
88      * @param want The want of the form to add.
89      * @param runningFormInfo Running form info.
90      * @return Returns ERR_OK on success, others on failure.
91      */
92     int CreateForm(const Want &want, RunningFormInfo &runningFormInfo);
93 
94     /**
95      * @brief Delete forms with formIds, send formIds to form manager service.
96      * @param formId The Id of the forms to delete.
97      * @param callerToken Caller ability token.
98      * @return Returns ERR_OK on success, others on failure.
99      */
100     int DeleteForm(const int64_t formId, const sptr<IRemoteObject> &callerToken);
101 
102     /**
103      * @brief Stop rendering form.
104      * @param formId The Id of the forms to delete.
105      * @param compId The compId of the forms to delete.
106      * @return Returns ERR_OK on success, others on failure.
107      */
108     int StopRenderingForm(const int64_t formId, const std::string &compId);
109 
110     /**
111      * @brief Release forms with formIds, send formIds to form Mgr service.
112      * @param formId The Id of the forms to release.
113      * @param callerToken Caller ability token.
114      * @param delCache Delete Cache or not.
115      * @return Returns ERR_OK on success, others on failure.
116      */
117     int ReleaseForm(const int64_t formId, const sptr<IRemoteObject> &callerToken, const bool delCache);
118 
119     /**
120      * @brief Update form with formId.
121      * @param formId The Id of the form to update.
122      * @param callingUid Provider ability uid.
123      * @param formProviderData form provider data.
124      * @param std::vector<FormDataProxy> Form proxy vector.
125      * @return Returns ERR_OK on success, others on failure.
126      */
127     int UpdateForm(const int64_t formId, const int32_t callingUid, const FormProviderData &formProviderData,
128         const std::vector<FormDataProxy> &formDataProxies = {});
129 
130     /**
131      * @brief Request form with formId and want, send formId and want to form manager service.
132      *
133      * @param formId The Id of the form to update.
134      * @param callerToken Caller ability token.
135      * @param want The want of the form to request.
136      * @return Returns ERR_OK on success, others on failure.
137      */
138     int RequestForm(const int64_t formId, const sptr<IRemoteObject> &callerToken, const Want &want);
139 
140     /**
141      * @brief Form visible/invisible notify, send formIds to form manager service.
142      *
143      * @param formIds The vector of form Ids.
144      * @param callerToken Caller ability token.
145      * @param formVisibleType The form visible type, including FORM_VISIBLE and FORM_INVISIBLE.
146      * @return Returns ERR_OK on success, others on failure.
147      */
148     ErrCode NotifyWhetherVisibleForms(const std::vector<int64_t> &formIds, const sptr<IRemoteObject> &callerToken,
149         const int32_t formVisibleType);
150 
151     /**
152      * @brief Query whether has visible form by tokenId.
153      * @param tokenId Unique identification of application.
154      * @return Returns true if has visible form, false otherwise.
155      */
156     bool HasFormVisible(const uint32_t tokenId);
157 
158     /**
159      * @brief Padding the formInstances map for visibleNotify.
160      * @param formVisibleType The form visible type, including FORM_VISIBLE and FORM_INVISIBLE.
161      * @param formId Form Id.
162      * @param formInstanceMaps formInstances for visibleNotify.
163      */
164     void PaddingNotifyVisibleFormsMap(const int32_t formVisibleType, int64_t formId,
165         std::map<std::string, std::vector<FormInstance>> &formInstanceMaps);
166 
167     /**
168      * @brief temp form to normal form.
169      * @param formId The Id of the form.
170      * @param callerToken Caller ability token.
171      * @return Returns ERR_OK on success, others on failure.
172      */
173     int CastTempForm(const int64_t formId, const sptr<IRemoteObject> &callerToken);
174 
175     /**
176      * @brief Dump all of form storage infos.
177      * @param formInfos All of form storage infos.
178      * @return Returns ERR_OK on success, others on failure.
179      */
180     int DumpStorageFormInfos(std::string &formInfos) const;
181     /**
182      * @brief Dump all of temporary form infos.
183      * @param formInfos All of temporary form infos.
184      * @return Returns ERR_OK on success, others on failure.
185      */
186     int DumpTemporaryFormInfos(std::string &formInfos) const;
187     /**
188      * @brief Dump form infos of all bundles, this is static info.
189      * @param formInfos All of static form infos.
190      * @return Returns ERR_OK on success, others on failure.
191      */
192     int DumpStaticBundleFormInfos(std::string &formInfos) const;
193 
194     /**
195      * @brief Dump has form visible with bundleInfo.
196      * @param bundleInfo Bundle info like bundleName_userId_instIndex.
197      * @param formInfos Form dump infos.
198      * @return Returns ERR_OK on success, others on failure.
199      */
200     int DumpHasFormVisible(const std::string &bundleInfo, std::string &formInfos) const;
201 
202     /**
203      * @brief Dump form info by a bundle name.
204      * @param bundleName The bundle name of form provider.
205      * @param formInfos Form infos.
206      * @return Returns ERR_OK on success, others on failure.
207      */
208     int DumpFormInfoByBundleName(const std::string &bundleName, std::string &formInfos) const;
209     /**
210      * @brief Dump form info by a bundle name.
211      * @param formId The id of the form.
212      * @param formInfo Form info.
213      * @return Returns ERR_OK on success, others on failure.
214      */
215     int DumpFormInfoByFormId(const std::int64_t formId, std::string &formInfo) const;
216     /**
217      * @brief Dump form timer by form id.
218      * @param formId The id of the form.
219      * @param isTimingService "true" or "false".
220      * @return Returns ERR_OK on success, others on failure.
221      */
222     int DumpFormTimerByFormId(const std::int64_t formId, std::string &isTimingService) const;
223 
224     /**
225      * @brief Dump running form info.
226      * @param runningFormInfosResult The dump info of all the running form info.
227      * @return Returns ERR_OK on success, others on failure.
228      */
229     int DumpFormRunningFormInfos(std::string &runningFormInfosResult) const;
230 
231     /**
232      * @brief set next refresh time.
233      * @param formId The id of the form.
234      * @param nextTime next refresh time.
235      * @return Returns ERR_OK on success, others on failure.
236      */
237     int SetNextRefreshTime(const int64_t formId, const int64_t nextTime);
238 
239     /**
240      * @brief Release renderer.
241      * @param formId The Id of the forms to release.
242      * @param compId The compId of the forms to release.
243      * @return Returns ERR_OK on success, others on failure.
244      */
245     int ReleaseRenderer(int64_t formId, const std::string &compId);
246 
247     /**
248      * @brief Request to publish a form to the form host.
249      *
250      * @param want The want of the form to publish.
251      * @param withFormBindingData Indicates whether the formBindingData is carried with.
252      * @param formBindingData Indicates the form data.
253      * @param formId Return the form id to be published.
254      * @param needCheckFormPermission Indicates whether the app have system permissions.default value is true.
255      * @return Returns ERR_OK on success, others on failure.
256      */
257     ErrCode RequestPublishForm(Want &want, bool withFormBindingData,
258         std::unique_ptr<FormProviderData> &formBindingData, int64_t &formId,
259         const std::vector<FormDataProxy> &formDataProxies = {}, bool needCheckFormPermission = true);
260 
261     ErrCode StartAbilityByFms(const Want &want);
262 
263     ErrCode SetPublishFormResult(const int64_t formId, Constants::PublishFormResult &errorCodeInfo);
264 
265     ErrCode AcquireAddFormResult(const int64_t formId);
266     /**
267      * @brief Check if the request of publishing a form is supported by the host.
268      * @return Returns true if the request is supported and false otherwise.
269      */
270     bool IsRequestPublishFormSupported();
271 
272     /**
273      * @brief enable update form.
274      * @param formIDs The id of the forms.
275      * @param callerToken Caller ability token.
276      * @return Returns ERR_OK on success, others on failure.
277      */
278     int EnableUpdateForm(const std::vector<int64_t> formIDs, const sptr<IRemoteObject> &callerToken);
279 
280     /**
281      * @brief disable update form.
282      * @param formIDs The id of the forms.
283      * @param callerToken Caller ability token.
284      * @return Returns ERR_OK on success, others on failure.
285      */
286     int DisableUpdateForm(const std::vector<int64_t> formIDs, const sptr<IRemoteObject> &callerToken);
287 
288     /**
289      * @brief Process js message event.
290      * @param formId Indicates the unique id of form.
291      * @param want information passed to supplier.
292      * @param callerToken Caller ability token.
293      * @return Returns true if execute success, false otherwise.
294      */
295     int MessageEvent(const int64_t formId, const Want &want, const sptr<IRemoteObject> &callerToken);
296 
297     /**
298      * @brief Process js router event.
299      * @param formId Indicates the unique id of form.
300      * @param want the want of the ability to start.
301      * @param callerToken Caller ability token.
302      * @return Returns true if execute success, false otherwise.
303      */
304     int RouterEvent(const int64_t formId, Want &want, const sptr<IRemoteObject> &callerToken);
305 
306     /**
307      * @brief Process background router event.
308      * @param formId Indicates the unique id of form.
309      * @param want the want of the ability to start.
310      * @param callerToken Caller ability token.
311      * @return Returns true if execute success, false otherwise.
312      */
313     int BackgroundEvent(const int64_t formId, Want &want, const sptr<IRemoteObject> &callerToken);
314 
315     /**
316      * @brief Delete the invalid forms.
317      * @param formIds Indicates the ID of the valid forms.
318      * @param callerToken Caller ability token.
319      * @param numFormsDeleted Returns the number of the deleted forms.
320      * @return Returns ERR_OK on success, others on failure.
321      */
322     int DeleteInvalidForms(const std::vector<int64_t> &formIds, const sptr<IRemoteObject> &callerToken,
323                            int32_t &numFormsDeleted);
324 
325     /**
326      * @brief Acquire form state info by passing a set of parameters (using Want) to the form provider.
327      * @param want Indicates a set of parameters to be transparently passed to the form provider.
328      * @param callerToken Caller ability token.
329      * @param stateInfo Returns the form's state info of the specify.
330      * @return Returns ERR_OK on success, others on failure.
331      */
332     int AcquireFormState(const Want &want, const sptr<IRemoteObject> &callerToken, FormStateInfo &stateInfo);
333 
334     /**
335      * @brief Acquire form data by formId.
336      * @param formId The Id of the form to acquire data.
337      * @param callerToken Indicates the host client.
338      * @param requestCode The request code of this acquire form.
339      * @param formData Return the forms' information of customization
340      * @return Returns ERR_OK on success, others on failure.
341      */
342     int AcquireFormData(int64_t formId, int64_t requestCode, const sptr<IRemoteObject> &callerToken,
343          AAFwk::WantParams &formData);
344 
345     /**
346      * @brief Notify the form is visible or not.
347      * @param formIds Indicates the ID of the forms.
348      * @param isVisible Visible or not.
349      * @param callerToken Host client.
350      * @return Returns ERR_OK on success, others on failure.
351      */
352     int NotifyFormsVisible(const std::vector<int64_t> &formIds, bool isVisible, const sptr<IRemoteObject> &callerToken);
353 
354     /**
355      * @brief Notify the form is enable to be updated or not.
356      * @param formIds Indicates the ID of the forms.
357      * @param isEnableUpdate enable update or not.
358      * @param callerToken Host client.
359      * @return Returns ERR_OK on success, others on failure.
360      */
361     int NotifyFormsEnableUpdate(const std::vector<int64_t> &formIds, bool isEnableUpdate,
362                                 const sptr<IRemoteObject> &callerToken);
363 
364     /**
365       * @brief Get All FormsInfo.
366       * @param formInfos Return the forms' information of all forms provided.
367       * @return Returns ERR_OK on success, others on failure.
368       */
369     int GetAllFormsInfo(std::vector<FormInfo> &formInfos);
370 
371     /**
372      * @brief Get forms info by bundle name .
373      * @param bundleName Application name.
374      * @param formInfos Return the forms' information of the specify application name.
375      * @return Returns ERR_OK on success, others on failure.
376      */
377     int GetFormsInfoByApp(const std::string &bundleName, std::vector<FormInfo> &formInfos);
378 
379     /**
380      * @brief Get forms info by bundle name and module name.
381      * @param bundleName bundle name.
382      * @param moduleName Module name of hap.
383      * @param formInfos Return the forms' information of the specify bundle name and module name.
384      * @return Returns ERR_OK on success, others on failure.
385      */
386     int GetFormsInfoByModule(const std::string &bundleName, const std::string &moduleName,
387         std::vector<FormInfo> &formInfos);
388 
389     /**
390      * @brief Get forms info specfied by filter parameters.
391      * @param filter Filter that contains necessary conditions, such as bundle name, module name, dimensions.
392      * @param formInfos Return the forms' information specified by filter.
393      * @return Returns ERR_OK on success, others on failure.
394      */
395     int GetFormsInfoByFilter(const FormInfoFilter &filter, std::vector<FormInfo> &formInfos);
396 
397     /**
398     * @brief get forms count.
399     * @param isTempFormFlag Indicates temp form or not.
400     * @param formCount Returns the number of the cast or temp form.
401     * @return Returns ERR_OK on success, others on failure.
402     */
403     int32_t GetFormsCount(bool isTempFormFlag, int32_t &formCount);
404 
405     /**
406     * @brief get host forms count.
407     * @param bundleName Indicates form host bundleName.
408     * @param formCount Returns the number of the host form.
409     * @return Returns ERR_OK on success, others on failure.
410     */
411     int32_t GetHostFormsCount(std::string &bundleName, int32_t &formCount);
412 
413     /**
414      * @brief Handle form add observer.
415      * @return Returns ERR_OK on success, others on failure.
416      */
417     ErrCode HandleFormAddObserver(const int64_t formId);
418 
419     /**
420      * @brief Handle form add observer.
421      * @param runningFormInfo the running forms' infos of the specify application name.
422      * @return Returns ERR_OK on success, others on failure.
423      */
424     ErrCode HandleFormRemoveObserver(const RunningFormInfo runningFormInfo);
425 
426     /**
427      * @brief Register form add observer by bundle.
428      * @param bundleName BundleName of the form host
429      * @param callerToken Caller ability token.
430      * @return Returns ERR_OK on success, others on failure.
431      */
432     ErrCode RegisterFormAddObserverByBundle(const std::string bundleName, const sptr<IRemoteObject> &callerToken);
433 
434     /**
435      * @brief Register form remove observer by bundle.
436      * @param bundleName BundleName of the form host
437      * @param callerToken Caller ability token.
438      * @return Returns ERR_OK on success, others on failure.
439      */
440     ErrCode RegisterFormRemoveObserverByBundle(const std::string bundleName, const sptr<IRemoteObject> &callerToken);
441 
442     /**
443      * @brief Get all running form infos.
444      * @param isUnusedIncluded Indicates whether to include unused forms.
445      * @param runningFormInfos Return the running forms' infos currently.
446      * @return Returns ERR_OK on success, others on failure.
447      */
448     ErrCode GetRunningFormInfos(bool isUnusedIncluded, std::vector<RunningFormInfo> &runningFormInfos);
449 
450     /**
451      * @brief Get the running form infos by bundle name.
452      * @param bundleName Application name.
453      * @param isUnusedIncluded Indicates whether to include unused forms.
454      * @param runningFormInfos Return the running forms' infos of the specify application name.
455      * @return Returns ERR_OK on success, others on failure.
456      */
457     ErrCode GetRunningFormInfosByBundleName(
458         const std::string &bundleName, bool isUnusedIncluded, std::vector<RunningFormInfo> &runningFormInfos);
459 
460     /**
461      * @brief Get form instances by filter info.
462      * @param formInstancesFilter includes bundleName, moduleName, formName, abilityName to get formInstances.
463      * @param formInstances return formInstances
464      * @return return ERR_OK on get info success, others on failure.
465      */
466     ErrCode GetFormInstancesByFilter(const FormInstancesFilter &formInstancesFilter,
467         std::vector<FormInstance> &formInstances);
468 
469     /**
470      * @brief Get form instance by formId.
471      * @param formId formId Indicates the unique id of form.
472      * @param formInstance return formInstance
473      * @return return ERR_OK on get info success, others on failure.
474      */
475     ErrCode GetFormInstanceById(const int64_t formId, FormInstance &formInstance);
476 
477     /**
478      * @brief Get form instance by formId, include form store in DB.
479      * @param formId formId Indicates the unique id of form.
480      * @param isUnusedIncluded Indicates whether to include unused form.
481      * @param formInstance return formInstance
482      * @return return ERR_OK on get info success, others on failure.
483      */
484     ErrCode GetFormInstanceById(const int64_t formId, bool isUnusedIncluded, FormInstance &formInstance);
485 
486     /**
487      * @brief Register form add observer.
488      * @param bundleName BundleName of the form host
489      * @param callerToken Caller ability token.
490      * @return Returns ERR_OK on success, others on failure.
491      */
492     ErrCode RegisterAddObserver(const std::string &bundleName, const sptr<IRemoteObject> &callerToken);
493 
494     /**
495      * @brief Register form remove observer.
496      * @param bundleName BundleName of the form host
497      * @param callerToken Caller ability token.
498      * @return Returns ERR_OK on success, others on failure.
499      */
500     ErrCode RegisterRemoveObserver(const std::string &bundleName, const sptr<IRemoteObject> &callerToken);
501 
502     /**
503      * @brief Register form router event proxy.
504      * @param formIds Indicates the ID of the forms.
505      * @param callerToken Router proxy call back client.
506      * @return Returns ERR_OK on success, others on failure.
507      */
508     ErrCode RegisterFormRouterProxy(const std::vector<int64_t> &formIds, const sptr<IRemoteObject> &callerToken);
509 
510     /**
511      * @brief Unregister form router event proxy.
512      * @param formIds Indicates the ID of the forms.
513      * @return Returns ERR_OK on success, others on failure.
514      */
515     ErrCode UnregisterFormRouterProxy(const std::vector<int64_t> &formIds);
516 
517     /**
518      * @brief Registers the callback for publish form. The callback is used to process the publish form request
519      * when the system handler is not found.
520      * @param interceptorCallback The injected callback, should implementation IFormPublishInterceptor.
521      * @return Returns ERR_OK on success, others on failure.
522      */
523     int32_t RegisterPublishFormInterceptor(const sptr<IRemoteObject> &interceptorCallback);
524 
525     /**
526      * @brief Unregisters the callback for publish form. The callback is used to process the publish form request
527      * when the system handler is not found.
528      * @param interceptorCallback The injected callback, should implementation IFormPublishInterceptor.
529      * @return Returns ERR_OK on success, others on failure.
530      */
531     int32_t UnregisterPublishFormInterceptor(const sptr<IRemoteObject> &interceptorCallback);
532 
533     /**
534      * @brief Register click callback observer.
535      * @param bundleName BundleName of the form host.
536      * @param formEventType Form event type.
537      * @param callerToken Caller ability token.
538      * @return Returns ERR_OK on success, others on failure.
539      */
540     ErrCode RegisterClickEventObserver(
541         const std::string &bundleName, const std::string &formEventType, const sptr<IRemoteObject> &observer);
542 
543     /**
544      * @brief Unregister click callback observer.
545      * @param bundleName BundleName of the form host.
546      * @param formEventType Form event type.
547      * @param callerToken Caller ability token.
548      * @return Returns ERR_OK on success, others on failure.
549      */
550     ErrCode UnregisterClickEventObserver(
551         const std::string &bundleName, const std::string &formEventType, const sptr<IRemoteObject> &observer);
552 
553     /**
554      * @brief Compare the locally configured update duration with the update duration in additionalInfo and
555      * return a larger value.
556      * @param formId The Id of the form.
557      * @param updateDuration The valid form update duration.
558      * @return Returns true on success, false on failure.
559      */
560     bool GetValidFormUpdateDuration(const int64_t formId, int64_t &updateDuration) const;
561 
562     /**
563      * @brief Handle forms visible/invisible notify after delay time, notification will be cancelled when
564      * formVisibleState recovered during the delay time.
565      * @param formIds the Ids of forms need to notify.
566      * @param formInstanceMaps formInstances for visibleNotify.
567      * @param eventMaps eventMaps for event notify.
568      * @param formVisibleType The form visible type, including FORM_VISIBLE and FORM_INVISIBLE.
569      * @param callerToken Caller ability token.
570      */
571     void HandlerNotifyWhetherVisibleForms(const std::vector<int64_t> &formIds,
572         std::map<std::string, std::vector<FormInstance>> formInstanceMaps,
573         std::map<std::string, std::vector<int64_t>> eventMaps, const int32_t formVisibleType,
574         const sptr<IRemoteObject> &callerToken);
575 
576     /**
577      * @brief Set forms recyclable
578      * @param formIds Indicates the id of the forms.
579      * @return Returns ERR_OK on success, others on failure.
580      */
581     int32_t SetFormsRecyclable(const std::vector<int64_t> &formIds);
582 
583     /**
584      * @brief Recycle forms
585      * @param formIds Indicates the id of the forms.
586      * @param want The want of forms to be recycled.
587      * @param isCheckCallingUid is need check CallingUid, default is true.
588      * @return Returns ERR_OK on success, others on failure.
589      */
590     int32_t RecycleForms(const std::vector<int64_t> &formIds, const Want &want, bool isCheckCallingUid = true);
591 
592     /**
593      * @brief Recover recycled forms
594      * @param formIds Indicates the id of the forms.
595      * @param want The want of forms to be recovered.
596      * @return Returns ERR_OK on success, others on failure.
597      */
598     int32_t RecoverForms(const std::vector<int64_t> &formIds, const Want &want);
599 
600     /**
601      * @brief Update form cloud update duration when additionalInfo changed.
602      * @param bundleName The bundleName of the form with a specified update duration in app gallery.
603      */
604     void UpdateFormCloudUpdateDuration(const std::string &bundleName);
605 
606     /**
607     * @brief Update formLocation with formId.
608     * @param formId The Id of the form to update.
609     * @param formLocation formLocation.
610     * @param isRequestPublishFormWithSnapshot is request publish form with snapshot, default is false.
611     * @return Returns ERR_OK on success, others on failure.
612     */
613     ErrCode UpdateFormLocation(const int64_t &formId, const int32_t &formLocation,
614         const bool isRequestPublishFormWithSnapshot = false);
615 
616     /**
617      * @brief Update form with formRefreshType, send to form manager service.
618      * @param formRefreshType The type of the form to refresh, 0: AllForm 1: 2: AppForm 2: AtomicServiceForm
619      * @return Returns ERR_OK on success, others on failure.
620      */
621     ErrCode BatchRefreshForms(const int32_t formRefreshType);
622 
623     /**
624      * @brief notify formAbility when system configuration changed.
625      * @param configuration system config
626      * @return Returns ERR_OK on success, others on failure.
627      */
628     ErrCode BatchNotifyFormsConfigurationUpdate(const AppExecFwk::Configuration &configuration);
629 #ifdef RES_SCHEDULE_ENABLE
630     /**
631      * @brief Set the value which indicate whether Refresh Timer task should be triggered.
632      * @param isTimerTaskNeeded The value of whether Refresh Timer task should be triggered.
633      */
634     void SetTimerTaskNeeded(bool isTimerTaskNeeded);
635 #endif // RES_SCHEDULE_ENABLE
636 
637     /**
638      * @brief enable/disable form update.
639      * @param bundleName BundleName of the form host.
640      * @param enable True for enable form, false for disable form.
641      * @return Returns ERR_OK on success, others on failure.
642      */
643     int32_t EnableForms(const std::string bundleName, const bool enable);
644 
645     /**
646      * @brief this interface is invoked when the application lock status changes.
647      * @param bundleName BundleName of the form host.
648      * @param lock True for lock bundle, false for unlock bundle.
649      * @return Returns ERR_OK on success, others on failure.
650      */
651     ErrCode SwitchLockForms(const std::string &bundleName, int32_t userId, const bool lock);
652 
653     /**
654      * @brief this interface is invoked when the application protect status changes.
655      * @param bundleName BundleName of the form host.
656      * @param lock True for protect form, false for unprotect form.
657      * @return Returns ERR_OK on success, others on failure.
658      */
659     ErrCode ProtectLockForms(const std::string &bundleName, int32_t userId, const bool protect);
660 
661     /**
662      * @brief Update form size.
663      * @param formId The Id of the form to update.
664      * @param width The width value to be updated.
665      * @param height The height value to be updated.
666      * @param borderWidth The borderWidth value to be updated.
667      * @return Returns ERR_OK on success, others on failure.
668      */
669     ErrCode UpdateFormSize(const int64_t &formId, float width, float height, float borderWidth);
670 
671     int32_t OnNotifyRefreshForm(const int64_t &formId);
672 
673     /**
674      * @brief Update form by condition.
675      * @param UpdateType The type of the form to update.
676      * @return Returns ERR_OK on success, others on failure.
677      */
678     ErrCode UpdateFormByCondition(int type);
679 
680     /**
681      * @brief Notify the form is locked or not.
682      * @param formId Indicates the ID of the form.
683      * @param isLocked locked or not.
684      * @return Returns ERR_OK on success, others on failure.
685      */
686     int32_t NotifyFormLocked(const int64_t &formId, bool isLocked);
687 
688     /**
689      * @brief Register overflow proxy
690      * @param callerToken The form host proxy
691      * @return Return true for overflow proxy register success, false otherwise
692      */
693     bool RegisterOverflowProxy(const sptr<IRemoteObject> &callerToken);
694 
695     /**
696      * @brief Unregister overflow proxy
697      * @return Return true for overflow proxy unregister success, false otherwise
698      */
699     bool UnregisterOverflowProxy();
700 
701     /**
702      * @brief Request overflow with specific range
703      * @param formId The id of the form to request overflow
704      * @param callingUid Provider ability uid.
705      * @param overflowInfo The overflowInfo to explict overflow area and duration
706      * @param isOverflow True for request overflow, false for cancel overflow, default value is true
707      * @return Return ERR_OK on success, others on failure
708      */
709     ErrCode RequestOverflow(const int64_t formId, const int32_t callingUid,
710         const OverflowInfo &overflowInfo, bool isOverflow = true);
711 
712     /**
713      * @brief Register change sceneAnimation state proxy
714      * @param callerToken The form host proxy.
715      * @return Returns true for change sceneAnimation state proxy register success, false otherwise
716      */
717     bool RegisterChangeSceneAnimationStateProxy(const sptr<IRemoteObject> &callerToken);
718 
719     /**
720      * @brief Unregister change sceneAnimation state proxy
721      * @return Return true for change sceneAnimation state proxy unregister success, false otherwise
722      */
723     bool UnregisterChangeSceneAnimationStateProxy();
724 
725     /**
726      * @brief Change SceneAnimation State.
727      * @param formId The formId.
728      * @param callingUid Provider ability uid.
729      * @param state 1 for activate SceneAnimation, 0 for deactivate SceneAnimation
730      * @return Return ERR_OK on success, others on failure
731      */
732     ErrCode ChangeSceneAnimationState(const int64_t formId, const int32_t callingUid, int32_t state);
733 
734     /**
735      * @brief Set get form rect proxy in fms.
736      * @param callerToken The form host proxy.
737      * @return Returns ERR_OK for setting success.
738      */
739     bool RegisterGetFormRectProxy(const sptr<IRemoteObject> &callerToken);
740 
741     /**
742      * @brief Unregister get form rect proxy in fms
743      * @return Return true if unregister success
744      */
745     bool UnregisterGetFormRectProxy();
746 
747     /**
748      * @brief Get the form rect.
749      * @param formId The formId.
750      * @param callingUid Provider ability uid.
751      * @param rect The desktop's rect related to the specified formId.
752      * @return Returns error code of method execute, which ERR_OK represents success.
753      */
754     ErrCode GetFormRect(const int64_t formId, const int32_t callingUid, Rect &rect);
755 
756     /**
757      * @brief Set get live form status proxy in fms.
758      * @param callerToken The form host proxy.
759      * @return Returns ERR_OK for setting success.
760      */
761     bool RegisterGetLiveFormStatusProxy(const sptr<IRemoteObject> &callerToken);
762 
763     /**
764      * @brief Unregister get live form status proxy in fms
765      * @return Return true if unregister success
766      */
767     bool UnregisterGetLiveFormStatusProxy();
768 
769     /**
770      * @brief Get live form status.
771      * @param liveFormStatusMap The Map that stores formId and live form status.
772      * @return Returns error code of method execute, which ERR_OK represents success.
773      */
774     ErrCode GetLiveFormStatus(std::unordered_map<std::string, std::string> &liveFormStatusMap);
775 
776     /**
777      * @brief Update form size.
778      * @param formId The Id of the form to update.
779      * @param newDimension The dimension value to be updated.
780      * @param newRect The rect value to be updated.
781      * @return Returns ERR_OK on success, others on failure.
782      */
783     ErrCode UpdateFormSize(const int64_t formId, const int32_t newDimension, const Rect &newRect);
784 
785     /**
786      * @brief Delay refresh forms task when provider update.
787      * @param updatedForms Need refresh forms.
788      * @param want The want of the request.
789      * @return Returns ERR_OK on success, others on failure.
790      */
791     void DelayRefreshForms(const std::vector<FormRecord> &updatedForms, const Want &want);
792 private:
793     /**
794      * @brief Get form configure info.
795      * @param want The want of the request.
796      * @param formItemInfo Form configure info.
797      * @return Returns ERR_OK on success, others on failure.
798      */
799     ErrCode GetFormConfigInfo(const Want& want, FormItemInfo &formItemInfo);
800 
801     /**
802      * @brief Get bundle info.
803      * @param want The want of the request.
804      * @param bundleInfo Bundle info.
805      * @param packageName Package name.
806      * @return Returns ERR_OK on success, others on failure.
807      */
808     ErrCode GetBundleInfo(const AAFwk::Want &want, BundleInfo &bundleInfo, std::string &packageName);
809 
810     /**
811      * @brief Get form info.
812      * @param want The want of the request.
813      * @param formInfo Form info.
814      * @return Returns ERR_OK on success, others on failure.
815      */
816     ErrCode GetFormInfo(const AAFwk::Want &want, FormInfo &formInfo);
817 
818     /**
819      * @brief Get form configure info.
820      * @param want The want of the request.
821      * @param bundleInfo Bundle info.
822      * @param formInfo Form info.
823      * @param formItemInfo Form configure info.
824      * @return Returns ERR_OK on success, others on failure.
825      */
826     ErrCode GetFormItemInfo(const AAFwk::Want &want, const BundleInfo &bundleInfo, const FormInfo &formInfo,
827         FormItemInfo &formItemInfo);
828 
829     /**
830      * @brief Dimension valid check.
831      * @param formInfo Form info.
832      * @param dimensionId Dimension id.
833      * @return Returns true on success, false on failure.
834      */
835     bool IsDimensionValid(const FormInfo &formInfo, int dimensionId) const;
836 
837     /**
838      * @brief Create form configure info.
839      * @param bundleInfo Bundle info.
840      * @param formInfo Form info.
841      * @param itemInfo Form configure info.
842      * @param want The want of the request.
843      * @return Returns ERR_OK on success, others on failure.
844      */
845     ErrCode CreateFormItemInfo(const BundleInfo& bundleInfo, const FormInfo& formInfo, FormItemInfo& itemInfo,
846         const AAFwk::Want &want);
847 
848     /**
849      * @brief Set form item info params.
850      * @param bundleInfo Bundle info.
851      * @param formInfo Form info.
852      * @param itemInfo Form item info.
853      */
854     void SetFormItemInfoParams(const BundleInfo& bundleInfo, const FormInfo& formInfo, FormItemInfo& itemInfo);
855 
856     /**
857      * @brief Set form item module info.
858      * @param hapModuleInfo Hap module info.
859      * @param formInfo Form info.
860      * @param itemInfo Form item info.
861      */
862     void SetFormItemModuleInfo(const HapModuleInfo& hapModuleInfo, const FormInfo& formInfo,
863         FormItemInfo& itemInfo);
864 
865     /**
866      * @brief Allocate form by formId.
867      * @param info Form configure info.
868      * @param callerToken Caller ability token.
869      * @param wantParams WantParams of the request.
870      * @param formInfo Form info for form host.
871      * @return Returns ERR_OK on success, others on failure.
872      */
873     ErrCode AllotFormById(const FormItemInfo &info, const sptr<IRemoteObject> &callerToken,
874         const WantParams &wantParams, FormJsInfo &formInfo);
875 
876     /**
877      * @brief Allocate form by form configure info.
878      * @param info Form configure info.
879      * @param callerToken Caller ability token.
880      * @param wantParams WantParams of the request.
881      * @param formInfo Form info for form host.
882      * @return Returns ERR_OK on success, others on failure.
883      */
884     ErrCode AllotFormByInfo(const FormItemInfo &info, const sptr<IRemoteObject> &callerToken,
885         const WantParams& wantParams, FormJsInfo &formInfo);
886 
887     /**
888      * @brief Acquire form data from form provider.
889      * @param formId The Id of the form..
890      * @param info Form configure info.
891      * @param wantParams WantParams of the request.
892      * @return Returns ERR_OK on success, others on failure.
893      */
894     ErrCode AcquireProviderFormInfoAsync(const int64_t formId, const FormItemInfo &info, const WantParams &wantParams);
895 
896     ErrCode InnerAcquireProviderFormInfoAsync(const int64_t formId,
897         const FormItemInfo &info, const WantParams &wantParams);
898 
899     /**
900      * @brief Handle release form.
901      * @param formId The form id.
902      * @param callerToken Caller ability token.
903      * @return Returns ERR_OK on success, others on failure.
904      */
905     ErrCode HandleReleaseForm(const int64_t formId, const sptr<IRemoteObject> &callerToken);
906 
907     /**
908      * @brief Handle delete form.
909      * @param formId The form id.
910      * @param callerToken Caller ability token.
911      * @return Returns ERR_OK on success, others on failure.
912      */
913     ErrCode HandleDeleteForm(const int64_t formId, const sptr<IRemoteObject> &callerToken);
914 
915     /**
916      * @brief Handle delete temp form.
917      * @param formId The form id.
918      * @param callerToken Caller ability token.
919      * @return Returns ERR_OK on success, others on failure.
920      */
921     ErrCode HandleDeleteTempForm(const int64_t formId, const sptr<IRemoteObject> &callerToken);
922 
923     /**
924      * @brief Handle delete form storage.
925      * @param dbRecord Form storage information.
926      * @param uid calling user id.
927      * @param formId The form id.
928      * @return Function result and has other host flag.
929      */
930     ErrCode HandleDeleteFormCache(FormRecord &dbRecord, const int uid, const int64_t formId);
931 
932     /**
933      * @brief Add existed form record.
934      * @param info Form configure info.
935      * @param callerToken Caller ability token.
936      * @param record Form data.
937      * @param formId The form id.
938      * @param wantParams WantParams of the request.
939      * @param formInfo Form info for form host.
940      * @return Returns ERR_OK on success, others on failure.
941      */
942     ErrCode AddExistFormRecord(const FormItemInfo &info, const sptr<IRemoteObject> &callerToken,
943         const FormRecord &record, const int64_t formId, const WantParams &wantParams, FormJsInfo &formInfo);
944 
945     /**
946      * @brief Add new form record.
947      * @param info Form configure info.
948      * @param formId The form id.
949      * @param callerToken Caller ability token.
950      * @param wantParams WantParams of the request.
951      * @param formInfo Form info for form host.
952      * @return Returns ERR_OK on success, others on failure.
953      */
954     ErrCode AddNewFormRecord(const FormItemInfo &info, const int64_t formId,
955         const sptr<IRemoteObject> &callerToken, const WantParams &wantParams, FormJsInfo &formInfo);
956 
957     /**
958      * @brief Send event notify to form provider. The event notify type include FORM_VISIBLE and FORM_INVISIBLE.
959      *
960      * @param providerKey The provider key string which consists of the provider bundle name and ability name.
961      * @param formIdsByProvider The map of form Ids and their event type which have the same provider.
962      * @param formVisibleType The form visible type, including FORM_VISIBLE and FORM_INVISIBLE.
963      * @return Returns ERR_OK on success, others on failure.
964      */
965     ErrCode HandleEventNotify(const std::string &providerKey, const std::vector<int64_t> &formIdsByProvider,
966         const int32_t formVisibleType);
967 
968     /**
969      * @brief Increase the timer refresh count.
970      *
971      * @param formId The form id.
972      */
973     void IncreaseTimerRefreshCount(const int64_t formId);
974 
975     /**
976      * @brief handle update form flag.
977      * @param formIDs The id of the forms.
978      * @param callerToken Caller ability token.
979      * @param flag form flag.
980      * @param isOnlyEnableUpdate form enable update form flag.
981      * @return Returns ERR_OK on success, others on failure.
982      */
983     ErrCode HandleUpdateFormFlag(const std::vector<int64_t> &formIds, const sptr<IRemoteObject> &callerToken,
984                                  bool flag, bool isOnlyEnableUpdate);
985 
986     /**
987      * @brief check form cached.
988      * @param record Form information.
989      * @return Returns true on cached, false on not.
990      */
991     bool IsFormCached(const FormRecord record);
992 
993     /**
994      * @brief check if update is valid.
995      * @param formId The form's id.
996      * @param bundleName Provider ability bundleName.
997      * @return Returns true or false.
998      */
999     bool IsUpdateValid(const int64_t formId, const std::string &bundleName);
1000     /**
1001      * @brief Handle cast temp form.
1002      * @param formId The form id.
1003      * @param record Form information.
1004      * @return Returns ERR_OK on success, others on failure.
1005      */
1006     ErrCode HandleCastTempForm(const int64_t formId, const FormRecord &record);
1007 
1008     /**
1009      * @brief Add form timer.
1010      * @param formRecord Form information.
1011      * @return Returns ERR_OK on success, others on failure.
1012      */
1013     ErrCode AddFormTimer(const FormRecord &formRecord);
1014 
1015     /**
1016      * @brief Genera checking the publish form.
1017      * @param want The want of the form to publish.
1018      * @param bundleName BundleName
1019      * @param needCheckFormPermission Indicates whether the app have system permissions.default value is true.
1020      * @return Returns ERR_OK on success, others on failure.
1021      */
1022     ErrCode CheckFormBundleName(Want &want, std::string &bundleName, bool needCheckFormPermission);
1023 
1024     /**
1025      * @brief check the publish form.
1026      * @param want The want of the form to publish.
1027      * @param needCheckFormPermission Indicates whether the app have system permissions.default value is true.
1028      * @return Returns ERR_OK on success, others on failure.
1029      */
1030     ErrCode CheckPublishForm(Want &want, bool needCheckFormPermission = true);
1031 
1032     /**
1033      * @brief Post request publish form to host.
1034      * @param want The want of the form to publish.
1035      * @return Returns ERR_OK on success, others on failure.
1036      */
1037     ErrCode RequestPublishFormToHost(Want &want);
1038 
1039     /**
1040      * @brief check request publish form want.
1041      * @param want The want of the form to publish.
1042      * @return Returns true if have snapshot info, others on none.
1043      */
1044     bool CheckSnapshotWant(const Want &want);
1045 
1046     /**
1047      * @brief check the argv of AddRequestPublishForm.
1048      * @param want The want of the form to add.
1049      * @param formProviderWant The want of the form to publish from provider.
1050      * @return Returns ERR_OK on success, others on failure.
1051      */
1052     ErrCode CheckAddRequestPublishForm(const Want &want, const Want &formProviderWant);
1053 
1054     /**
1055      * @brief add request publish form.
1056      * @param formItemInfo Form configure info.
1057      * @param want The want of the form to add.
1058      * @param callerToken Caller ability token.
1059      * @param formJsInfo Return form info to form host.
1060      * @return Returns ERR_OK on success, others on failure.
1061      */
1062     ErrCode AddRequestPublishForm(const FormItemInfo &formItemInfo, const Want &want,
1063         const sptr<IRemoteObject> &callerToken, FormJsInfo &formJsInfo);
1064 
1065     /**
1066      * @brief get bundleName.
1067      * @param bundleName for output.
1068      * @param needCheckFormPermission Indicates whether the app have system permissions.default value is true.
1069      * @return Returns true on success, others on failure.
1070      */
1071     bool GetBundleName(std::string &bundleName, bool needCheckFormPermission = true);
1072 
1073     /**
1074      * @brief Check if the form should update information to the host.
1075      *
1076      * @param matchedFormId The Id of the form
1077      * @param userId User ID.
1078      * @param callerToken Caller ability token.
1079      * @param formRecord Form storage information
1080      * @return Returns true on success, false on failure.
1081      */
1082     bool isFormShouldUpdateProviderInfoToHost(const int64_t &matchedFormId, const int32_t &userId,
1083         const sptr<IRemoteObject> &callerToken, FormRecord &formRecord);
1084 
1085     /**
1086      * @brief Update provider info to host
1087      *
1088      * @param matchedFormId The Id of the form
1089      * @param userId User ID.
1090      * @param callerToken Caller ability token.
1091      * @param formVisibleType The form visible type, including FORM_VISIBLE and FORM_INVISIBLE.
1092      * @param formRecord Form storage information
1093      * @return Returns true on success, false on failure.
1094      */
1095     bool UpdateProviderInfoToHost(const int64_t &matchedFormId, const int32_t &userId,
1096         const sptr<IRemoteObject> &callerToken, const int32_t &formVisibleType, FormRecord &formRecord);
1097 
1098     /**
1099      * @brief if the ability have permission for keeping background running is true,
1100      * @param iBundleMgr BundleManagerProxy
1101      * @param bundleName BundleName
1102      * @param userId UserId
1103      * @return Returns true if the form provider is system app, false if not.
1104      */
1105     bool CheckIsSystemAppByBundleName(const sptr<IBundleMgr> &iBundleMgr,
1106         const int32_t &userId, const std::string &bundleName);
1107 
1108     /**
1109      * @brief if the ability have permission for keeping background running is true,
1110      * @param iBundleMgr BundleManagerProxy
1111      * @param bundleName BundleName
1112      * @return Returns true if the ability have permission for keeping background running, false if not.
1113      */
1114     bool CheckKeepBackgroundRunningPermission(const sptr<IBundleMgr> &iBundleMgr, const std::string &bundleName);
1115     /**
1116      * @brief Create eventMaps for event notify.
1117      *
1118      * @param matchedFormId The Id of the form
1119      * @param formRecord Form storage information
1120      * @param eventMaps eventMaps for event notify
1121      * @return Returns true on success, false on failure.
1122      */
1123     bool CreateHandleEventMap(const int64_t matchedFormId, const FormRecord &formRecord,
1124         std::map<std::string, std::vector<int64_t>> &eventMaps);
1125     /**
1126      * @brief Get current user ID.
1127      * @param callingUid calling Uid.
1128      * @return Returns user ID.
1129      */
1130     int32_t GetCurrentUserId(const int callingUid);
1131     /**
1132      * @brief AcquireFormState want check.
1133      * @param bundleName The bundle name of the form.
1134      * @param abilityName The ability name of the form.
1135      * @param want The want of the form.
1136      * @param provider the provider info.
1137      * @return Returns ERR_OK on success, others on failure.
1138      */
1139     ErrCode AcquireFormStateCheck(const std::string &bundleName, const std::string &abilityName, const Want &want,
1140                                   std::string &provider);
1141     /**
1142      * @brief check if the form host is system app
1143      * @param formRecord Form storage information
1144      * @return Returns true if the form host is system app, false if not.
1145      */
1146     bool checkFormHostHasSaUid(const FormRecord &formRecord);
1147 
1148     /**
1149      * @brief Check whether the caller for publish form is in the whitelist.
1150      * @param iBundleMgr BundleManagerProxy
1151      * @param bundleName BundleName of caller
1152      * @param want want of target form
1153      * @param needCheckFormPermission Indicates whether the app have system permissions.default value is true.
1154      * @return Returns true if the caller is in the whitelist, others if not.
1155      */
1156     bool IsValidPublishEvent(const sptr<IBundleMgr> &iBundleMgr, const std::string &bundleName, const Want &want,
1157         bool needCheckFormPermission = true);
1158 
1159     /**
1160      * @brief Allocate form by specific Id.
1161      * @param info Form configure info.
1162      * @param callerToken Caller ability token.
1163      * @param wantParams WantParams of the request.
1164      * @param formInfo Form info for form host.
1165      * @return Returns ERR_OK on success, others on failure.
1166      */
1167     ErrCode AllotFormBySpecificId(const FormItemInfo &info,
1168         const sptr<IRemoteObject> &callerToken, const WantParams &wantParams, FormJsInfo &formInfo);
1169 
1170     /**
1171      * @brief when form observer died clean the resource.
1172      * @param remote remote object.
1173      */
1174     void CleanResource(const wptr<IRemoteObject> &remote);
1175 
1176     /**
1177      * @brief Set value of deathRecipient_.
1178      * @param callerToken Caller ability token.
1179      * @param deathRecipient DeathRecipient object.
1180      */
1181     void SetDeathRecipient(const sptr<IRemoteObject> &callerToken,
1182         const sptr<IRemoteObject::DeathRecipient> &deathRecipient);
1183     mutable std::mutex formObserversMutex_;
1184     mutable std::mutex deathRecipientsMutex_;
1185     std::map<std::string, std::vector<sptr<IRemoteObject>>> formObservers_;
1186     std::map<sptr<IRemoteObject>, sptr<IRemoteObject::DeathRecipient>> deathRecipients_;
1187 
1188     void NotifyFormClickEvent(int64_t formId, const std::string &formClickType);
1189 
1190     /**
1191      * @brief Get caller type.
1192      * @param bundleName the caller's bundle name.
1193      */
1194     int32_t GetCallerType(std::string bundleName);
1195 
1196     /**
1197      * @brief Check if the form is allow to publish.
1198      * @param bundleName the caller's bundle name.
1199      * @param wants Wants of the request.
1200      */
1201     bool IsErmsSupportPublishForm(std::string bundleName, std::vector<Want> wants);
1202 
1203     /**
1204      * @brief Check if the caller is formRenderService.
1205      * @param callingUid the caller's Uid.
1206      * @return Returns true if the caller is formRenderService, false if not.
1207      */
1208     bool IsFormRenderServiceCall(int callingUid);
1209 
1210     /**
1211      * @brief Notify forms visible/invisible to remoteCallers.
1212      * @param bundleName the caller's bundle name.
1213      * @param remoteObjects refs of remoteCallers.
1214      * @param formInstanceMaps formInstances for visibleNotify.
1215      * @param formVisibleType The form visible type, including FORM_VISIBLE and FORM_INVISIBLE.
1216      */
1217     void NotifyWhetherFormsVisible(const std::string &bundleName,
1218         std::vector<sptr<IRemoteObject>> &remoteObjects,
1219         std::map<std::string, std::vector<FormInstance>> &formInstanceMaps, const int32_t formVisibleType);
1220 
1221     /**
1222      * @brief Forms formInstanceMaps or eventMaps should remove when visible/invisible status recovered.
1223      * @param formInstanceMaps formInstances for visibleNotify.
1224      * @param eventMaps eventMaps for event notify.
1225      * @param formVisibleType The form visible type, including FORM_VISIBLE and FORM_INVISIBLE.
1226      */
1227     void FilterDataByVisibleType(std::map<std::string, std::vector<FormInstance>> &formInstanceMaps,
1228         std::map<std::string, std::vector<int64_t>> &eventMaps, const int32_t formVisibleType);
1229 
1230     /**
1231      * @brief Forms formInstanceMaps should remove when visible/invisible status recovered.
1232      * @param formInstanceMaps formInstances for visibleNotify.
1233      * @param formVisibleType The form visible type, including FORM_VISIBLE and FORM_INVISIBLE.
1234      * @param restoreFormRecords formRecords of forms no need to notify.
1235      */
1236     void FilterFormInstanceMapsByVisibleType(std::map<std::string, std::vector<FormInstance>> &formInstanceMaps,
1237         const int32_t formVisibleType, std::map<int64_t, FormRecord> &restoreFormRecords);
1238 
1239     /**
1240      * @brief Forms eventMaps should remove when visible/invisible status recovered.
1241      * @param eventMaps eventMaps for event notify.
1242      * @param formVisibleType The form visible type, including FORM_VISIBLE and FORM_INVISIBLE.
1243      * @param restoreFormRecords formRecords of forms no need to notify.
1244      */
1245     void FilterEventMapsByVisibleType(std::map<std::string, std::vector<int64_t>> &eventMaps,
1246         const int32_t formVisibleType, std::map<int64_t, FormRecord> &restoreFormRecords);
1247 
1248     ErrCode CheckFormCountLimit(const int64_t formId, const Want &want);
1249 
1250     ErrCode AllotForm(const int64_t formId, const Want &want,
1251         const sptr<IRemoteObject> &callerToken, FormJsInfo &formInfo, const FormItemInfo &formItemInfo);
1252 
1253     void GetUpdateDurationFromAdditionalInfo(const std::string &additionalInfo, std::vector<int> &durationArray) const;
1254 
1255     void IncreaseAddFormRequestTimeOutTask(const int64_t formId);
1256 
1257     void CancelAddFormRequestTimeOutTask(const int64_t formId, const int result);
1258 
1259     AddFormResultErrorCode GetFormResultErrCode(const int64_t formId);
1260 
1261     ErrCode CheckAddFormTaskTimeoutOrFailed(const int64_t formId, AddFormResultErrorCode &formStates);
1262 
1263     void RemoveFormIdMapElement(const int64_t formId);
1264 
1265     void UpdateReUpdateFormMap(const int64_t formId);
1266 
1267     void SetReUpdateFormMap(const int64_t formId);
1268 
1269     ErrCode UpdateTimer(const int64_t formId, const FormRecord &record);
1270 
1271     void SetFormEnableAndLockState(FormInfo &formInfo, FormItemInfo &formConfigInfo, int formLocation);
1272 
1273     void SetLockFormStateOfFormItemInfo(FormInfo &formInfo, FormItemInfo &formConfigInfo);
1274 
1275     bool IsActionAllowToPublish(const std::string &action);
1276 
1277     /**
1278      * @brief Get form info by form record.
1279      * @param record The record of the form.
1280      * @param formInfo Form info.
1281      * @return Returns ERR_OK on success, others on failure.
1282      */
1283     ErrCode GetFormInfoByFormRecord(const FormRecord &record, FormInfo &formInfo);
1284 
1285     /**
1286      * @brief Get calling user ID.
1287      * @return Returns user ID.
1288      */
1289     int32_t GetCallingUserId();
1290     /**
1291      * @class ClientDeathRecipient
1292      * notices IRemoteBroker died.
1293      */
1294     class ClientDeathRecipient : public IRemoteObject::DeathRecipient {
1295     public:
1296         /**
1297          * @brief Constructor
1298          */
1299         ClientDeathRecipient() = default;
1300         virtual ~ClientDeathRecipient() = default;
1301         /**
1302          * @brief handle remote object died event.
1303          * @param remote remote object.
1304          */
1305         void OnRemoteDied(const wptr<IRemoteObject> &remote) override;
1306     };
1307 
1308     /**
1309      * @brief Check sceneAnimation request parameter legitimacy.
1310      * @param formId The formId.
1311      * @param callingUid Provider ability uid.
1312      * @return Return ERR_OK on success, others on failure
1313      */
1314     ErrCode SceneAnimationCheck(const int64_t formId, const int32_t callingUid);
1315 
1316     /**
1317      * @brief Check caller parameter legitimacy.
1318      * @param formId The formId.
1319      * @param callingUid Provider ability uid.
1320      * @return Return ERR_OK on success, others on failure
1321      */
1322     ErrCode CallerCheck(const int64_t formId, const int32_t callingUid);
1323 private:
1324     sptr<IFormPublishInterceptor> formPublishInterceptor_ = nullptr;
1325     int32_t visibleNotifyDelay_ = Constants::DEFAULT_VISIBLE_NOTIFY_DELAY;
1326     std::map<int64_t, AddFormResultErrorCode> formIdMap_;
1327     std::unique_ptr<FormSerialQueue> serialQueue_ = nullptr;
1328     std::mutex formResultMutex_;
1329     std::condition_variable condition_;
1330 #ifdef THEME_MGR_ENABLE
1331     /**
1332      * @brief Fill ThemeFormInfo with want and formId
1333      * @param formId Indicates the id of form.
1334      * @param themeFormInfo Info of theme form defined by ThemeManager.
1335      * @param want The want of form.
1336      */
1337     void FillThemeFormInfo(const Want &want, ThemeManager::ThemeFormInfo &themeFormInfo, int64_t formId);
1338 
1339     /**
1340      * @brief Call ThemeManager to delete form and clear record in database.
1341      * @param formId Indicates the id of form.
1342      * @return Returns ERR_OK on success, others on failure.
1343      */
1344     int DeleteThemeForm(const int64_t formId);
1345 
1346     /**
1347      * @brief Add theme form record in database.
1348      * @param want The want of form.
1349      * @param formId Indicates the id of form.
1350      * @return Returns ERR_OK on success, others on failure.
1351      */
1352     int AddThemeDBRecord(const Want &want, int64_t formId);
1353 
1354     /**
1355      * @brief Allot theme form record in FormDataMgr.
1356      * @param want The want of form.
1357      * @param formId Indicates the id of form.
1358      * @return Returns formrecord created.
1359      */
1360     FormRecord AllotThemeRecord(const Want &want, int64_t formId);
1361 #endif
1362 
1363     /**
1364      * @brief Delete common forms with formId.
1365      * @param formId Indicates the id of form.
1366      * @param callerToken Caller ability token.
1367      * @return Returns ERR_OK on success, others on failure.
1368      */
1369     int DeleteCommonForm(const int64_t formId, const sptr<IRemoteObject> &callerToken);
1370 
1371     void CheckUpdateFormRecord(const int64_t formId, const FormItemInfo &info, FormRecord &record);
1372 
1373     void SetVisibleChange(const int64_t formId, const int32_t formVisibleType);
1374 
1375     /**
1376     * @brief Post Form visible/invisible notify.
1377     * @param formIds  the Ids of forms need to notify.
1378     * @param formInstanceMaps formInstances for visibleNotify.
1379     * @param eventMaps eventMaps for event notify.
1380     * @param formVisibleType The form visible type, including FORM_VISIBLE and FORM_INVISIBLE.
1381     * @param visibleNotifyDelay delay time.
1382     * @param callerToken Caller ability token.
1383     */
1384     void PostVisibleNotify(const std::vector<int64_t> &formIds,
1385         std::map<std::string, std::vector<FormInstance>> &formInstanceMaps,
1386         std::map<std::string, std::vector<int64_t>> &eventMaps,
1387         const int32_t formVisibleType, int32_t visibleNotifyDelay,
1388         const sptr<IRemoteObject> &callerToken);
1389 
1390     sptr<OHOS::AppExecFwk::IAppMgr> GetAppMgr();
1391 
1392     void PostEnterpriseAppInstallFailedRetryTask(const FormRecord &record, const Want &want);
1393 
1394     std::mutex reUpdateFormMapMutex_;
1395     std::unordered_map<int64_t, std::pair<int64_t, bool>> reUpdateFormMap_;
1396 
1397     std::map<int, std::vector<int64_t>> conditionUpdateFormMap;
1398 
1399     bool IsForegroundApp();
1400 
1401     sptr<IRemoteObject> overflowCallerToken_;
1402 
1403     sptr<IRemoteObject> sceneanimationCallerToken_;
1404 
1405     sptr<IRemoteObject> getFormRectCallerToken_;
1406 
1407     sptr<IRemoteObject> getLiveFormStatusCallerToken_;
1408 };
1409 }  // namespace AppExecFwk
1410 }  // namespace OHOS
1411 
1412 #endif // OHOS_FORM_FWK_FORM_MGR_ADAPTER_H
1413