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_SERVICE_H
17 #define OHOS_FORM_FWK_FORM_MGR_SERVICE_H
18 
19 #include <singleton.h>
20 #include <system_ability.h>
21 
22 #include "form_event_handler.h"
23 #include "form_instance.h"
24 #include "form_instances_filter.h"
25 #include "form_mgr_stub.h"
26 #include "form_provider_data.h"
27 #include "form_serial_queue.h"
28 #include "form_sys_event_receiver.h"
29 #include "iremote_object.h"
30 #include "mem_status_listener.h"
31 namespace OHOS {
32 namespace AppExecFwk {
33 enum class ServiceRunningState {
34     STATE_NOT_START,
35     STATE_RUNNING,
36 };
37 /**
38  * @class FormMgrService
39  * FormMgrService provides a facility for managing form life cycle.
40  */
41 class FormMgrService : public SystemAbility,
42                        public FormMgrStub,
43                        public std::enable_shared_from_this<FormMgrService> {
44     DECLARE_DELAYED_SINGLETON(FormMgrService);
45     DECLEAR_SYSTEM_ABILITY(FormMgrService);
46 public:
47     /**
48      * @brief Start event for the form manager service.
49      */
50     void OnStart() override;
51     /**
52      * @brief Stop event for the form manager service.
53      */
54     void OnStop() override;
55 
56     /**
57      * @brief Add form with want, send want to form manager service.
58      * @param formId The Id of the forms to add.
59      * @param want The want of the form to add.
60      * @param callerToken Caller ability token.
61      * @param formInfo Form info.
62      * @return Returns ERR_OK on success, others on failure.
63      */
64     int AddForm(const int64_t formId, const Want &want, const sptr<IRemoteObject> &callerToken,
65         FormJsInfo &formInfo) override;
66 
67     /**
68      * @brief Add form with want, send want to form manager service.
69      * @param want The want of the form to add.
70      * @param runningFormInfo Running form info.
71      * @return Returns ERR_OK on success, others on failure.
72      */
73     int CreateForm(const Want &want, RunningFormInfo &runningFormInfo) override;
74 
75     /**
76      * @brief Delete forms with formIds, send formIds to form manager service.
77      * @param formId The Id of the forms to delete.
78      * @param callerToken Caller ability token.
79      * @return Returns ERR_OK on success, others on failure.
80      */
81     int DeleteForm(const int64_t formId, const sptr<IRemoteObject> &callerToken) override;
82 
83     /**
84      * @brief Stop rendering form.
85      * @param formId The Id of the forms to delete.
86      * @param compId The compId of the forms to delete.
87      * @return Returns ERR_OK on success, others on failure.
88      */
89     int StopRenderingForm(const int64_t formId, const std::string &compId) override;
90 
91     /**
92      * @brief Release forms with formIds, send formIds to form manager service.
93      * @param formId The Id of the forms to release.
94      * @param callerToken Caller ability token.
95      * @param delCache Delete Cache or not.
96      * @return Returns ERR_OK on success, others on failure.
97      */
98     int ReleaseForm(const int64_t formId, const sptr<IRemoteObject> &callerToken, const bool delCache) override;
99 
100     /**
101      * @brief Update form with formId, send formId to form manager service.
102      * @param formId The Id of the form to update.
103      * @param bundleName Provider ability bundleName.
104      * @param FormProviderData Form binding data.
105      * @return Returns ERR_OK on success, others on failure.
106      */
107     int UpdateForm(const int64_t formId, const FormProviderData &FormProviderData) override;
108 
109     /**
110      * @brief set next refresh time.
111      * @param formId The id of the form.
112      * @param nextTime next refresh time.
113      * @return Returns ERR_OK on success, others on failure.
114      */
115     int SetNextRefreshTime(const int64_t formId, const int64_t nextTime) override;
116 
117     /**
118      * @brief Release renderer.
119      * @param formId The Id of the forms to release.
120      * @param compId The compId of the forms to release.
121      * @return Returns ERR_OK on success, others on failure.
122      */
123     int ReleaseRenderer(int64_t formId, const std::string &compId) override;
124 
125     /**
126      * @brief Request to publish a form to the form host.
127      *
128      * @param want The want of the form to publish.
129      * @param withFormBindingData Indicates whether the formBindingData is carried with.
130      * @param formBindingData Indicates the form data.
131      * @param formId Return the form id to be published.
132      * @return Returns ERR_OK on success, others on failure.
133      */
134     ErrCode RequestPublishForm(Want &want, bool withFormBindingData,
135                                std::unique_ptr<FormProviderData> &formBindingData, int64_t &formId) override;
136 
137     ErrCode SetPublishFormResult(const int64_t formId, Constants::PublishFormResult &errorCodeInfo) override;
138 
139     ErrCode AcquireAddFormResult(const int64_t formId) override;
140 
141     /**
142      * @brief Request to publish a form to the form host for normal authority.
143      *
144      * @param want The want of the form to publish.
145      * @param withFormBindingData Indicates whether the formBindingData is carried with.
146      * @param formBindingData Indicates the form data.
147      * @param formId Return the form id to be published.
148      * @return Returns ERR_OK on success, others on failure.
149      */
150     ErrCode RequestPublishFormWithSnapshot(Want &want, bool withFormBindingData,
151         std::unique_ptr<FormProviderData> &formBindingData, int64_t &formId) override;
152     /**
153      * @brief lifecycle update.
154      * @param formIds formIds of host client.
155      * @param callerToken Caller ability token.
156      * @param updateType update type, enable if true and disable if false.
157      * @return Returns true on success, false on failure.
158      */
159     int LifecycleUpdate(const std::vector<int64_t> &formIds, const sptr<IRemoteObject> &callerToken,
160         bool updateType) override;
161 
162     /**
163      * @brief Request form with formId and want, send formId and want to form manager service.
164      * @param formId The Id of the form to update.
165      * @param callerToken Caller ability token.
166      * @param want The want of the form to add.
167      * @return Returns ERR_OK on success, others on failure.
168      */
169     int RequestForm(const int64_t formId, const sptr<IRemoteObject> &callerToken, const Want &want) override;
170 
171     /**
172      * @brief Form visible/invisible notify, send formIds to form manager service.
173      * @param formIds The Id list of the forms to notify.
174      * @param callerToken Caller ability token.
175      * @param formVisibleType The form visible type, including FORM_VISIBLE and FORM_INVISIBLE.
176      * @return Returns ERR_OK on success, others on failure.
177      */
178     int NotifyWhetherVisibleForms(const std::vector<int64_t> &formIds, const sptr<IRemoteObject> &callerToken,
179         const int32_t formVisibleType) override;
180 
181     /**
182      * @brief temp form to normal form.
183      * @param formId The Id of the form.
184      * @param callerToken Caller ability token.
185      * @return Returns ERR_OK on success, others on failure.
186      */
187     int CastTempForm(const int64_t formId, const sptr<IRemoteObject> &callerToken) override;
188 
189     /**
190      * @brief Query whether has visible form by tokenId.
191      * @param tokenId Unique identification of application.
192      * @return Returns true if has visible form, false otherwise.
193      */
194     bool HasFormVisible(const uint32_t tokenId) override;
195 
196     /**
197      * @brief Dump all of form storage infos.
198      * @param formInfos All of form storage infos.
199      * @return Returns ERR_OK on success, others on failure.
200      */
201     int DumpStorageFormInfos(std::string &formInfos) override;
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) override;
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) override;
216     /**
217      * @brief Dump form timer by form id.
218      * @param formId The id of the form.
219      * @param formInfo Form info.
220      * @return Returns ERR_OK on success, others on failure.
221      */
222     int DumpFormTimerByFormId(const std::int64_t formId, std::string &isTimingService) override;
223     /**
224      * @brief Process js message event.
225      * @param formId Indicates the unique id of form.
226      * @param want information passed to supplier.
227      * @param callerToken Caller ability token.
228      * @return Returns true if execute success, false otherwise.
229      */
230     int MessageEvent(const int64_t formId, const Want &want, const sptr<IRemoteObject> &callerToken) override;
231 
232     /**
233      * @brief Process js router event.
234      * @param formId Indicates the unique id of form.
235      * @param want the want of the ability to start.
236      * @param callerToken Caller ability token.
237      * @return Returns true if execute success, false otherwise.
238      */
239     int RouterEvent(const int64_t formId, Want &want, const sptr<IRemoteObject> &callerToken) override;
240 
241     /**
242      * @brief Process Background event.
243      * @param formId Indicates the unique id of form.
244      * @param want the want of the ability to start.
245      * @param callerToken Caller ability token.
246      * @return Returns true if execute success, false otherwise.
247      */
248     int BackgroundEvent(const int64_t formId, Want &want, const sptr<IRemoteObject> &callerToken) override;
249 
250     /**
251      * @brief Delete the invalid forms.
252      * @param formIds Indicates the ID of the valid forms.
253      * @param callerToken Caller ability token.
254      * @param numFormsDeleted Returns the number of the deleted forms.
255      * @return Returns ERR_OK on success, others on failure.
256      */
257     virtual int DeleteInvalidForms(const std::vector<int64_t> &formIds, const sptr<IRemoteObject> &callerToken,
258                                    int32_t &numFormsDeleted) override;
259 
260     /**
261      * @brief Acquire form state info by passing a set of parameters (using Want) to the form provider.
262      * @param want Indicates a set of parameters to be transparently passed to the form provider.
263      * @param callerToken Caller ability token.
264      * @param stateInfo Returns the form's state info of the specify.
265      * @return Returns ERR_OK on success, others on failure.
266      */
267     virtual int AcquireFormState(const Want &want, const sptr<IRemoteObject> &callerToken,
268                                  FormStateInfo &stateInfo) override;
269 
270     /**
271      * @brief Register form router event proxy.
272      * @param formIds Indicates the ID of the forms.
273      * @param callerToken Host client.
274      * @return Returns ERR_OK on success, others on failure.
275      */
276     virtual ErrCode RegisterFormRouterProxy(const std::vector<int64_t> &formIds,
277                                             const sptr<IRemoteObject> &callerToken) override;
278 
279     /**
280      * @brief Unregister form router event proxy.
281      * @param formIds Indicates the ID of the forms.
282      * @return Returns ERR_OK on success, others on failure.
283      */
284     virtual ErrCode UnregisterFormRouterProxy(const std::vector<int64_t> &formIds) override;
285 
286     /**
287      * @brief Notify the form is visible or not.
288      * @param formIds Indicates the ID of the forms.
289      * @param isVisible Visible or not.
290      * @param callerToken Host client.
291      * @return Returns ERR_OK on success, others on failure.
292      */
293     virtual int NotifyFormsVisible(const std::vector<int64_t> &formIds, bool isVisible,
294                                    const sptr<IRemoteObject> &callerToken) override;
295 
296     /**
297      * @brief Notify the form is privacy protected or not.
298      * @param formIds Indicates the ID of the forms.
299      * @param isProtected isProtected or not.
300      * @param callerToken Host client.
301      * @return Returns ERR_OK on success, others on failure.
302      */
303     int NotifyFormsPrivacyProtected(const std::vector<int64_t> &formIds, bool isProtected,
304                                             const sptr<IRemoteObject> &callerToken) override;
305 
306     /**
307      * @brief Notify the form is enable to be updated or not.
308      * @param formIds Indicates the ID of the forms.
309      * @param isEnableUpdate enable update or not.
310      * @param callerToken Host client.
311      * @return Returns ERR_OK on success, others on failure.
312      */
313     virtual int NotifyFormsEnableUpdate(const std::vector<int64_t> &formIds, bool isEnableUpdate,
314                                         const sptr<IRemoteObject> &callerToken) override;
315 
316     /**
317      * @brief Get All FormsInfo.
318      * @param formInfos Return the forms' information of all forms provided.
319      * @return Returns ERR_OK on success, others on failure.
320      */
321     int GetAllFormsInfo(std::vector<FormInfo> &formInfos) override;
322 
323     /**
324      * @brief Get forms info by bundle name .
325      * @param bundleName Application name.
326      * @param formInfos Return the forms' information of the specify application name.
327      * @return Returns ERR_OK on success, others on failure.
328      */
329     int GetFormsInfoByApp(std::string &bundleName, std::vector<FormInfo> &formInfos) override;
330 
331     /**
332      * @brief Get forms info by bundle name and module name.
333      * @param bundleName bundle name.
334      * @param moduleName Module name of hap.
335      * @param formInfos Return the forms' information of the specify bundle name and module name.
336      * @return Returns ERR_OK on success, others on failure.
337      */
338     int GetFormsInfoByModule(std::string &bundleName, std::string &moduleName,
339                              std::vector<FormInfo> &formInfos) override;
340 
341     /**
342     * @brief This function is called by host and gets formsInfos info specifild by filter.
343     * @param filter Filter that contains necessary conditions, such as bundle name, module name, dimensions.
344     * @param formInfos Return the forms' information specified by filter.
345     * @return Returns ERR_OK on success, others on failure.
346     */
347     int GetFormsInfoByFilter(const FormInfoFilter &filter, std::vector<FormInfo> &formInfos) override;
348 
349     /**
350     * @brief This function is called by formProvider and gets forms info by the bundle name of the calling ability.
351     *        The bundle name will be retrieved here.
352     * @param filter Filter that contains attributes that the formInfos have to have.
353     * @param formInfos Return the forms' information of the calling bundle name
354     * @return Returns ERR_OK on success, others on failure.
355     */
356     int32_t GetFormsInfo(const FormInfoFilter &filter, std::vector<FormInfo> &formInfos) override;
357 
358     /**
359      * @brief Acquire form data by formId.
360      * @param formId The Id of the form to acquire data.
361      * @param callerToken Indicates the host client.
362      * @param requestCode The request code of this acquire form.
363      * @param formData Return the forms' information of customization
364      * @return Returns ERR_OK on success, others on failure.
365      */
366     int32_t AcquireFormData(int64_t formId, int64_t requestCode, const sptr<IRemoteObject> &callerToken,
367         AAFwk::WantParams &formData) override;
368 
369     /**
370      * @brief Check if the request of publishing a form is supported by the host.
371      * @return Returns true if the request is supported and false otherwise.
372      */
373     bool IsRequestPublishFormSupported() override;
374 
375     /**
376      * @brief Start an ability. This function can only be called by a form extension of a system app.
377      * @param want includes ability name, parameters and relative info sending to an ability.
378      * @param callerToken token of the ability that initially calls this function.
379      * @return Returns ERR_OK on success, others on failure.
380      */
381     int32_t StartAbility(const Want &want, const sptr<IRemoteObject> &callerToken) override;
382 
383     /**
384      * @brief Share form by formID and deviceID.
385      * @param formId Indicates the unique id of form.
386      * @param deviceId Indicates the remote device ID.
387      * @param callerToken Indicates the host client.
388      * @param requestCode The request code of this share form.
389      * @return Returns ERR_OK on success, others on failure.
390      */
391     int32_t ShareForm(int64_t formId, const std::string &deviceId,
392         const sptr<IRemoteObject> &callerToken, int64_t requestCode) override;
393 
394     /**
395      * @brief Receive form sharing information from remote.
396      * @param info Indicates form sharing information.
397      * @return Returns ERR_OK on success, others on failure.
398      */
399     int32_t RecvFormShareInfoFromRemote(const FormShareInfo &info) override;
400 
401     /**
402      * @brief Dump form.
403      * @param fd Indicates the file descriptor for result.
404      * @param args Indicates the input arguments.
405      * @return Returns ERR_OK on success, others on failure.
406      */
407     int Dump(int fd, const std::vector<std::u16string> &args) override;
408 
409     /**
410      * @brief Register form add observer by bundle.
411      * @param bundleName BundleName of the form host
412      * @param callerToken Caller ability token.
413      * @return Returns ERR_OK on success, others on failure.
414      */
415     ErrCode RegisterFormAddObserverByBundle(const std::string bundleName,
416         const sptr<IRemoteObject> &callerToken) override;
417 
418     /**
419      * @brief Register form remove observer by bundle.
420      * @param bundleName BundleName of the form host
421      * @param callerToken Caller ability token.
422      * @return Returns ERR_OK on success, others on failure.
423      */
424     ErrCode RegisterFormRemoveObserverByBundle(const std::string bundleName,
425         const sptr<IRemoteObject> &callerToken) override;
426 
427     /**
428     * @brief Check form manager service ready.
429     * @return Return true if form manager service Ready; return false otherwise.
430     */
431     bool CheckFMSReady() override;
432 
433     /**
434      * @brief Check whether the form is system app.
435      * @param bundleName The bundleName of the form.
436      * @return Returns true if the form app is system, others false.
437      */
438     bool IsSystemAppForm(const std::string &bundleName) override;
439 
440     /**
441      * @brief The Call Event triggers the callee method.
442      * @param funcName function name which is used by callee.
443      * @param params parameter which is used by callee.
444      * @return Returns ERR_OK on success, others on failure.
445      */
SetBackgroundFunction(const std::string funcName,const std::string params)446     int32_t SetBackgroundFunction(const std::string funcName, const std::string params) override
447     {
448         return ERR_OK;
449     }
450     /**
451     * @brief get forms count.
452     * @param isTempFormFlag Indicates temp form or not.
453     * @param formCount Returns the number of the cast or temp form.
454     * @return Returns ERR_OK on success, others on failure.
455     */
456     int32_t GetFormsCount(bool isTempFormFlag, int32_t &formCount) override;
457 
458     /**
459     * @brief get host forms count.
460     * @param bundleName Indicates form host bundleName.
461     * @param formCount Returns the number of the host form.
462     * @return Returns ERR_OK on success, others on failure.
463     */
464     int32_t GetHostFormsCount(std::string &bundleName, int32_t &formCount) override;
465 
466     /**
467      * @brief Get all running form infos.
468      * @param isUnusedIncluded Indicates whether to include unused forms.
469      * @param runningFormInfos Return the running forms' infos currently.
470      * @return Returns ERR_OK on success, others on failure.
471      */
472     ErrCode GetRunningFormInfos(bool isUnusedIncluded, std::vector<RunningFormInfo> &runningFormInfos) override;
473 
474     /**
475      * @brief Get the running form infos by bundle name.
476      * @param bundleName Application name.
477      * @param isUnusedIncluded Indicates whether to include unused forms.
478      * @param runningFormInfos Return the running forms' infos of the specify application name.
479      * @return Returns ERR_OK on success, others on failure.
480      */
481     ErrCode GetRunningFormInfosByBundleName(
482         const std::string &bundleName, bool isUnusedIncluded, std::vector<RunningFormInfo> &runningFormInfos) override;
483 
484     /**
485      * @brief Get form instances by filter info.
486      * @param formInstancesFilter include bundleName, moduleName, formName, abilityName to get formInstances.
487      * @param formInstances return formInstances
488      * @return return ERR_OK on get info success,other on failure.
489      */
490     ErrCode GetFormInstancesByFilter(const FormInstancesFilter &formInstancesFilter,
491         std::vector<FormInstance> &formInstances) override;
492 
493     /**
494      * @brief Get form instances by formId.
495      * @param formId formId Indicates the unique id of form.
496      * @param formInstance return formInstance
497      * @return return ERR_OK on get info success, others on failure.
498      */
499     ErrCode GetFormInstanceById(const int64_t formId, FormInstance &formInstance) override;
500 
501     /**
502      * @brief Get form instance by formId, include form store in DB.
503      * @param formId formId Indicates the unique id of form.
504      * @param isUnusedIncluded Indicates whether to include unused form instances.
505      * @param formInstance return formInstance
506      * @return return ERR_OK on get info success, others on failure.
507      */
508     ErrCode GetFormInstanceById(const int64_t formId, bool isUnusedIncluded, FormInstance &formInstance) override;
509 
510     /**
511      * @brief Register form add observer.
512      * @param bundleName BundleName of the form host
513      * @param callerToken Caller ability token.
514      * @return Returns ERR_OK on success, others on failure.
515      */
516     ErrCode RegisterAddObserver(const std::string &bundleName, const sptr<IRemoteObject> &callerToken) override;
517 
518     /**
519      * @brief Register form remove observer.
520      * @param bundleName BundleName of the form host
521      * @param callerToken Caller ability token.
522      * @return Returns ERR_OK on success, others on failure.
523      */
524     ErrCode RegisterRemoveObserver(const std::string &bundleName, const sptr<IRemoteObject> &callerToken) override;
525 
526     /**
527      * @brief Update proxy form with formId.
528      * @param formId The Id of the form to update.
529      * @param FormProviderData Form binding data.
530      * @param std::vector<FormDataProxy> Form proxy vector.
531      * @return Returns ERR_OK on success, others on failure.
532      */
533     ErrCode UpdateProxyForm(int64_t formId, const FormProviderData &FormProviderData,
534         const std::vector<FormDataProxy> &formDataProxies) override;
535 
536     /**
537      * @brief Request to publish a proxy form to the form host.
538      * @param want The want of the form to publish.
539      * @param withFormBindingData Indicates whether the formBindingData is carried with.
540      * @param formBindingData Indicates the form data.
541      * @param formId Return the form id to be published.
542      * @param std::vector<FormDataProxy> Form proxy vector.
543      * @return Returns ERR_OK on success, others on failure.
544      */
545     ErrCode RequestPublishProxyForm(Want &want, bool withFormBindingData,
546         std::unique_ptr<FormProviderData> &formBindingData, int64_t &formId,
547         const std::vector<FormDataProxy> &formDataProxies) override;
548 
549     /**
550      * @brief Read the form_config.xml.
551      * @return Returns ERR_OK on success, others on failure.
552      */
553     ErrCode ReadFormConfigXML();
554 
555     /**
556      * @brief Registers the callback for publish form. The callback is used to process the publish form request
557      * when the system handler is not found.
558      * @param interceptorCallback The injected callback, should implementation IFormPublishInterceptor.
559      * @return Returns ERR_OK on success, others on failure.
560      */
561     int32_t RegisterPublishFormInterceptor(const sptr<IRemoteObject> &interceptorCallback) override;
562 
563     /**
564      * @brief Unregisters the callback for publish form. The callback is used to process the publish form request
565      * when the system handler is not found.
566      * @param interceptorCallback The injected callback, should implementation IFormPublishInterceptor.
567      * @return Returns ERR_OK on success, others on failure.
568      */
569     int32_t UnregisterPublishFormInterceptor(const sptr<IRemoteObject> &interceptorCallback) override;
570 
571     /**
572      * @brief Register click callback observer.
573      * @param observer Form click event callback listener.
574      * @param bundleName BundleName of the form host.
575      * @param formEventType Form event type.
576      * @return Returns ERR_OK on success, others on failure.
577      */
578     ErrCode RegisterClickEventObserver(
579         const std::string &bundleName, const std::string &formEventType, const sptr<IRemoteObject> &observer) override;
580 
581     /**
582      * @brief Unregister click callback observer.
583      * @param bundleName BundleName of the form host.
584      * @param formEventType Form event type.
585      * @param observer Form click event callback listener.
586      * @return Returns ERR_OK on success, others on failure.
587      */
588     ErrCode UnregisterClickEventObserver(
589         const std::string &bundleName, const std::string &formEventType, const sptr<IRemoteObject> &observer) override;
590 
591     /**
592      * @brief Set forms recyclable
593      * @param formIds Indicates the id of the forms.
594      * @return Returns ERR_OK on success, others on failure.
595      */
596     int32_t SetFormsRecyclable(const std::vector<int64_t> &formIds) override;
597 
598     /**
599      * @brief Recycle forms
600      * @param formIds Indicates the id of the forms.
601      * @param want The want of forms to be recycled.
602      * @return Returns ERR_OK on success, others on failure.
603      */
604     int32_t RecycleForms(const std::vector<int64_t> &formIds, const Want &want) override;
605 
606     /**
607      * @brief Recover recycled forms
608      * @param formIds Indicates the id of the forms.
609      * @param want The want of forms to be recovered.
610      * @return Returns ERR_OK on success, others on failure.
611      */
612     int32_t RecoverForms(const std::vector<int64_t> &formIds, const Want &want) override;
613 
614     /**
615      * @brief Update formLocation with formId.
616      * @param formId The Id of the form to update.
617      * @param formLocation The FormLocation.
618      * @return Returns ERR_OK on success, others on failure.
619      */
620     ErrCode UpdateFormLocation(const int64_t &formId, const int32_t &formLocation) override;
621 
622     /**
623      * @brief Update form with formRefreshType, send to form manager service.
624      * @param formRefreshType The type of the form to refresh, 0: AllForm 1: 2: AppForm 2: AtomicServiceForm
625      * @return Returns ERR_OK on success, others on failure.
626      */
627     ErrCode BatchRefreshForms(const int32_t formRefreshType) override;
628 
629 #ifdef RES_SCHEDULE_ENABLE
630     /**
631      * @brief Update refresh_Timer_task_needed_flag depend on the systemload level.
632      * @param level The value of the systemload level.
633      */
634     void OnSystemloadLevel(int32_t level);
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) override;
644 
645     /**
646      * @brief Check form bundle is controlled.
647      * @param bundleName The bundle name of form to be check.
648      * @return Returns true for form bundle is controlled.
649      */
650     bool IsFormBundleForbidden(const std::string &bundleName) override;
651 
652     /**
653      * @brief Update form size.
654      * @param formId The Id of the form to update.
655      * @param width The width value to be updated.
656      * @param height The height value to be updated.
657      * @param borderWidth The borderWidth value to be updated.
658      * @return Returns ERR_OK on success, others on failure.
659      */
660     ErrCode UpdateFormSize(const int64_t &formId, float width, float height, float borderWidth) override;
661 private:
662     /**
663      * OnAddSystemAbility, OnAddSystemAbility will be called when the listening SA starts.
664      *
665      * @param systemAbilityId, The said being listened to.
666      * @param deviceId, deviceId is empty.
667      * @return void.
668      */
669     virtual void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override;
670 
671     enum class DumpKey {
672         KEY_DUMP_HELP = 0,
673         KEY_DUMP_STORAGE,
674         KEY_DUMP_BY_BUNDLE_NAME,
675         KEY_DUMP_BY_FORM_ID,
676         KEY_DUMP_TEMPORARY,
677         KEY_DUMP_STATIC,
678         KEY_DUMP_VISIBLE,
679         KEY_DUMP_RUNNING,
680         KEY_DUMP_BLOCKED_APPS,
681     };
682     /**
683      * @brief initialization of form manager service.
684      */
685     ErrCode Init();
686 
687     ErrCode CheckFormPermission(
688         const std::string &permission = AppExecFwk::Constants::PERMISSION_REQUIRE_FORM);
689 
690     bool CheckAcrossLocalAccountsPermission() const;
691 
692     void InitFormShareMgrSerialQueue();
693 
694     void Dump(const std::vector<std::u16string> &args, std::string &result);
695     bool ParseOption(const std::vector<std::u16string> &args, DumpKey &key, std::string &value, std::string &result);
696     void HiDumpHelp([[maybe_unused]] const std::string &args, std::string &result);
697     void HiDumpStorageFormInfos([[maybe_unused]] const std::string &args, std::string &result);
698     void HiDumpTemporaryFormInfos([[maybe_unused]] const std::string &args, std::string &result);
699     void HiDumpStaticBundleFormInfos([[maybe_unused]] const std::string &args, std::string &result);
700     void HiDumpHasFormVisible(const std::string &args, std::string &result);
701     void HiDumpFormInfoByBundleName(const std::string &args, std::string &result);
702     void HiDumpFormInfoByFormId(const std::string &args, std::string &result);
703     void HiDumpFormRunningFormInfos([[maybe_unused]] const std::string &args, std::string &result);
704     void HiDumpFormBlockedApps([[maybe_unused]] const std::string &args, std::string &result);
705     bool CheckCallerIsSystemApp() const;
706     static std::string GetCurrentDateTime();
707 private:
708     static const int32_t ENABLE_FORM_UPDATE = 5;
709     const static std::map<std::string, DumpKey> dumpKeyMap_;
710     std::string onStartBeginTime_;
711     std::string onStartPublishTime_;
712     std::string onStartEndTime_;
713     std::string onKvDataServiceAddTime_;
714     ServiceRunningState state_ = ServiceRunningState::STATE_NOT_START;
715     std::shared_ptr<FormEventHandler> handler_ = nullptr;
716     std::shared_ptr<FormSerialQueue> serialQueue_ = nullptr;
717     std::shared_ptr<FormSysEventReceiver> formSysEventReceiver_ = nullptr;
718     mutable std::mutex instanceMutex_;
719     DISALLOW_COPY_AND_MOVE(FormMgrService);
720 #ifdef MEM_MGR_ENABLE
721     std::shared_ptr<MemStatusListener> memStatusListener_ = nullptr;
722 #endif
723     void SubscribeSysEventReceiver();
724 
725     /**
726      * @brief report add form event
727      * @param formId Indicates the id of form.
728      * @param want The want of form.
729      */
730     void ReportAddFormEvent(const int64_t formId, const Want &want);
731 };
732 }  // namespace AppExecFwk
733 }  // namespace OHOS
734 #endif  // OHOS_FORM_FWK_FORM_MGR_SERVICE_H
735