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