• 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_serial_queue.h"
26 #include "form_state_info.h"
27 #include "iremote_object.h"
28 #include "running_form_info.h"
29 #include "want.h"
30 
31 namespace OHOS {
32 namespace AppExecFwk {
33 using Want = OHOS::AAFwk::Want;
34 using WantParams = OHOS::AAFwk::WantParams;
35 enum class TaskType : int64_t {
36     RECYCLE_FORM,
37 };
38 /**
39  * @class FormTaskMgr
40  * form task manager.
41  */
42 class FormTaskMgr final : public DelayedRefSingleton<FormTaskMgr> {
43     DECLARE_DELAYED_REF_SINGLETON(FormTaskMgr)
44 
45 public:
46     DISALLOW_COPY_AND_MOVE(FormTaskMgr);
47 
48     /**
49      * @brief SetSerialQueue.
50      * @param serialQueue serial queue
51      */
SetSerialQueue(const std::shared_ptr<FormSerialQueue> & serialQueue)52     inline void SetSerialQueue(const std::shared_ptr<FormSerialQueue> &serialQueue)
53     {
54         serialQueue_ = serialQueue;
55     }
56 
57     /**
58      * @brief Acquire form data from form provider(task).
59      * @param formId The Id of the form.
60      * @param want The want of the request.
61      * @param remoteObject Form provider proxy object.
62      */
63     void PostAcquireTask(const int64_t formId, const Want &want, const sptr<IRemoteObject> &remoteObject);
64 
65     /**
66      * @brief Acquire share form data from form provider(task).
67      * @param formId The Id of the form.
68      * @param remoteDeviceId The device ID to share.
69      * @param want The want of the request.
70      * @param remoteObject Form provider proxy object.
71      */
72     void PostShareAcquireTask(int64_t formId, const std::string &remoteDeviceId, const Want &want,
73         const sptr<IRemoteObject> &remoteObject);
74 
75     /**
76      * @brief Delete form data from form provider(task).
77      * @param formId The Id of the form.
78      * @param want The want of the request.
79      * @param remoteObject Form provider proxy object.
80      */
81     void PostDeleteTask(const int64_t formId, const Want &want, const sptr<IRemoteObject> &remoteObject);
82    /**
83      * @brief Notify provider batch delete.
84      * @param formIds The Id list.
85      * @param want The want of the request.
86      * @param remoteObject Form provider proxy object.
87      */
88     void PostProviderBatchDeleteTask(std::set<int64_t> &formIds, const Want &want,
89         const sptr<IRemoteObject> &remoteObject);
90     /**
91      * @brief Refresh form data from form provider(task).
92      *
93      * @param formId The Id of the form.
94      * @param want The want of the form.
95      * @param remoteObject Form provider proxy object.
96      * @return none.
97      */
98     void PostRefreshTask(const int64_t formId, const Want &want, const sptr<IRemoteObject> &remoteObject);
99 
100     /**
101      * @brief Cast temp form data from form provider(task).
102      *
103      * @param formId The Id of the form.
104      * @param want The want of the request.
105      * @param remoteObject Form provider proxy object.
106      * @return none.
107      */
108     void PostCastTempTask(const int64_t formId, const Want &want, const sptr<IRemoteObject> &remoteObject);
109 
110     /**
111      * @brief Post form data to form host(task) when acquire form.
112      * @param formId The Id of the form.
113      * @param record form record.
114      * @param remoteObject Form provider proxy object.
115      */
116     void PostAcquireTaskToHost(const int64_t formId, const FormRecord &record, const sptr<IRemoteObject> &remoteObject);
117 
118     /**
119      * @brief Post form data to form host(task) when update form.
120      * @param formId The Id of the form.
121      * @param record form record.
122      * @param remoteObject Form provider proxy object.
123      */
124     void PostUpdateTaskToHost(const int64_t formId, const FormRecord &record, const sptr<IRemoteObject> &remoteObject);
125 
126     /**
127      * @brief Handel form host died(task).
128      * @param remoteHost Form host proxy object.
129      */
130     void PostHostDiedTask(const sptr<IRemoteObject> &remoteHost);
131 
132     /**
133      * @brief Post event notify to form provider.
134      *
135      * @param formEvent The vector of form ids.
136      * @param formVisibleType The form visible type, including FORM_VISIBLE and FORM_INVISIBLE.
137      * @param want The want of the form.
138      * @param remoteObject The form provider proxy object.
139      */
140     void PostEventNotifyTask(const std::vector<int64_t> &formEvent, const int32_t formVisibleType, const Want &want,
141         const sptr<IRemoteObject> &remoteObject);
142 
143     /**
144      * @brief Post message event to form provider.
145      * @param formId The Id of the from.
146      * @param message Event message.
147      * @param want The want of the request.
148      * @param remoteObject Form provider proxy object.
149      */
150     void PostFormEventTask(const int64_t formId, const std::string &message, const Want &want,
151         const sptr<IRemoteObject> &remoteObject);
152 
153     /**
154     * @brief Post acquire state to form provider.
155     * @param wantArg The want of onAcquireFormState.
156     * @param provider The provider info.
157     * @param want The want of the request.
158     * @param remoteObject Form provider proxy object.
159     */
160     void PostAcquireStateTask(const Want &wantArg, const std::string &provider, const Want &want,
161                               const sptr <IRemoteObject> &remoteObject);
162 
163     /**
164     * @brief Post acquire data to form provider.
165     * @param formId The Id of the from.
166     * @param want The want of the request.
167     * @param remoteObject Form provider proxy object.
168     */
169     void PostAcquireDataTask(const int64_t formId, const Want &want, const sptr<IRemoteObject> &remoteObject);
170 
171      /**
172      * @brief Post uninstall message to form host(task).
173      * @param formIds The Id list of the forms.
174      * @param remoteObject Form provider proxy object.
175      */
176     void PostUninstallTaskToHost(const std::vector<int64_t> &formIds, const sptr<IRemoteObject> &remoteObject);
177 
178     /**
179     * @brief Post acquire form state message to form host(task).
180     * @param state The form state.
181     * @param want The want of onAcquireFormState.
182     * @param remoteObject Form provider proxy object.
183     */
184     void PostAcquireStateTaskToHost(AppExecFwk::FormState state, const AAFwk::Want &want,
185                                     const sptr<IRemoteObject> &remoteObject);
186 
187     /**
188     * @brief Post acquire form data message to form host(task).
189     * @param wantParams Indicates the data information acquired by the form.
190     * @param requestCode Indicates the requested id.
191     * @param remoteObject Form provider proxy object.
192     */
193     void PostAcquireDataTaskToHost(const AAFwk::WantParams &wantParams, int64_t requestCode,
194                                     const sptr<IRemoteObject> &remoteObject);
195 
196     /**
197     * @brief Post form share error code to form host(task).
198     * @param formShareRequestCode The request code for this share.
199     * @param result The error code of this share.
200     */
201     void PostFormShareSendResponse(int64_t formShareRequestCode, int32_t result);
202 
203     void PostRenderForm(const FormRecord &formRecord, const Want &want, const sptr<IRemoteObject> &remoteObject);
204 
205     void PostStopRenderingForm(const FormRecord &formRecord, const Want &want, const sptr<IRemoteObject> &remoteObject);
206 
207     void PostReloadForm(const std::vector<FormRecord> &&formRecords, const Want &want,
208         const sptr<IRemoteObject> &remoteObject);
209 
210     void PostAddTaskToHost(const std::string bundleName, const sptr<IRemoteObject> &remoteObject,
211         const RunningFormInfo &runningFormInfo);
212 
213     void PostRouterProxyToHost(const int64_t formId, const sptr<IRemoteObject> &remoteObject, const Want &want);
214 
215     void PostRemoveTaskToHost(const std::string bundleName, const sptr<IRemoteObject> &remoteObject,
216         const RunningFormInfo &runningFormInfo);
217 
218     void PostReleaseRenderer(
219         int64_t formId, const std::string &compId, const std::string &uid, const sptr<IRemoteObject> &remoteObject);
220 
221     void PostOnUnlock(const sptr<IRemoteObject> &remoteObject);
222 
223     /**
224     * @brief Post Form visible/invisible notify.
225     * @param formIds  the Ids of forms need to notify.
226     * @param formInstanceMaps formInstances for visibleNotify.
227     * @param eventMaps eventMaps for event notify.
228     * @param formVisibleType The form visible type, including FORM_VISIBLE and FORM_INVISIBLE.
229     * @param visibleNotifyDelay delay time.
230     */
231     void PostVisibleNotify(const std::vector<int64_t> &formIds,
232         std::map<std::string, std::vector<FormInstance>> &formInstanceMaps,
233         std::map<std::string, std::vector<int64_t>> &eventMaps,
234         const int32_t formVisibleType, int32_t visibleNotifyDelay);
235 
236     /**
237     * @brief Post form click event.
238     * @param bundleName BundleName of the form host
239     * @param formEventType form event type.
240     * @param remoteObject thr remote observer.
241     * @param runningFormInfo Current form data.
242     */
243     void PostFormClickEventToHost(
244         const std::string &bundleName, const std::string &formEventType, const sptr<IRemoteObject> &remoteObject,
245         const RunningFormInfo &runningFormInfo);
246 
247     /**
248      * @brief Post recycle forms.
249      * @param formIds the Ids of forms to be recycled.
250      * @param want The want of the request.
251      * @param remoteObjectOfHost Form host proxy object.
252      * @param remoteObjectOfRender Form render proxy object.
253      */
254     void PostRecycleForms(const std::vector<int64_t> &formIds, const Want &want,
255         const sptr<IRemoteObject> &remoteObjectOfHost, const sptr<IRemoteObject> &remoteObjectOfRender);
256 
257     /**
258      * @brief Post recover form.
259      * @param formIds the Id of form to be recovered.
260      * @param want The want of the request.
261      * @param remoteObject Form render proxy object.
262      */
263     void PostRecoverForm(const int64_t &formId, const Want &want, const sptr<IRemoteObject> &remoteObject);
264 
265     /**
266      * @brief Cancel delay task.
267      * @param eventMsg Delay Task.
268      */
269     void CancelDelayTask(const std::pair<int64_t, int64_t> &eventMsg);
270 private:
271     /**
272      * @brief Acquire form data from form provider.
273      * @param formId The Id of the from.
274      * @param want The want of the request.
275      * @param remoteObject Form provider proxy object.
276      */
277     void AcquireProviderFormInfo(const int64_t formId, const Want &want, const sptr<IRemoteObject> &remoteObject);
278 
279     /**
280      * @brief Acquire share form data from form provider(task).
281      * @param formId The Id of the form.
282      * @param remoteDeviceId The device ID to share.
283      * @param want The want of the request.
284      * @param remoteObject Form provider proxy object.
285      */
286     void AcquireShareFormData(int64_t formId, const std::string &remoteDeviceId, const Want &want,
287         const sptr<IRemoteObject> &remoteObject);
288 
289     /**
290      * @brief Notify form provider for delete form.
291      * @param formId The Id of the from.
292      * @param want The want of the form.
293      * @param remoteObject Form provider proxy object.
294      */
295     void NotifyFormDelete(const int64_t formId, const Want &want, const sptr<IRemoteObject> &remoteObject);
296 
297     /**
298      * @brief Notify form provider for updating form.
299      * @param formId The Id of the from.
300      * @param want The want of the form.
301      * @param remoteObject Form provider proxy object.
302      */
303     void NotifyFormUpdate(const int64_t formId, const Want &want, const sptr<IRemoteObject> &remoteObject);
304 
305     /**
306      * @brief Event notify to form provider.
307      *
308      * @param formEvents The vector of form ids.
309      * @param formVisibleType The form visible type, including FORM_VISIBLE and FORM_INVISIBLE.
310      * @param want The want of the form.
311      * @param remoteObject The form provider proxy object.
312      */
313     void EventNotify(const std::vector<int64_t> &formEvents, const int32_t formVisibleType, const Want &want,
314         const sptr<IRemoteObject> &remoteObject);
315 
316     /**
317      * @brief Notify form provider for cast temp form.
318      *
319      * @param formId The Id of the from.
320      * @param want The want of the form.
321      * @param remoteObject Form provider proxy object.
322      * @return none.
323      */
324     void NotifyCastTemp(const int64_t formId, const Want &want, const sptr<IRemoteObject> &remoteObject);
325     /**
326      * @brief Post form data to form host when acquire form..
327      * @param formId The Id of the form.
328      * @param record form record.
329      * @param remoteObject Form provider proxy object.
330      */
331     void AcquireTaskToHost(const int64_t formId, const FormRecord &record, const sptr<IRemoteObject> &remoteObject);
332 
333     /**
334      * @brief Post form data to form host when update form.
335      * @param formId The Id of the form.
336      * @param record form record.
337      * @param remoteObject Form provider proxy object.
338      */
339     void UpdateTaskToHost(const int64_t formId, const FormRecord &record, const sptr<IRemoteObject> &remoteObject);
340 
341     /**
342      * @brief Handle form host died.
343      * @param remoteHost Form host proxy object.
344      */
345     void HostDied(const sptr<IRemoteObject> &remoteHost);
346 
347     /**
348      * @brief Post provider batch delete.
349      * @param formIds The Id list.
350      * @param want The want of the request.
351      * @param remoteObject Form provider proxy object.
352      */
353     void ProviderBatchDelete(std::set<int64_t> &formIds, const Want &want, const sptr<IRemoteObject> &remoteObject);
354     /**
355      * @brief Fire message event to form provider.
356      * @param formId The Id of the from.
357      * @param message Event message.
358      * @param want The want of the request.
359      * @param remoteObject Form provider proxy object.
360      */
361     void FireFormEvent(const int64_t formId, const std::string &message, const Want &want,
362         const sptr<IRemoteObject> &remoteObject);
363 
364     /**
365      * @brief Acquire form state to form provider.
366      * @param wantArg The want of onAcquireFormState.
367      * @param provider The provider info.
368      * @param want The want of the request.
369      * @param remoteObject Form provider proxy object.
370      */
371     void AcquireState(const Want &wantArg, const std::string &provider, const Want &want,
372                       const sptr <IRemoteObject> &remoteObject);
373     /**
374      * @brief Handle acquire data.
375      * @param wantParams Indicates the data information acquired by the form.
376      * @param requestCode Indicates the requested id.
377      * @param remoteObject Form provider proxy object.
378      */
379     void AcquireFormDataBack(const AAFwk::WantParams &wantParams, int64_t requestCode,
380                             const sptr<IRemoteObject> &remoteObject);
381 
382     /**
383      * @brief Acquire form data to form provider.
384      * @param formId The Id of the form.
385      * @param want The want of the request.
386      * @param remoteObject Form provider proxy object.
387      */
388     void AcquireFormData(const int64_t formId, const Want &want, const sptr<IRemoteObject> &remoteObject);
389 
390     /**
391      * @brief Handle uninstall message.
392      * @param formIds The Id list of the forms.
393      * @param remoteObject Form provider proxy object.
394      */
395     void FormUninstall(const std::vector<int64_t> &formIds, const sptr<IRemoteObject> &remoteObject);
396 
397     /**
398      * @brief Handle acquire state.
399      * @param state the form state.
400      * @param want The want of onAcquireFormState.
401      * @param remoteObject Form provider proxy object.
402      */
403     void AcquireStateBack(AppExecFwk::FormState state, const AAFwk::Want &want,
404                           const sptr <IRemoteObject> &remoteObject);
405 
406     /**
407      * @brief Create form data for form host.
408      * @param formId The Id of the form.
409      * @param record Form record.
410      * @return Form data.
411      */
412     FormJsInfo CreateFormJsInfo(const int64_t formId, const FormRecord &record);
413 
414     /**
415     * @brief Post form share error code to form host(task).
416     * @param formShareRequestCode The request code for this share.
417     * @param result The error code of this share.
418     */
419     void FormShareSendResponse(int64_t formShareRequestCode, int32_t result);
420 
421     /**
422     * @brief Post form share error code to form host(task).
423     * @param formShareRequestCode The request code for this share.
424     * @param result The error code of this share.
425     */
426     void RenderForm(const FormRecord &formRecord, const Want &want, const sptr<IRemoteObject> &remoteObject);
427 
428     void StopRenderingForm(const FormRecord &formRecord, const Want &want, const sptr<IRemoteObject> &remoteObject);
429 
430     void ReloadForm(const std::vector<FormRecord> &&formRecords, const Want &want,
431         const sptr<IRemoteObject> &remoteObject);
432 
433     void FormAdd(const std::string bundleName, const sptr<IRemoteObject> &remoteObject,
434         const RunningFormInfo &runningFormInfo);
435 
436     void FormRemove(const std::string bundleName, const sptr<IRemoteObject> &remoteObject,
437         const RunningFormInfo &runningFormInfo);
438 
439     void ReleaseRenderer(
440         int64_t formId, const std::string &compId, const std::string &uid, const sptr<IRemoteObject> &remoteObject);
441 
442     void OnUnlock(const sptr<IRemoteObject> &remoteObject);
443 
444     void RemoveConnection(int32_t connectId);
445 
446     /**
447      * @brief Form router event proxy.
448      * @param formId The id of the form.
449      * @param remoteObject Form router proxy manager object.
450      * @param want The want of the form for router event.
451      */
452     void FormRouterEventProxy(const int64_t formId, const sptr<IRemoteObject> &remoteObject, const Want &want);
453 
454     /**
455     * @brief Form visible/invisible notify.
456     * @param formIds  the Ids of forms need to notify.
457     * @param formInstanceMaps formInstances for visibleNotify.
458     * @param eventMaps eventMaps for event notify.
459     * @param formVisibleType The form visible type, including FORM_VISIBLE and FORM_INVISIBLE.
460     */
461     void NotifyVisible(const std::vector<int64_t> &formIds,
462         std::map<std::string, std::vector<FormInstance>> formInstanceMaps,
463         std::map<std::string, std::vector<int64_t>> eventMaps, const int32_t formVisibleType);
464 
465     /**
466      * @brief Handle recycle form message.
467      * @param formId The Id of form to be recycled.
468      * @param remoteObjectOfHost Form host proxy object.
469      * @param remoteObjectOfRender Form render proxy object.
470      */
471     void RecycleForm(const int64_t &formId, const sptr<IRemoteObject> &remoteObjectOfHost,
472         const sptr<IRemoteObject> &remoteObjectOfRender);
473 
474     /**
475      * @brief Handle recover form message.
476      * @param formId The Id of form to be recovered.
477      * @param want The want of the request.
478      * @param remoteObject Form render proxy object.
479      */
480     void RecoverForm(const int64_t &formId, const Want &want, const sptr<IRemoteObject> &remoteObject);
481 
482     /**
483     * @brief Notify remote observer form click event.
484     * @param bundleName BundleName of the form host
485     * @param formEventType  form event type.
486     * @param remoteObject thr remote observer.
487     * @param runningFormInfo Current form data.
488     */
489     void FormClickEvent(const std::string &bundleName, const std::string &formEventType,
490         const sptr<IRemoteObject> &remoteObject, const RunningFormInfo &runningFormInfo);
491 
492 private:
493     std::shared_ptr<FormSerialQueue> serialQueue_ = nullptr;
494 };
495 }  // namespace AppExecFwk
496 }  // namespace OHOS
497 #endif // OHOS_FORM_FWK_FORM_TASK_MGR_H
498