• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 FOUNDATION_APPEXECFWK_SERVICES_FORMMGR_INCLUDE_FORM_PROVIDER_MGRR_H
17 #define FOUNDATION_APPEXECFWK_SERVICES_FORMMGR_INCLUDE_FORM_PROVIDER_MGRR_H
18 #include <set>
19 #include <singleton.h>
20 #include "form_provider_info.h"
21 #include "form_record.h"
22 #include "form_state_info.h"
23 #include "want.h"
24 
25 namespace OHOS {
26 namespace AppExecFwk {
27 using Want = OHOS::AAFwk::Want;
28 /**
29  * @class FormProviderMgr
30  * Form provider manager.
31  */
32 class FormProviderMgr final : public DelayedRefSingleton<FormProviderMgr> {
33     DECLARE_DELAYED_REF_SINGLETON(FormProviderMgr)
34 public:
35     DISALLOW_COPY_AND_MOVE(FormProviderMgr);
36 
37     /**
38      * @brief handle for acquire back event from provider.
39      * @param formId The id of the form.
40      * @param providerFormInfo provider form info.
41      * @return Returns ERR_OK on success, others on failure.
42      */
43     ErrCode AcquireForm(const int64_t formId, const FormProviderInfo &formProviderInfo);
44     /**
45      * @brief handle for update form event from provider.
46      * @param formId The id of the form.
47      * @param providerFormInfo provider form info.
48      * @return Returns ERR_OK on success, others on failure.
49      */
50     ErrCode UpdateForm(const int64_t formId, const FormProviderInfo &formProviderInfo);
51     /**
52      * handle for update form event from provider.
53      *
54      * @param formId The id of the form.
55      * @param formRecord The form's record.
56      * @param formProviderData provider form info.
57      * @return Returns ERR_OK on success, others on failure.
58      */
59     ErrCode UpdateForm(const int64_t formId, FormRecord &formRecord, const FormProviderData &formProviderData);
60     /**
61      * @brief Refresh form.
62      *
63      * @param formId The form id.
64      * @param want The want of the form to request.
65      * @param isVisibleToFresh The form is visible to fresh.
66      * @return Returns ERR_OK on success, others on failure.
67      */
68     ErrCode RefreshForm(const int64_t formId, const Want &want, bool isVisibleToFresh);
69     /**
70      * @brief Connect ams for refresh form
71      *
72      * @param formId The form id.
73      * @param record Form data.
74      * @param want The want of the form.
75      * @param isTimerRefresh The flag of timer refresh.
76      * @return Returns ERR_OK on success, others on failure.
77      */
78     ErrCode ConnectAmsForRefresh(const int64_t formId, const FormRecord &record, const Want &want,
79     const bool isTimerRefresh);
80     /**
81      * @brief Notify provider form delete.
82      * @param formId The form id.
83      * @param record Form information.
84      * @return Returns ERR_OK on success, others on failure.
85      */
86     ErrCode NotifyProviderFormDelete(const int64_t formId, const FormRecord &formRecord);
87     /**
88      * @brief Notify provider forms batch delete.
89      * @param bundleName BundleName.
90      * @param bundleName AbilityName.
91      * @param formIds form id list.
92      * @return Returns ERR_OK on success, others on failure.
93      */
94     ErrCode NotifyProviderFormsBatchDelete(const std::string &bundleName, const std::string &abilityName,
95     const std::set<int64_t> &formIds);
96     /**
97      * @brief Acquire form state.
98      * @param state form state.
99      * @param provider provider info.
100      * @param wantArg The want of onAcquireFormState.
101      * @return Returns ERR_OK on success, others on failure.
102      */
103     ErrCode AcquireFormStateBack(FormState state, const std::string& provider, const Want &wantArg);
104     /**
105      * @brief Process js message event.
106      * @param formId Indicates the unique id of form.
107      * @param record Form record.
108      * @param want information passed to supplier.
109      * @return Returns true if execute success, false otherwise.
110      */
111     int MessageEvent(const int64_t formId, const FormRecord &record, const Want &want);
112 private:
113     bool IsNeedToFresh(FormRecord &record, int64_t formId, bool isVisibleToFresh);
114 
115     FormRecord GetFormAbilityInfo(const FormRecord &record) const;
116     /**
117      * @brief Increase the timer refresh count.
118      *
119      * @param formId The form id.
120      */
121     void IncreaseTimerRefreshCount(const int64_t formId);
122     bool IsFormCached(const FormRecord &record);
123 };
124 }  // namespace AppExecFwk
125 }  // namespace OHOS
126 
127 #endif // FOUNDATION_APPEXECFWK_SERVICES_FORMMGR_INCLUDE_FORM_PROVIDER_MGRR_H
128