1 /*
2  * Copyright (c) 2021-2024 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_MGR_STUB_H
17 #define OHOS_FORM_FWK_FORM_MGR_STUB_H
18 
19 #include <map>
20 
21 #include "form_mgr_interface.h"
22 #include "form_instance.h"
23 #include "form_instances_filter.h"
24 #include "iremote_object.h"
25 #include "iremote_stub.h"
26 
27 namespace OHOS {
28 namespace AppExecFwk {
29 /**
30  * @class FormMgrStub
31  * Form manager service stub.
32  */
33 class FormMgrStub : public IRemoteStub<IFormMgr> {
34 public:
35     FormMgrStub();
36     virtual ~FormMgrStub();
37     /**
38      * @brief Handle remote request.
39      * @param data input param.
40      * @param reply output param.
41      * @param option message option.
42      * @return Returns ERR_OK on success, others on failure.
43      */
44     virtual int OnRemoteRequest(
45         uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option);
46 
47 private:
48     /**
49      * @brief Handle AddForm message.
50      * @param data input param.
51      * @param reply output param.
52      * @return Returns ERR_OK on success, others on failure.
53      */
54     int32_t HandleAddForm(MessageParcel &data, MessageParcel &reply);
55 
56     /**
57      * @brief Handle CreateForm message.
58      * @param data input param.
59      * @param reply output param.
60      * @return Returns ERR_OK on success, others on failure.
61      */
62     int32_t HandleCreateForm(MessageParcel &data, MessageParcel &reply);
63 
64     /**
65      * @brief Handle DeleteForm message.
66      * @param data input param.
67      * @param reply output param.
68      * @return Returns ERR_OK on success, others on failure.
69      */
70     int32_t HandleDeleteForm(MessageParcel &data, MessageParcel &reply);
71 
72     /**
73      * @brief Handle StopRenderingForm message.
74      * @param data input param.
75      * @param reply output param.
76      * @return Returns ERR_OK on success, others on failure.
77      */
78     int32_t HandleStopRenderingForm(MessageParcel &data, MessageParcel &reply);
79     /**
80      * @brief Handle ReleaseForm message.
81      * @param data input param.
82      * @param reply output param.
83      * @return Returns ERR_OK on success, others on failure.
84      */
85     int32_t HandleReleaseForm(MessageParcel &data, MessageParcel &reply);
86     /**
87      * @brief Handle UpdateForm message.
88      * @param data input param.
89      * @param reply output param.
90      * @return Returns ERR_OK on success, others on failure.
91      */
92     int32_t HandleUpdateForm(MessageParcel &data, MessageParcel &reply);
93 
94     /**
95      * @brief handle LifecycleUpdate message.
96      * @param data input param.
97      * @param reply output param.
98      * @return Returns ERR_OK on success, others on failure.
99      */
100     int32_t HandleLifecycleUpdate(MessageParcel &data, MessageParcel &reply);
101     /**
102      * @brief handle SetNextRefreshTime message.
103      * @param data input param.
104      * @param reply output param.
105      * @return Returns ERR_OK on success, others on failure.
106      */
107     int32_t HandleSetNextRefreshTime(MessageParcel &data, MessageParcel &reply);
108 
109     /**
110      * @brief handle ReleaseRenderer message.
111      * @param data input param.
112      * @param reply output param.
113      * @return Returns ERR_OK on success, others on failure.
114      */
115     int32_t HandleReleaseRenderer(MessageParcel &data, MessageParcel &reply);
116 
117     /**
118      * @brief handle RequestPublishForm message.
119      * @param data input param.
120      * @param reply output param.
121      * @return Returns ERR_OK on success, others on failure.
122      */
123     ErrCode HandleRequestPublishForm(MessageParcel &data, MessageParcel &reply);
124 
125     ErrCode HandleSetPublishFormResult(MessageParcel &data, MessageParcel &reply);
126 
127     ErrCode HandleAcquireAddFormResult(MessageParcel &data, MessageParcel &reply);
128 
129     /**
130      * @brief Handle RequestForm message.
131      * @param data input param.
132      * @param reply output param.
133      * @return Returns ERR_OK on success, others on failure.
134      */
135     int32_t HandleRequestForm(MessageParcel &data, MessageParcel &reply);
136     /**
137      * @brief Handle NotifyWhetherVisibleForms message.
138      * @param data input param.
139      * @param reply output param.
140      * @return Returns ERR_OK on success, others on failure.
141      */
142     int32_t HandleNotifyWhetherVisibleForms(MessageParcel &data, MessageParcel &reply);
143 
144     /**
145      * @brief Handle HasFormVisible message.
146      * @param data input param.
147      * @param reply output param.
148      * @return Returns ERR_OK on success, others on failure.
149      */
150     int32_t HandleHasFormVisible(MessageParcel &data, MessageParcel &reply);
151 
152     /**
153      * @brief Handle CastTempForm message.
154      * @param data input param.
155      * @param reply output param.
156      * @return Returns ERR_OK on success, others on failure.
157      */
158     int32_t HandleCastTempForm(MessageParcel &data, MessageParcel &reply);
159     /**
160      * @brief Handle DumpStorageFormInfos message.
161      * @param data input param.
162      * @param reply output param.
163      * @return Returns ERR_OK on success, others on failure.
164      */
165     int32_t HandleDumpStorageFormInfos(MessageParcel &data, MessageParcel &reply);
166     /**
167      * @brief Handle DumpFormInfoByBundleName message.
168      * @param data input param.
169      * @param reply output param.
170      * @return Returns ERR_OK on success, others on failure.
171      */
172     int32_t HandleDumpFormInfoByBundleName(MessageParcel &data, MessageParcel &reply);
173     /**
174      * @brief Handle DumpFormInfoByFormId message.
175      * @param data input param.
176      * @param reply output param.
177      * @return Returns ERR_OK on success, others on failure.
178      */
179     int32_t HandleDumpFormInfoByFormId(MessageParcel &data, MessageParcel &reply);
180     /**
181      * @brief Handle DumpFormTimerByFormId message.
182      * @param data input param.
183      * @param reply output param.
184      * @return Returns ERR_OK on success, others on failure.
185      */
186     int32_t HandleDumpFormTimerByFormId(MessageParcel &data, MessageParcel &reply);
187     /**
188      * @brief Handle DumpFormInfoByFormId message.
189      * @param data input param.
190      * @param reply output param.
191      * @return Returns ERR_OK on success, others on failure.
192      */
193     int32_t HandleMessageEvent(MessageParcel &data, MessageParcel &reply);
194 
195     /**
196      * @brief Handle HandleRouterEvent message.
197      * @param data input param.
198      * @param reply output param.
199      * @return Returns ERR_OK on success, others on failure.
200      */
201     int32_t HandleRouterEvent(MessageParcel &data, MessageParcel &reply);
202 
203     /**
204      * @brief Handle Background message.
205      * @param data input param.
206      * @param reply output param.
207      * @return Returns ERR_OK on success, others on failure.
208      */
209     int32_t HandleBackgroundEvent(MessageParcel &data, MessageParcel &reply);
210 
211     /**
212      * @brief Handle DeleteInvalidForms message.
213      * @param data input param.
214      * @param reply output param.
215      * @return Returns ERR_OK on success, others on failure.
216      */
217     int32_t HandleDeleteInvalidForms(MessageParcel &data, MessageParcel &reply);
218     /**
219      * @brief Handle AcquireFormState message.
220      * @param data input param.
221      * @param reply output param.
222      * @return Returns ERR_OK on success, others on failure.
223      */
224     int32_t HandleAcquireFormState(MessageParcel &data, MessageParcel &reply);
225     /**
226      * @brief Handle NotifyFormsVisible message.
227      * @param data input param.
228      * @param reply output param.
229      * @return Returns ERR_OK on success, others on failure.
230      */
231     int32_t HandleNotifyFormsVisible(MessageParcel &data, MessageParcel &reply);
232     /**
233      * @brief Handle NotifyFormsPrivacyProtected message.
234      * @param data input param.
235      * @param reply output param.
236      * @return Returns ERR_OK on success, others on failure.
237      */
238     int32_t HandleNotifyFormsPrivacyProtected(MessageParcel &data, MessageParcel &reply);
239     /**
240      * @brief Handle NotifyFormsEnableUpdate message.
241      * @param data input param.
242      * @param reply output param.
243      * @return Returns ERR_OK on success, others on failure.
244      */
245     int32_t HandleNotifyFormsEnableUpdate(MessageParcel &data, MessageParcel &reply);
246     /**
247      * @brief Handle GetAllFormsInfo message.
248      * @param data input param.
249      * @param reply output param.
250      * @return Returns ERR_OK on success, others on failure.
251      */
252     int32_t HandleGetAllFormsInfo(MessageParcel &data, MessageParcel &reply);
253     /**
254      * @brief Handle GetFormsInfoByApp message.
255      * @param data input param.
256      * @param reply output param.
257      * @return Returns ERR_OK on success, others on failure.
258      */
259     int32_t HandleGetFormsInfoByApp(MessageParcel &data, MessageParcel &reply);
260     /**
261      * @brief Handle GetFormsInfoByModule message.
262      * @param data input param.
263      * @param reply output param.
264      * @return Returns ERR_OK on success, others on failure.
265      */
266     int32_t HandleGetFormsInfoByModule(MessageParcel &data, MessageParcel &reply);
267     /**
268      * @brief Handle GetFormsInfoByModule message.
269      * @param data input param.
270      * @param reply output param.
271      * @return Returns ERR_OK on success, others on failure.
272      */
273     int32_t HandleGetFormsInfoByFilter(MessageParcel &data, MessageParcel &reply);
274     /**
275      * @brief Handle GetFormsInfo message.
276      * @param data input param.
277      * @param reply output param.
278      * @return Returns ERR_OK on success, others on failure.
279      */
280     int32_t HandleGetFormsInfo(MessageParcel &data, MessageParcel &reply);
281 
282     /**
283      * @brief Handle share form message.
284      * @param data input param.
285      * @param reply output param.
286      * @return Returns ERR_OK on success, others on failure.
287      */
288     int32_t HandleShareForm(MessageParcel &data, MessageParcel &reply);
289 
290     /**
291      * @brief Handle acquire form data.
292      * @param data input param.
293      * @param reply output param.
294      * @return Returns ERR_OK on success, others on failure.
295      */
296     int32_t HandleAcquireFormData(MessageParcel &data, MessageParcel &reply);
297 
298     /**
299      * @brief Receive form sharing information from remote.
300      * @param data input param.
301      * @param reply output param.
302      * @return Returns ERR_OK on success, others on failure.
303      */
304     int32_t HandleRecvFormShareInfoFromRemote(MessageParcel &data, MessageParcel &reply);
305 
306     /**
307      * @brief Handle IsRequestPublishFormSupported message.
308      * @param data input param.
309      * @param reply output param.
310      * @return Returns ERR_OK on success, others on failure.
311      */
312     int32_t HandleIsRequestPublishFormSupported(MessageParcel &data, MessageParcel &reply);
313 
314     /**
315      * @brief Handle StartAbility message.
316      * @param data input param.
317      * @param reply output param.
318      * @return Returns ERR_OK on success, others on failure.
319      */
320     int32_t HandleStartAbility(MessageParcel &data, MessageParcel &reply);
321 
322     /**
323      * @brief Check form manager service ready
324      * @param data input param
325      * @param reply output param
326      * @return Return ERR_OK on success, others on failure
327     */
328     int32_t HandleCheckFMSReady(MessageParcel &data, MessageParcel &reply);
329 
330     /**
331      * @brief Check whether the form is system app.
332      * @param data input param
333      * @param reply output param
334      * @return Returns ERR_OK on success, others on failure.
335      */
336     ErrCode HandleIsSystemAppForm(MessageParcel &data, MessageParcel &reply);
337 
338     /**
339      * @brief Handle RegisterFormAddObserverByBundle message.
340      * @param data input param
341      * @param reply output param
342      * @return Return ERR_OK on success, others on failure
343     */
344     int32_t HandleRegisterFormAddObserverByBundle(MessageParcel &data, MessageParcel &reply);
345 
346     /**
347      * @brief Handle RegisterFormRemoveObserverByBundle message.
348      * @param data input param
349      * @param reply output param
350      * @return Return ERR_OK on success, others on failure
351     */
352     int32_t HandleRegisterFormRemoveObserverByBundle(MessageParcel &data, MessageParcel &reply);
353 
354     /**
355      * @brief Handle get forms count message.
356      * @param data input param.
357      * @param reply output param.
358      * @return Return ERR_OK on success, others on failure.
359     */
360     int32_t HandleGetFormsCount(MessageParcel &data, MessageParcel &reply);
361 
362     /**
363      * @brief Handle get host forms count message.
364      * @param data input param.
365      * @param reply output param.
366      * @return Return ERR_OK on success, others on failure.
367     */
368     int32_t HandleGetHostFormsCount(MessageParcel &data, MessageParcel &reply);
369 
370     /**
371      * @brief Handle get Running forms infos message.
372      * @param data input param.
373      * @param reply output param.
374      * @return Return ERR_OK on success, others on failure.
375     */
376     ErrCode HandleGetRunningFormInfos(MessageParcel &data, MessageParcel &reply);
377 
378     /**
379      * @brief Handle get Running forms infos by bundleName message.
380      * @param data input param.
381      * @param reply output param.
382      * @return Return ERR_OK on success, others on failure.
383     */
384     ErrCode HandleGetRunningFormInfosByBundleName(MessageParcel &data, MessageParcel &reply);
385 
386     /**
387      * @brief Get form instances by filter info.
388      * @param data input param
389      * @param reply output param
390      * @return Return ERR_OK on success, others on failure
391      */
392     ErrCode HandleGetFormInstancesByFilter(MessageParcel &data, MessageParcel &reply);
393 
394     /**
395      * @brief Get form instances by filter info.
396      * @param data input param
397      * @param reply output param
398      * @return Return ERR_OK on success, others on failure
399      */
400     ErrCode HandleGetFormInstanceById(MessageParcel &data, MessageParcel &reply);
401 
402     /**
403      * @brief Register form add observer.
404      * @param data input param
405      * @param reply output param
406      * @return Return ERR_OK on success, others on failure
407      */
408     ErrCode HandleRegisterAddObserver(MessageParcel &data, MessageParcel &reply);
409     /**
410      * @brief Register form remove observer.
411      * @param data input param
412      * @param reply output param
413      * @return Return ERR_OK on success, others on failure
414      */
415     ErrCode HandleRegisterRemoveObserver(MessageParcel &data, MessageParcel &reply);
416 
417     /**
418      * @brief Register form router event proxy.
419      * @param data input param
420      * @param reply output param
421      * @return Return ERR_OK on success, others on failure
422      */
423     ErrCode HandleRegisterFormRouterProxy(MessageParcel &data, MessageParcel &reply);
424 
425     /**
426      * @brief Unregister form router event proxy.
427      * @param data input param
428      * @param reply output param
429      * @return Return ERR_OK on success, others on failure
430      */
431     ErrCode HandleUnregisterFormRouterProxy(MessageParcel &data, MessageParcel &reply);
432 
433     /**
434      * @brief update proxy form.
435      * @param data input param
436      * @param reply output param
437      * @return Return ERR_OK on success, others on failure
438      */
439     ErrCode HandleUpdateProxyForm(MessageParcel &data, MessageParcel &reply);
440 
441     /**
442      * @brief handle request publish form message.
443      * @param data input param.
444      * @param reply output param.
445      * @return Returns ERR_OK on success, others on failure.
446      */
447     ErrCode HandleRequestPublishProxyForm(MessageParcel &data, MessageParcel &reply);
448 
449     /**
450      * @brief Register the callback to publish form. The callback is used to process the publish form request
451      * when the system handler is not found.
452      * @param interceptorCallback The injected callback, should implementation IFormPublishInterceptor.
453      * @return Returns ERR_OK on success, others on failure.
454      */
455     int32_t HandleRegisterPublishFormInterceptor(MessageParcel &data, MessageParcel &reply);
456 
457     /**
458      * @brief Unregister the callback to publish form. The callback is used to process the publish form request
459      * when the system handler is not found.
460      * @param interceptorCallback The injected callback, should implementation IFormPublishInterceptor.
461      * @return Returns ERR_OK on success, others on failure.
462      */
463     int32_t HandleUnregisterPublishFormInterceptor(MessageParcel &data, MessageParcel &reply);
464 
465     /**
466      * @brief Handle retister click callback event observer message.
467      * @param data input param
468      * @param reply output param
469      * @return Return ERR_OK on success, others on failure
470     */
471     int32_t HandleRegisterClickCallbackEventObserver(MessageParcel &data, MessageParcel &reply);
472 
473     /**
474      * @brief Handle unretister click callback event observer message.
475      * @param data input param
476      * @param reply output param
477      * @return Return ERR_OK on success, others on failure
478     */
479     int32_t HandleUnregisterClickCallbackEventObserver(MessageParcel &data, MessageParcel &reply);
480 
481     bool ReadFormDataProxies(MessageParcel &data, std::vector<FormDataProxy> &formDataProxies);
482 
483     /**
484      * @brief Handle set forms recyclable message.
485      * @param data input param.
486      * @param reply output param.
487      * @return Returns ERR_OK on success, others on failure.
488      */
489     int32_t HandleSetFormsRecyclable(MessageParcel &data, MessageParcel &reply);
490 
491     /**
492      * @brief Handle recycle forms message.
493      * @param data input param.
494      * @param reply output param.
495      * @return Returns ERR_OK on success, others on failure.
496      */
497     int32_t HandleRecycleForms(MessageParcel &data, MessageParcel &reply);
498 
499     /**
500      * @brief Handle recover forms message.
501      * @param data input param.
502      * @param reply output param.
503      * @return Returns ERR_OK on success, others on failure.
504      */
505     int32_t HandleRecoverForms(MessageParcel &data, MessageParcel &reply);
506 
507     /**
508      * @brief Handle UpdateFormLocation.
509      * @param data input param.
510      * @param reply output param.
511      * @return Returns ERR_OK on success, others on failure.
512      */
513     ErrCode HandleUpdateFormLocation(MessageParcel &data, MessageParcel &reply);
514 
515     /**
516      * @brief handle RequestPublishFormWithSnapshot message.
517      * @param data input param.
518      * @param reply output param.
519      * @return Returns ERR_OK on success, others on failure.
520      */
521     ErrCode HandleRequestPublishFormWithSnapshot(MessageParcel &data, MessageParcel &reply);
522 
523     /**
524      * @brief Update form with formRefreshType, send to form manager service.
525      * @param formRefreshType The type of the form to refresh, 0: AllForm 1: 2: AppForm 2: AtomicServiceForm
526      * @return Returns ERR_OK on success, others on failure.
527      */
528     ErrCode HandleBatchRefreshForms(MessageParcel &data, MessageParcel &reply);
529 
530     /**
531      * @brief Handle enable or disable forms message.
532      * @param data input param.
533      * @param reply output param.
534      * @return Returns ERR_OK on success, others on failure.
535      */
536     int32_t HandleEnableForms(MessageParcel &data, MessageParcel &reply);
537 
538     /**
539      * @brief Handle check form bundle is forbidden.
540      * @param data input param.
541      * @param reply output param.
542      * @return Returns ERR_OK on success, others on failure.
543      */
544     ErrCode HandleIsFormBundleForbidden(MessageParcel &data, MessageParcel &reply);
545 
546     /**
547      * @brief the first part of handle remote request.
548      * @param code ipc code.
549      * @param data input param.
550      * @param reply output param.
551      * @param option message option.
552      * @return Returns ERR_OK on success, others on failure.
553      */
554     int OnRemoteRequestFirst(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option);
555 
556     /**
557      * @brief the second part of handle remote request.
558      * @param code ipc code.
559      * @param data input param.
560      * @param reply output param.
561      * @param option message option.
562      * @return Returns ERR_OK on success, others on failure.
563      */
564     int OnRemoteRequestSecond(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option);
565 
566     /**
567      * @brief the third part of handle remote request.
568      * @param code ipc code.
569      * @param data input param.
570      * @param reply output param.
571      * @param option message option.
572      * @return Returns ERR_OK on success, others on failure.
573      */
574     int OnRemoteRequestThird(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option);
575 
576     /**
577      * @brief the fourth part of handle remote request.
578      * @param code ipc code.
579      * @param data input param.
580      * @param reply output param.
581      * @param option message option.
582      * @return Returns ERR_OK on success, others on failure.
583      */
584     int OnRemoteRequestFourth(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option);
585 
586     /**
587      * @brief Handle update form size.
588      * @param data input param.
589      * @param reply output param.
590      * @return Returns ERR_OK on success, others on failure.
591      */
592     ErrCode HandleUpdateFormSize(MessageParcel &data, MessageParcel &reply);
593 private:
594     DISALLOW_COPY_AND_MOVE(FormMgrStub);
595 
596     /**
597      * @brief Write a parcelabe vector objects to the proxy node.
598      * @param parcelableVector Indicates the objects to be write.
599      * @param reply Indicates the reply to be sent;
600      * @return Returns true if objects send successfully; returns false otherwise.
601      */
602     template<typename T>
603     bool WriteParcelableVector(std::vector<T> &parcelableVector, Parcel &reply);
604 };
605 }  // namespace AppExecFwk
606 }  // namespace OHOS
607 #endif  // OHOS_FORM_FWK_FORM_MGR_STUB_H
608