• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2023 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_FORM_DATA_MGR_H
17 #define OHOS_FORM_FWK_FORM_FORM_DATA_MGR_H
18 
19 #include <map>
20 #include <mutex>
21 #include <set>
22 #include <singleton.h>
23 #include <string>
24 
25 #include "bundle_pack_info.h"
26 #include "form_constants.h"
27 #include "form_host_record.h"
28 #include "form_id_key.h"
29 #include "form_info.h"
30 #include "form_instance.h"
31 #include "form_instances_filter.h"
32 #include "form_item_info.h"
33 #include "form_js_info.h"
34 #include "form_record.h"
35 #include "form_state_info.h"
36 #include "iremote_object.h"
37 #include "libxml/parser.h"
38 #include "libxml/tree.h"
39 #include "running_form_info.h"
40 
41 namespace OHOS {
42 namespace AppExecFwk {
43 using Want = AAFwk::Want;
44 
45 /**
46  * @class FormDataMgr
47  * form data manager.
48  */
49 class FormDataMgr final : public DelayedRefSingleton<FormDataMgr> {
50 DECLARE_DELAYED_REF_SINGLETON(FormDataMgr)
51 public:
52     DISALLOW_COPY_AND_MOVE(FormDataMgr);
53     /**
54      * @brief Allot form info by item info.
55      * @param formInfo Form item info.
56      * @param callingUid The UID of the proxy.
57      * @param userId User ID.
58      * @return Returns form record.
59      */
60     FormRecord AllotFormRecord(const FormItemInfo &formInfo, const int callingUid,
61         const int32_t userId = Constants::DEFAULT_USER_ID);
62     /**
63      * @brief Create form js info by form record.
64      * @param formId The Id of the form.
65      * @param record Form record.
66      * @param formInfo Js info.
67      */
68     void CreateFormJsInfo(const int64_t formId, const FormRecord &record, FormJsInfo &formInfo);
69     /**
70      * @brief Delete form js info by form record.
71      * @param formId The Id of the form.
72      * @return Returns true if this function is successfully called; returns false otherwise.
73      */
74     bool DeleteFormRecord(const int64_t formId);
75     /**
76      * @brief Clean removed forms for host.
77      * @param removedFormIds The id list of the forms.
78      */
79     void CleanHostRemovedForms(const std::vector<int64_t> &removedFormIds);
80     /**
81      * @brief Allot form host record by caller token.
82      * @param info The form item info.
83      * @param callerToken callerToken
84      * @param formId The Id of the form.
85      * @param callingUid The UID of the proxy.
86      * @return Returns true if this function is successfully called; returns false otherwise.
87      */
88     bool AllotFormHostRecord(const FormItemInfo &info, const sptr<IRemoteObject> &callerToken,
89         const int64_t formId, const int callingUid);
90     /**
91      * @brief Check temp form count is max.
92      * @return Returns ERR_OK if the temp form not reached; returns ERR_MAX_SYSTEM_TEMP_FORMS is reached.
93      */
94     int CheckTempEnoughForm() const;
95     /**
96      * @brief Check form count is max.
97      * @param currentUserId The current userId.
98      * @param callingUid The UID of the proxy.
99      * @return Returns true if this function is successfully called; returns false otherwise.
100      */
101     int CheckEnoughForm(const int callingUid, const int32_t currentUserId = Constants::DEFAULT_USER_ID) const;
102     /**
103      * @brief Delete temp form.
104      * @param formId The Id of the form.
105      * @return Returns true if this function is successfully called; returns false otherwise.
106      */
107     bool DeleteTempForm(const int64_t formId);
108     /**
109      * @brief Check temp form is exist.
110      * @param formId The Id of the form.
111      * @return Returns true if the temp form is exist; returns false is not exist.
112      */
113     bool ExistTempForm(const int64_t formId) const;
114     /**
115      * @brief Modify form temp flag by formId.
116      * @param formId The Id of the form.
117      * @param formTempFlag The form temp flag.
118      * @return Returns true if this function is successfully called; returns false otherwise.
119      */
120     bool ModifyFormTempFlag(const int64_t formId, const bool formTempFlag);
121     /**
122      * @brief Add form user uid from form record.
123      * @param formId The Id of the form.
124      * @param formUserUid The form user uid.
125      * @return Returns true if this function is successfully called; returns false otherwise.
126      */
127     bool AddFormUserUid(const int64_t formId, const int formUserUid);
128     /**
129      * @brief Delete form user uid from form record.
130      * @param formId The Id of the form.
131      * @param uid calling user id.
132      * @return Returns true if this function is successfully called; returns false otherwise.
133      */
134     bool DeleteFormUserUid(const int64_t formId, const int uid);
135     /**
136      * @brief Update form record.
137      * @param formId The Id of the form.
138      * @param formRecord The form record.
139      * @return Returns true if this function is successfully called; returns false otherwise.
140      */
141     bool UpdateFormRecord(const int64_t formId, const FormRecord &formRecord);
142     /**
143      * @brief Get form record.
144      * @param formId The Id of the form.
145      * @param formRecord The form record.
146      * @return Returns true if this function is successfully called; returns false otherwise.
147      */
148     bool GetFormRecord(const int64_t formId, FormRecord &formRecord) const;
149     /**
150      * @brief Get form record.
151      * @param bundleName Bundle name.
152      * @param formInfos The form record list.
153      * @return Returns true if this function is successfully called; returns false otherwise.
154      */
155     bool GetFormRecord(const std::string &bundleName, std::vector<FormRecord> &formInfos,
156         int32_t userId = Constants::INVALID_USER_ID) const;
157     /**
158      * @brief Get temporary form record.
159      * @param formTempRecords The temp form record.
160      * @return Returns true if this function is successfully called; returns false otherwise.
161      */
162     bool GetTempFormRecord(std::vector<FormRecord> &formTempRecords);
163     /**
164      * @brief Check form record is exist.
165      * @param formId The Id of the form.
166      * @return Returns true if the form record is exist; returns false is not exist.
167      */
168     bool ExistFormRecord(const int64_t formId) const;
169     /**
170      * @brief Has form user uids in form record.
171      * @param formId The Id of the form.
172      * @return Returns true if this form has form user uids; returns false is not has.
173      */
174     bool HasFormUserUids(const int64_t formId) const;
175     /**
176      * @brief Get form host record.
177      * @param formId The id of the form.
178      * @param formHostRecords The form host records.
179      */
180     void GetFormHostRecord(const int64_t formId, std::vector<FormHostRecord> &formHostRecords) const;
181     /**
182      * @brief Get form host remote object.
183      * @param formId The id of the form.
184      * @param formHostObjs The form host remote object.
185      */
186     void GetFormHostRemoteObj(const int64_t formId, std::vector<sptr<IRemoteObject>> &formHostObjs) const;
187     /**
188      * @brief Delete form host record.
189      * @param callerToken The client stub of the form host record.
190      * @param formId The id of the form.
191      * @return Returns true if this function is successfully called; returns false otherwise.
192      */
193     bool DeleteHostRecord(const sptr<IRemoteObject> &callerToken, const int64_t formId);
194     /**
195      * @brief Handle form host died.
196      * @param remoteHost Form host proxy object.
197      */
198     void HandleHostDied(const sptr<IRemoteObject> &remoteHost);
199     /**
200      * @brief Refresh enable or not.
201      * @param formId The Id of the form.
202      * @return true on enable, false on disable.
203      */
204     bool IsEnableRefresh(int64_t formId);
205     /**
206      * @brief update enable or not.
207      * @param formId The Id of the form.
208      * @return true on enable, false on disable.
209      */
210     bool IsEnableUpdate(int64_t formId);
211     /**
212      * @brief Check calling uid is valid.
213      * @param formUserUids The form user uids.
214      * @return Returns true if this user uid is valid; returns false otherwise.
215      */
216     bool IsCallingUidValid(const std::vector<int> &formUserUids) const;
217     /**
218      * @brief Generate udid.
219      * @return Returns true if this function is successfully called; returns false otherwise.
220      */
221     bool GenerateUdidHash();
222     /**
223      * @brief Padding udid hash.
224      * @param formId The form id.
225      * @return Padded form id.
226      */
227     int64_t PaddingUdidHash(int64_t formId);
228     /**
229      * @brief Generate form id.
230      * @return form id.
231      */
232     int64_t GenerateFormId();
233     /**
234      * @brief Get udid.
235      * @return udid.
236      */
237     int64_t GetUdidHash() const;
238     /**
239      * @brief Set udid.
240      * @param udidHash udid.
241      */
242     void SetUdidHash(const int64_t udidHash);
243 
244     /**
245      * @brief Get the matched form host record by client stub.
246      *
247      * @param callerToken The client stub of the form host record.
248      * @param formHostRecord The form host record.
249      * @return Returns true if this function is successfully called, returns false otherwise.
250      */
251     bool GetMatchedHostClient(const sptr<IRemoteObject> &callerToken, FormHostRecord &formHostRecord) const;
252 
253     /**
254      * @brief Set needRefresh for FormRecord.
255      * @param formId The Id of the form.
256      * @param needRefresh true or false.
257      */
258     void SetNeedRefresh(const int64_t formId, const bool needRefresh);
259     /**
260      * @brief Set isCountTimerRefresh for FormRecord.
261      * @param formId The Id of the form.
262      * @param countTimerRefresh true or false.
263      */
264     void SetCountTimerRefresh(const int64_t formId, const bool countTimerRefresh);
265 
266     /**
267      * @brief Set timerRefresh for FormRecord.
268      * @param formId The Id of the form.
269      * @param timerRefresh true or false.
270      */
271     void SetTimerRefresh(const int64_t formId, const bool timerRefresh);
272 
273     /**
274      * @brief Get updated form info.
275      * @param record FormRecord.
276      * @param targetForms Target forms.
277      * @param updatedForm Updated form info.
278      * @return Returns true on success, false on failure.
279      */
280     bool GetUpdatedForm(const FormRecord &record, const std::vector<FormInfo> &targetForms, FormInfo &updatedForm);
281     /**
282      * @brief Set isEnableUpdate for FormRecord.
283      * @param formId The Id of the form.
284      * @param enableUpdate true or false.
285      */
286     void SetEnableUpdate(const int64_t formId, const bool enableUpdate);
287     /**
288      * @brief Set update info for FormRecord.
289      * @param formId The Id of the form.
290      * @param enableUpdate true or false.
291      * @param updateDuration Update duration.
292      * @param updateAtHour Update at hour.
293      * @param updateAtMin Update at minute.
294      */
295     void SetUpdateInfo(const int64_t formId, const bool enableUpdate, const long updateDuration,
296     const int updateAtHour, const int updateAtMin);
297     /**
298      * @brief Clean removed form records.
299      * @param bundleName BundleName.
300      * @param removedForms The id list of the forms.
301      */
302     void CleanRemovedFormRecords(const std::string &bundleName, std::set<int64_t> &removedForms);
303     /**
304      * @brief Clean removed temp form records.
305      * @param  bundleName BundleName.
306      * @param removedForms The id list of the forms.
307      */
308     void CleanRemovedTempFormRecords(const std::string &bundleName, const int32_t userId,
309         std::set<int64_t> &removedForms);
310     /**
311      * @brief Get recreate form records.
312      * @param reCreateForms The id list of the forms.
313      */
314     void GetReCreateFormRecordsByBundleName(const std::string &bundleName, std::set<int64_t> &reCreateForms);
315     /**
316      * @brief Set form isInited = true.
317      * @param formId The Id of the form.
318      * @param isInited isInited property
319      */
320     void SetFormCacheInited(const int64_t formId, const bool isInited);
321     /**
322      * @brief Set versionUpgrade.
323      * @param formId The Id of the form.
324      * @param versionUpgrade true or false
325      */
326     void SetVersionUpgrade(const int64_t formId, const bool versionUpgrade);
327     /**
328      * @brief Update form for host clients.
329      * @param formId The Id of the form.
330      * @param needRefresh true or false
331      */
332     void UpdateHostNeedRefresh(const int64_t formId, const bool needRefresh);
333     /**
334      * @brief Update form for host clients.
335      * @param formId The Id of the form.
336      * @param formRecord The form info.
337      * @return Returns true if form update, false if other.
338      */
339     bool UpdateHostForm(const int64_t formId, const FormRecord &formRecord);
340     /**
341      * @brief handle update form flag.
342      * @param formIDs The id of the forms.
343      * @param callerToken Caller ability token.
344      * @param flag form flag.
345      * @param isOnlyEnableUpdate form enable update form flag.
346      * @param refreshForms Refresh forms
347      * @return Returns ERR_OK on success, others on failure.
348      */
349     ErrCode UpdateHostFormFlag(const std::vector<int64_t> &formIds, const sptr<IRemoteObject> &callerToken,
350                                bool flag, bool isOnlyEnableUpdate, std::vector<int64_t> &refreshForms);
351     /**
352      * @brief Find matched form id.
353      * @param formId The form id.
354      * @return Matched form id.
355      */
356     int64_t FindMatchedFormId(const int64_t formId);
357     /**
358      * @brief Clear host data by uId.
359      * @param uId The caller uId.
360      */
361     void ClearHostDataByUId(const int uId);
362     /**
363      * @brief Get no host temp forms.
364      * @param uid The caller uid.
365      * @param noHostTempFormsMap no host temp forms.
366      * @param foundFormsMap Form Id list.
367      */
368     void GetNoHostTempForms(const int uid, std::map<FormIdKey, std::set<int64_t>> &noHostTempFormsMap,
369         std::map<int64_t, bool> &foundFormsMap);
370 
371     /**
372      * @brief delete forms by userId.
373      *
374      * @param userId user ID.
375      * @param removedFormIds removed userId.
376      */
377     void DeleteFormsByUserId(const int32_t userId, std::vector<int64_t> &removedFormIds);
378     /**
379     * @brief Clear form records for st limit value test.
380     */
381     void ClearFormRecords();
382 
383     /**
384      * @brief handle get no host invalid temp forms.
385      * @param userId User ID.
386      * @param callingUid The UID of the proxy.
387      * @param matchedFormIds The set of the valid forms.
388      * @param noHostTempFormsMap The map of the no host forms.
389      * @param foundFormsMap The map of the found forms.
390      */
391     void GetNoHostInvalidTempForms(int32_t userId, int32_t callingUid, std::set<int64_t> &matchedFormIds,
392                                    std::map<FormIdKey, std::set<int64_t>> &noHostTempFormsMap,
393                                    std::map<int64_t, bool> &foundFormsMap);
394 
395     /**
396      * @brief handle delete no host temp forms.
397      * @param callingUid The UID of the proxy.
398      * @param noHostTempFormsMap The map of the no host forms.
399      * @param foundFormsMap The map of the found forms.
400      */
401     void BatchDeleteNoHostTempForms(int32_t callingUid, std::map<FormIdKey, std::set<int64_t>> &noHostTempFormsMap,
402                                     std::map<int64_t, bool> &foundFormsMap);
403 
404     /**
405      * @brief delete invalid temp forms.
406      * @param userId User ID.
407      * @param callingUid The UID of the proxy.
408      * @param matchedFormIds The set of the valid forms.
409      * @param removedFormsMap The map of the removed invalid forms.
410      * @return Returns ERR_OK on success, others on failure.
411      */
412     int32_t DeleteInvalidTempForms(int32_t userId, int32_t callingUid, std::set<int64_t> &matchedFormIds,
413                                    std::map<int64_t, bool> &removedFormsMap);
414 
415     /**
416      * @brief clear host data by invalid forms.
417      * @param callingUid The UID of the proxy.
418      * @param removedFormsMap The map of the removed invalid forms.
419      * @return Returns ERR_OK on success, others on failure.
420      */
421     int32_t ClearHostDataByInvalidForms(int32_t callingUid, std::map<int64_t, bool> &removedFormsMap);
422 
423     /**
424      * @brief delete publish forms temp data
425      * @param userId User ID.
426      * @param bundleName BundleName.
427      * @param validFormIds The set of the valid forms.
428      * @return Returns -
429      */
430     void DeleteInvalidPublishForms(int32_t userId, std::string bundleName, std::set<int64_t> &validFormIds);
431 
432     /**
433      * @brief Create form acquire data host record.
434      * @param requestCode The request code of this acquire form.
435      * @param info The form item info.
436      * @param callerToken  Caller ability token.
437      * @param callingUid The UID of the proxy.
438      * @return Returns true if this function is successfully called; returns false otherwise.
439      */
440     bool CreateFormAcquireDataRecord(int64_t requestCode, const FormItemInfo &info,
441                                      const sptr<IRemoteObject> &callerToken, int callingUid);
442 
443     /**
444      * @brief Create form state host record.
445      * @param provider The provider of the form state
446      * @param info The form item info.
447      * @param callerToken The UID of the proxy.
448      * @param callingUid The UID of the proxy.
449      * @return Returns true if this function is successfully called; returns false otherwise.
450      */
451     bool CreateFormStateRecord(std::string &provider, const FormItemInfo &info, const sptr<IRemoteObject> &callerToken,
452                                int callingUid);
453 
454     /**
455      * @brief acquire form state callback.
456      * @param state form state.
457      * @param provider provider info.
458      * @param want The want of onAcquireFormState.
459      * @return Returns true if this function is successfully called; returns false otherwise.
460      */
461     ErrCode AcquireFormStateBack(AppExecFwk::FormState state, const std::string &provider, const Want &want);
462 
463     /**
464      * @brief acquire form data callback.
465      * @param wantParams Indicates the data information acquired by the form.
466      * @param requestCode Indicates the requested id.
467      * @return Returns true if this function is successfully called; returns false otherwise.
468      */
469     ErrCode AcquireFormDataBack(const AAFwk::WantParams &wantParams, int64_t requestCode);
470 
471     /**
472      * @brief Notify the form is visible or not.
473      * @param formIds Indicates the ID of the forms.
474      * @param isVisible Visible or not.
475      * @param callerToken Host client.
476      * @return Returns ERR_OK on success, others on failure.
477      */
478     ErrCode NotifyFormsVisible(const std::vector<int64_t> &formIds, bool isVisible,
479                                const sptr<IRemoteObject> &callerToken);
480 
481     /**
482      * @brief set form record visible.
483      * @param matchedFormId form id.
484      * @param isVisible is visible.
485      * @return Returns true if this function is successfully called; returns false otherwise.
486      */
487     ErrCode SetRecordVisible(int64_t matchedFormId, bool isVisible);
488 
489     /**
490      * @brief add request publish form info.
491      * @param formId The form id of the form to publish.
492      * @param want The want of the form to publish.
493      * @param formProviderData The form data.
494      * @return Returns ERR_OK on success, others on failure.
495      */
496     ErrCode AddRequestPublishFormInfo(int64_t formId, const Want &want,
497                                       std::unique_ptr<FormProviderData> &formProviderData);
498 
499     /**
500      * @brief remove request publish form info.
501      * @param formId The form id of the form to publish.
502      * @return Returns true if this function is successfully called; returns false otherwise.
503      */
504     ErrCode RemoveRequestPublishFormInfo(int64_t formId);
505 
506     /**
507      * @brief check whether request publish form info.
508       * @param formId The form id of the form to publish.
509      * @return Returns true if this function is successfully called; returns false otherwise.
510      */
511     bool IsRequestPublishForm(int64_t formId);
512 
513     /**
514      * @brief get request publish form info.
515      * @param formId The form id of the form to publish.
516      * @param want The want of the form to publish.
517      * @param formProviderData The form data.
518      * @return Returns true if this function is successfully called; returns false otherwise.
519      */
520     ErrCode GetRequestPublishFormInfo(int64_t formId, Want &want,
521                                       std::unique_ptr<FormProviderData> &formProviderData);
522     /**
523      * @brief Get updated form info.
524      * @param record Indicates the form record.
525      * @param bundlePackInfo Indicates the BundlePackInfo object.
526      * @param abilityFormInfo Indicates the obtained abilityFormInfo object.
527      * @return Returns true on success, false on failure.
528      */
529     bool GetPackageForm(const FormRecord &record, const BundlePackInfo &bundlePackInfo,
530         AbilityFormInfo &abilityFormInfo);
531 
532     /**
533      * @brief Set form free install flag.
534      * @param formId Indicates the form ID.
535      * @param isNeedFreeInstall Indicates the free install flag is true or false.
536      * @return Returns true on success, false on failure.
537      */
538     bool SetRecordNeedFreeInstall(int64_t formId, bool isNeedFreeInstall);
539 
540     /**
541      * @brief StopRenderingForm.
542      * @param formId The form id.
543      */
544     void StopRenderingForm(int32_t formId);
545 
546     /**
547      * @brief update host forms
548      * @param updateFormIds
549      */
550     void UpdateHostForms(const std::vector<int64_t> &updateFormIds);
551 
552     /**
553      * @brief Checks that the form is valid.
554      * @param formId Indicates the form ID.
555      * @return Returns ERR_OK on success, others on failure.
556      */
557     ErrCode CheckInvalidForm(const int64_t formId);
558 
559     /**
560     * @brief get cast forms count.
561     * @param formCount Returns the number of the cast form.
562     * @return Return the cast forms number.
563     */
564     int32_t GetCastFormsCount(int32_t &formCount);
565 
566     /**
567     * @brief get temp forms count.
568     * @param formCount Returns the number of the temp form.
569     * @return Return the temp forms number.
570     */
571     int32_t GetTempFormsCount(int32_t &formCount);
572 
573     /**
574     * @brief get host forms count.
575     * @param bundleName Indicates form host bundleName.
576     * @param formCount Returns the number of the host form.
577     * @return Return the host forms number.
578     */
579     int32_t GetHostFormsCount(const std::string &bundleName, int32_t &formCount);
580 
581     /**
582     * @brief handle form add observer.
583     * @param hostBundleName the bundle name of form host.
584     * @param formId Indicates the form ID.
585     * @return Returns ERR_OK on success, others on failure.
586     */
587     ErrCode HandleFormAddObserver(const std::string hostBundleName, const int64_t formId);
588 
589     /**
590     * @brief handle form add observer.
591     * @param hostBundleName the bundle name of form host.
592     * @param runningFormInfo the running forms' infos of the specify application name.
593     * @return Returns ERR_OK on success, others on failure.
594     */
595     ErrCode HandleFormRemoveObserver(const std::string hostBundleName, const RunningFormInfo runningFormInfo);
596 
597     /**
598      * @brief Get the running form infos by form id.
599      * @param formId Indicates the form ID.
600      * @param runningFormInfos Return the running forms' infos of the specify application name.
601      * @return Returns ERR_OK on success, others on failure.
602      */
603     ErrCode GetRunningFormInfosByFormId(const int64_t formId, RunningFormInfo &runningFormInfo);
604 
605     /**
606      * @brief Get all running form infos.
607      * @param runningFormInfos Return the running forms' infos currently.
608      * @return Returns ERR_OK on success, others on failure.
609      */
610     ErrCode GetRunningFormInfos(std::vector<RunningFormInfo> &runningFormInfos);
611 
612     /**
613      * @brief Get the running form infos by bundle name.
614      * @param bundleName Application name.
615      * @param runningFormInfos Return the running forms' infos of the specify application name.
616      * @return Returns ERR_OK on success, others on failure.
617      */
618     ErrCode GetRunningFormInfosByBundleName(const std::string &bundleName,
619         std::vector<RunningFormInfo> &runningFormInfos);
620 
621     /**
622      * @brief Get form instances by filter info.
623      * @param formInstancesFilter includes bundleName, moduleName, formName, abilityName to get formInstances.
624      * @param formInstances return formInstances
625      * @return return ERR_OK on get info success,other on failure.
626      */
627     ErrCode GetFormInstancesByFilter(const FormInstancesFilter &formInstancesFilter,
628         std::vector<FormInstance> &formInstances);
629 
630     /**
631      * @brief Get form instance by formId.
632      * @param formId formId Indicates the unique id of form.
633      * @param formInstance return formInstance
634      * @return return ERR_OK on get info success, others on failure.
635      */
636     ErrCode GetFormInstanceById(const int64_t formId, FormInstance &formInstances);
637 
638     /**
639      * @brief Get form instance by formId, include form store in DB.
640      * @param formId formId Indicates the unique id of form.
641      * @param isIncludeUnused Indicates whether to include unused forms.
642      * @param formInstance return formInstance
643      * @return return ERR_OK on get info success, others on failure.
644      */
645     ErrCode GetFormInstanceById(const int64_t formId, bool isIncludeUnused, FormInstance &formInstances);
646 
647     /**
648      * @brief Set form config map.
649      * @param configMap form config map.
650      */
651     void SetConfigMap(const std::map<std::string, int32_t> &configMap);
652 
653     /**
654      * @brief Get form config param form map.
655      * @param key the param's name.
656      * @param value the return value.
657      */
658     void GetConfigParamFormMap(const std::string &key, int32_t &value) const;
659 private:
660     /**
661      * @brief Create form record.
662      * @param formInfo The form item info.
663      * @param callingUid The UID of the proxy.
664      * @param userId User ID.
665      * @return Form record.
666      */
667     FormRecord CreateFormRecord(const FormItemInfo &formInfo, const int callingUid,
668         const int32_t userId = Constants::DEFAULT_USER_ID) const;
669     /**
670      * @brief Create host record.
671      * @param info The form item info.
672      * @param callerToken The UID of the proxy.
673      * @param callingUid The UID of the proxy.
674      * @param record The form host record.
675      * @return Returns true if this function is successfully called; returns false otherwise.
676      */
677     bool CreateHostRecord(const FormItemInfo &info, const sptr<IRemoteObject> &callerToken,
678         const int callingUid, FormHostRecord &record);
679     /**
680      * @brief Parse update config.
681      * @param record The form record.
682      * @param info The form item info.
683      * @return None.
684      */
685     void ParseUpdateConfig(FormRecord &record, const FormItemInfo &info) const;
686     /**
687      * @brief Parse update interval config.
688      * @param record The form record.
689      * @param configDuration interval duration.
690      */
691     void ParseIntervalConfig(FormRecord &record, const int configDuration) const;
692     /**
693      * @brief Parse at time config.
694      * @param record The form record.
695      * @param info form item info.
696      */
697     void ParseAtTimerConfig(FormRecord &record, const FormItemInfo &info) const;
698     /**
699      * @brief Get the temp forms from host and delete temp form in cache.
700      * @param record The form record.
701      * @param recordTempForms the temp forms.
702      */
703     void HandleHostDiedForTempForms(const FormHostRecord &record, std::vector<int64_t> &recordTempForms);
704     /**
705      * @brief Check if two forms is same or not.
706      * @param record FormRecord.
707      * @param formInfo FormInfo.
708      * @return Returns true on success, false on failure.
709      */
710     bool IsSameForm(const FormRecord &record, const FormInfo &formInfo);
711 
712     /**
713      * @brief Check if two forms is same or not.
714      * @param record Indicates the form record.
715      * @param abilityFormInfo Indicates the AbilityFormInfo.
716      * @return Returns true on success, false on failure.
717      */
718     bool IsSameForm(const FormRecord &record, const AbilityFormInfo &abilityFormInfo);
719 
720     /**
721      * @brief check if form cached.
722      * @param record The form record.
723      * @return Returns ERR_OK on cached, others on not cached.
724      */
725     bool IsFormCached(const FormRecord record);
726 
727     /**
728     * @brief handle update form flag.
729     * @param formIDs The id of the forms.
730     * @param flag form flag.
731     * @param isOnlyEnableUpdate form enable update form flag.
732     * @param formHostRecord form host record.
733     * @param refreshForms Refresh forms
734     * @return Returns ERR_OK on success, others on failure.
735     */
736     ErrCode HandleUpdateHostFormFlag(const std::vector<int64_t> &formIds, bool flag, bool isOnlyEnableUpdate,
737                                      FormHostRecord &formHostRecord, std::vector<int64_t> &refreshForms);
738 
739     /**
740     * @brief Get ability form info.
741     * @param record Indicates form record.
742     * @param abilities Indicates the ModuleAbilityInfo in FA model or ExtensionAbilities in stage model.
743     * @param abilityFormInfo Indicates the obtained abilityFormInfo object.
744     * @return Returns ERR_OK on success, others on failure.
745     */
746     template<typename T>
747     bool GetAbilityFormInfo(const FormRecord &record, const std::vector<T> &abilities,
748         AbilityFormInfo &abilityFormInfo);
749 private:
750     mutable std::mutex formRecordMutex_;
751     mutable std::mutex formHostRecordMutex_;
752     mutable std::mutex formTempMutex_;
753     mutable std::mutex formStateRecordMutex_;
754     mutable std::mutex formRequestPublishFormsMutex_;
755     mutable std::mutex formAcquireDataRecordMutex_;
756     mutable std::mutex formConfigMapMutex_;
757     std::map<int64_t, FormRecord> formRecords_;
758     std::vector<FormHostRecord> clientRecords_;
759     std::vector<int64_t> tempForms_;
760     std::map<std::string, FormHostRecord> formStateRecord_;
761     std::map<std::string, std::vector<sptr<IRemoteObject>>> formAddObservers_;
762     std::map<int32_t, FormHostRecord> formAcquireDataRecord_;
763     using FormRequestPublishFormInfo = std::pair<Want, std::unique_ptr<FormProviderData>>;
764     std::map<int64_t, FormRequestPublishFormInfo> formRequestPublishForms_;
765     int64_t udidHash_ = 0;
766     std::vector<sptr<IRemoteObject>> formObservers_;
767     std::map<std::string, int32_t> formConfigMap_;
768 };
769 } // namespace AppExecFwk
770 } // namespace OHOS
771 #endif // OHOS_FORM_FWK_FORM_FORM_DATA_MGR_H
772