• 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_TASK_MGR_H
17 #define FOUNDATION_APPEXECFWK_SERVICES_FORMMGR_INCLUDE_FORM_TASK_MGR_H
18 
19 #include <singleton.h>
20 #include <vector>
21 
22 #include "event_handler.h"
23 #include "form_item_info.h"
24 #include "form_js_info.h"
25 #include "form_provider_info.h"
26 #include "form_record.h"
27 #include "ipc_types.h"
28 #include "iremote_object.h"
29 #include "form_record.h"
30 #include "want.h"
31 
32 namespace OHOS {
33 namespace AppExecFwk {
34 using Want = OHOS::AAFwk::Want;
35 using WantParams = OHOS::AAFwk::WantParams;
36 /**
37  * @class FormTaskMgr
38  * form task manager.
39  */
40 class FormTaskMgr final : public DelayedRefSingleton<FormTaskMgr> {
41     DECLARE_DELAYED_REF_SINGLETON(FormTaskMgr)
42 
43 public:
44     DISALLOW_COPY_AND_MOVE(FormTaskMgr);
45 
46     /**
47      * @brief SetEventHandler.
48      * @param handler event handler
49      */
SetEventHandler(const std::shared_ptr<AppExecFwk::EventHandler> & handler)50     inline void SetEventHandler(const std::shared_ptr<AppExecFwk::EventHandler> &handler)
51     {
52         eventHandler_ = handler;
53     }
54 
55     /**
56      * @brief Acquire form data from form provider(task).
57      * @param formId The Id of the form.
58      * @param want The want of the request.
59      * @param remoteObject Form provider proxy object.
60      */
61     void PostAcquireTask(const int64_t formId, const Want &want, const sptr<IRemoteObject> &remoteObject);
62 
63     /**
64      * @brief Delete form data from form provider(task).
65      * @param formId The Id of the form.
66      * @param want The want of the request.
67      * @param remoteObject Form provider proxy object.
68      */
69     void PostDeleteTask(const int64_t formId, const Want &want, const sptr<IRemoteObject> &remoteObject);
70    /**
71      * @brief Notify provider batch delete.
72      * @param formIds The Id list.
73      * @param want The want of the request.
74      * @param remoteObject Form provider proxy object.
75      */
76     void PostProviderBatchDeleteTask(std::set<int64_t> &formIds, const Want &want,
77         const sptr<IRemoteObject> &remoteObject);
78     /**
79      * @brief Refresh form data from form provider(task).
80      *
81      * @param formId The Id of the form.
82      * @param want The want of the form.
83      * @param remoteObject Form provider proxy object.
84      * @return none.
85      */
86     void PostRefreshTask(const int64_t formId, const Want &want, const sptr<IRemoteObject> &remoteObject);
87 
88     /**
89      * @brief Cast temp form data from form provider(task).
90      *
91      * @param formId The Id of the form.
92      * @param want The want of the request.
93      * @param remoteObject Form provider proxy object.
94      * @return none.
95      */
96     void PostCastTempTask(const int64_t formId, const Want &want, const sptr<IRemoteObject> &remoteObject);
97 
98     /**
99      * @brief Post form data to form host(task) when acquire form.
100      * @param formId The Id of the form.
101      * @param callingUid Calling uid.
102      * @param info Form configure info.
103      * @param wantParams WantParams of the request.
104      * @param remoteObject Form provider proxy object.
105      */
106 
107     void PostAcquireTaskToHost(const int64_t formId, const FormRecord &record, const sptr<IRemoteObject> &remoteObject);
108 
109     /**
110      * @brief Post form data to form host(task) when update form.
111      * @param formId The Id of the form.
112      * @param callingUid Calling uid.
113      * @param info Form configure info.
114      * @param wantParams WantParams of the request.
115      * @param remoteObject Form provider proxy object.
116      */
117     void PostUpdateTaskToHost(const int64_t formId, const FormRecord &record, const sptr<IRemoteObject> &remoteObject);
118 
119     /**
120      * @brief Handel form host died(task).
121      * @param remoteHost Form host proxy object.
122      */
123     void PostHostDiedTask(const sptr<IRemoteObject> &remoteHost);
124 
125     /**
126      * @brief Post event notify to form provider.
127      *
128      * @param formEvent The vector of form ids.
129      * @param formVisibleType The form visible type, including FORM_VISIBLE and FORM_INVISIBLE.
130      * @param want The want of the form.
131      * @param remoteObject The form provider proxy object.
132      * @return none.
133      */
134     void PostEventNotifyTask(const std::vector<int64_t> &formEvent, const int32_t formVisibleType, const Want &want,
135         const sptr<IRemoteObject> &remoteObject);
136 
137     /**
138      * @brief Post message event to form provider.
139      * @param formId The Id of the from.
140      * @param message Event message.
141      * @param want The want of the request.
142      * @param remoteObject Form provider proxy object.
143      */
144     void PostFormEventTask(const int64_t formId, const std::string &message, const Want &want,
145         const sptr<IRemoteObject> &remoteObject);
146 
147     /**
148     * @brief Post acquire state to form provider.
149     * @param wantArg The want of onAcquireFormState.
150     * @param provider The provider info.
151     * @param want The want of the request.
152     * @param remoteObject Form provider proxy object.
153     */
154     void PostAcquireStateTask(const Want &wantArg, const std::string &provider, const Want &want,
155                               const sptr <IRemoteObject> &remoteObject);
156 
157      /**
158      * @brief Post uninstall message to form host(task).
159      * @param formIds The Id list of the forms.
160      * @param remoteObject Form provider proxy object.
161      */
162     void PostUninstallTaskToHost(const std::vector<int64_t> &formIds, const sptr<IRemoteObject> &remoteObject);
163 
164     /**
165     * @brief Post acquire form state message to form host(task).
166     * @param state The form state.
167     * @param want The want of onAcquireFormState.
168     * @param remoteObject Form provider proxy object.
169     */
170     void PostAcquireStateTaskToHost(AppExecFwk::FormState state, const AAFwk::Want &want,
171                                     const sptr<IRemoteObject> &remoteObject);
172 private:
173     /**
174      * @brief Acquire form data from form provider.
175      * @param formId The Id of the from.
176      * @param want The want of the request.
177      * @param remoteObject Form provider proxy object.
178      */
179     void AcquireProviderFormInfo(const int64_t formId, const Want &want, const sptr<IRemoteObject> &remoteObject);
180 
181     /**
182      * @brief Notify form provider for delete form.
183      * @param formId The Id of the from.
184      * @param want The want of the form.
185      * @param remoteObject Form provider proxy object.
186      * @return none.
187      */
188     void NotifyFormDelete(const int64_t formId, const Want &want, const sptr<IRemoteObject> &remoteObject);
189 
190     /**
191      * @brief Notify form provider for updating form.
192      * @param formId The Id of the from.
193      * @param want The want of the form.
194      * @param remoteObject Form provider proxy object.
195      * @return none.
196      */
197     void NotifyFormUpdate(const int64_t formId, const Want &want, const sptr<IRemoteObject> &remoteObject);
198 
199     /**
200      * @brief Event notify to form provider.
201      *
202      * @param formEvents The vector of form ids.
203      * @param formVisibleType The form visible type, including FORM_VISIBLE and FORM_INVISIBLE.
204      * @param want The want of the form.
205      * @param remoteObject The form provider proxy object.
206      * @return none.
207      */
208     void EventNotify(const std::vector<int64_t> &formEvents, const int32_t formVisibleType, const Want &want,
209         const sptr<IRemoteObject> &remoteObject);
210 
211     /**
212      * @brief Notify form provider for cast temp form.
213      *
214      * @param formId The Id of the from.
215      * @param want The want of the form.
216      * @param remoteObject Form provider proxy object.
217      * @return none.
218      */
219     void NotifyCastTemp(const int64_t formId, const Want &want, const sptr<IRemoteObject> &remoteObject);
220     /**
221      * @brief Post form data to form host when acquire form..
222      * @param formId The Id of the form.
223      * @param callingUid Calling uid.
224      * @param info Form configure info.
225      * @param wantParams WantParams of the request.
226      * @param remoteObject Form provider proxy object.
227      */
228     void AcquireTaskToHost(const int64_t formId, const FormRecord &record, const sptr<IRemoteObject> &remoteObject);
229 
230     /**
231      * @brief Post form data to form host when update form.
232      * @param formId The Id of the form.
233      * @param callingUid Calling uid.
234      * @param info Form configure info.
235      * @param wantParams WantParams of the request.
236      * @param remoteObject Form provider proxy object.
237      */
238     void UpdateTaskToHost(const int64_t formId, const FormRecord &record, const sptr<IRemoteObject> &remoteObject);
239 
240     /**
241      * @brief Handle form host died.
242      * @param remoteHost Form host proxy object.
243      */
244     void HostDied(const sptr<IRemoteObject> &remoteHost);
245 
246     /**
247      * @brief Post provider batch delete.
248      * @param formIds The Id list.
249      * @param want The want of the request.
250      * @param remoteObject Form provider proxy object.
251      */
252     void ProviderBatchDelete(std::set<int64_t> &formIds, const Want &want, const sptr<IRemoteObject> &remoteObject);
253     /**
254      * @brief Fire message event to form provider.
255      * @param formId The Id of the from.
256      * @param message Event message.
257      * @param want The want of the request.
258      * @param remoteObject Form provider proxy object.
259      */
260     void FireFormEvent(const int64_t formId, const std::string &message, const Want &want,
261         const sptr<IRemoteObject> &remoteObject);
262 
263     /**
264      * @brief Acquire form state to form provider.
265      * @param wantArg The want of onAcquireFormState.
266      * @param provider The provider info.
267      * @param want The want of the request.
268      * @param remoteObject Form provider proxy object.
269      */
270     void AcquireState(const Want &wantArg, const std::string &provider, const Want &want,
271                       const sptr <IRemoteObject> &remoteObject);
272 
273     /**
274      * @brief Handle uninstall message.
275      * @param formIds The Id list of the forms.
276      * @param remoteObject Form provider proxy object.
277      */
278     void FormUninstall(const std::vector<int64_t> &formIds, const sptr<IRemoteObject> &remoteObject);
279 
280     /**
281      * @brief Handle acquire state.
282      * @param state the form state.
283      * @param want The want of onAcquireFormState.
284      * @param remoteObject Form provider proxy object.
285      */
286     void AcquireStateBack(AppExecFwk::FormState state, const AAFwk::Want &want,
287                           const sptr <IRemoteObject> &remoteObject);
288 
289     /**
290      * @brief Create form data for form host.
291      * @param formId The Id of the form.
292      * @param record Form record.
293      * @return Form data.
294      */
295     FormJsInfo CreateFormJsInfo(const int64_t formId, const FormRecord &record);
296 
297 private:
298     std::shared_ptr<AppExecFwk::EventHandler> eventHandler_ = nullptr;
299 };
300 }  // namespace AppExecFwk
301 }  // namespace OHOS
302 #endif // FOUNDATION_APPEXECFWK_SERVICES_FORMMGR_INCLUDE_FORM_TASK_MGR_H
303