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