• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2023 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_PROXY_H
17 #define OHOS_FORM_FWK_FORM_MGR_PROXY_H
18 
19 #include "form_db_info.h"
20 #include "form_info.h"
21 #include "form_mgr_interface.h"
22 #include "form_state_info.h"
23 #include "form_instance.h"
24 #include "form_instances_filter.h"
25 #include "iremote_proxy.h"
26 
27 namespace OHOS {
28 namespace AppExecFwk {
29 /**
30  * @class FormMgrProxy
31  * FormMgrProxy is used to access form manager service.
32  */
33 class FormMgrProxy : public IRemoteProxy<IFormMgr> {
34 public:
35     explicit FormMgrProxy(const sptr<IRemoteObject> &impl);
36     virtual ~FormMgrProxy() = default;
37     /**
38      * @brief Add form with want, send want to form manager service.
39      * @param formId The Id of the forms to add.
40      * @param want The want of the form to add.
41      * @param callerToken Caller ability token.
42      * @param formInfo Form info.
43      * @return Returns ERR_OK on success, others on failure.
44      */
45     virtual int AddForm(const int64_t formId, const Want &want, const sptr<IRemoteObject> &callerToken,
46         FormJsInfo &formInfo) override;
47 
48     /**
49      * @brief Delete forms with formIds, send formIds to form manager service.
50      * @param formId The Id of the forms to delete.
51      * @param callerToken Caller ability token.
52      * @return Returns ERR_OK on success, others on failure.
53      */
54     virtual int DeleteForm(const int64_t formId, const sptr<IRemoteObject> &callerToken) override;
55 
56     /**
57      * @brief Stop rendering form.
58      * @param formId The Id of the forms to delete.
59      * @param compId The compId of the forms to delete.
60      * @return Returns ERR_OK on success, others on failure.
61      */
62     virtual int StopRenderingForm(const int64_t formId, const std::string &compId) override;
63 
64      /**
65      * @brief Release forms with formIds, send formIds to form manager service.
66      * @param formId The Id of the forms to release.
67      * @param callerToken Caller ability token.
68      * @param delCache Delete Cache or not.
69      * @return Returns ERR_OK on success, others on failure.
70      */
71     virtual int ReleaseForm(const int64_t formId, const sptr<IRemoteObject> &callerToken, const bool delCache) override;
72 
73     /**
74      * @brief Update form with formId, send formId to form manager service.
75      * @param formId The Id of the form to update.
76      * @param FormProviderData Form binding data.
77      * @return Returns ERR_OK on success, others on failure.
78      */
79     virtual int UpdateForm(const int64_t formId, const FormProviderData &FormProviderData) override;
80 
81     /**
82      * @brief Set next refresh time.
83      * @param formId The Id of the form to update.
84      * @param nextTime Next refresh time.
85      * @return Returns ERR_OK on success, others on failure.
86      */
87     virtual int SetNextRefreshTime(const int64_t formId, const int64_t nextTime) override;
88 
89     /**
90      * @brief Release renderer.
91      * @param formId The Id of the forms to release.
92      * @param compId The compId of the forms to release.
93      * @return Returns ERR_OK on success, others on failure.
94      */
95     virtual int ReleaseRenderer(int64_t formId, const std::string &compId) override;
96 
97     /**
98      * @brief Request to publish a form to the form host.
99      *
100      * @param want The want of the form to publish.
101      * @param withFormBindingData Indicates whether the formBindingData is carried with.
102      * @param formBindingData Indicates the form data.
103      * @param formId Return the form id to be published.
104      * @return Returns ERR_OK on success, others on failure.
105      */
106     ErrCode RequestPublishForm(Want &want, bool withFormBindingData,
107                                std::unique_ptr<FormProviderData> &formBindingData, int64_t &formId) override;
108 
109     /**
110      * @brief Lifecycle update.
111      * @param formIds The Id of the forms.
112      * @param callerToken Caller ability token.
113      * @param updateType update type, enable if true and disable if false.
114      * @return Returns ERR_OK on success, others on failure.
115      */
116     virtual int LifecycleUpdate(const std::vector<int64_t> &formIds, const sptr<IRemoteObject> &callerToken,
117     bool updateType) override;
118 
119     /**
120      * @brief Request form with formId and want, send formId and want to form manager service.
121      * @param formId The Id of the form to update.
122      * @param callerToken Caller ability token.
123      * @param want The want of the form to add.
124      * @return Returns ERR_OK on success, others on failure.
125      */
126     virtual int RequestForm(const int64_t formId, const sptr<IRemoteObject> &callerToken, const Want &want) override;
127 
128     /**
129      * @brief Form visible/invisible notify, send formIds to form manager service.
130      * @param formIds The Id list of the forms to notify.
131      * @param callerToken Caller ability token.
132      * @param formVisibleType The form visible type, including FORM_VISIBLE and FORM_INVISIBLE.
133      * @return Returns ERR_OK on success, others on failure.
134      */
135     virtual int NotifyWhetherVisibleForms(const std::vector<int64_t> &formIds, const sptr<IRemoteObject> &callerToken,
136     const int32_t formVisibleType) override;
137 
138     /**
139      * @brief temp form to normal form.
140      * @param formId The Id of the form.
141      * @param callerToken Caller ability token.
142      * @return Returns ERR_OK on success, others on failure.
143      */
144     virtual int CastTempForm(const int64_t formId, const sptr<IRemoteObject> &callerToken) override;
145 
146     /**
147      * @brief Dump all of form storage infos.
148      * @param formInfos All of form storage infos.
149      * @return Returns ERR_OK on success, others on failure.
150      */
151     virtual int DumpStorageFormInfos(std::string &formInfos) override;
152     /**
153      * @brief Dump form info by a bundle name.
154      * @param bundleName The bundle name of form provider.
155      * @param formInfos Form infos.
156      * @return Returns ERR_OK on success, others on failure.
157      */
158     virtual int DumpFormInfoByBundleName(const std::string &bundleName, std::string &formInfos) override;
159     /**
160      * @brief Dump form info by a bundle name.
161      * @param formId The id of the form.
162      * @param formInfo Form info.
163      * @return Returns ERR_OK on success, others on failure.
164      */
165     virtual int DumpFormInfoByFormId(const std::int64_t formId, std::string &formInfo) override;
166     /**
167      * @brief Dump timer info by form id.
168      * @param formId The id of the form.
169      * @param formInfo Form timer info.
170      * @return Returns ERR_OK on success, others on failure.
171      */
172     virtual int DumpFormTimerByFormId(const std::int64_t formId, std::string &isTimingService) override;
173     /**
174      * @brief Process js message event.
175      * @param formId Indicates the unique id of form.
176      * @param want information passed to supplier.
177      * @param callerToken Caller ability token.
178      * @return Returns true if execute success, false otherwise.
179      */
180     virtual int MessageEvent(const int64_t formId, const Want &want, const sptr<IRemoteObject> &callerToken) override;
181 
182     /**
183      * @brief Process js router event.
184      * @param formId Indicates the unique id of form.
185      * @param want the want of the ability to start.
186      * @param callerToken Caller ability token.
187      * @return Returns true if execute success, false otherwise.
188      */
189     virtual int RouterEvent(const int64_t formId, Want &want, const sptr<IRemoteObject> &callerToken) override;
190 
191     /**
192      * @brief Process Background event.
193      * @param formId Indicates the unique id of form.
194      * @param want the want of the ability to start.
195      * @param callerToken Caller ability token.
196      * @return Returns true if execute success, false otherwise.
197      */
198     virtual int BackgroundEvent(const int64_t formId, Want &want, const sptr<IRemoteObject> &callerToken) override;
199 
200     /**
201      * @brief Delete the invalid forms.
202      * @param formIds Indicates the ID of the valid forms.
203      * @param callerToken Caller ability token.
204      * @param numFormsDeleted Returns the number of the deleted forms.
205      * @return Returns ERR_OK on success, others on failure.
206      */
207     virtual int DeleteInvalidForms(const std::vector<int64_t> &formIds, const sptr<IRemoteObject> &callerToken,
208                                    int32_t &numFormsDeleted) override;
209 
210     /**
211      * @brief Acquire form state info by passing a set of parameters (using Want) to the form provider.
212      * @param want Indicates a set of parameters to be transparently passed to the form provider.
213      * @param callerToken Caller ability token.
214      * @param stateInfo Returns the form's state info of the specify.
215      * @return Returns ERR_OK on success, others on failure.
216      */
217     virtual int AcquireFormState(const Want &want, const sptr<IRemoteObject> &callerToken,
218                                  FormStateInfo &stateInfo) override;
219 
220     /**
221      * @brief Notify the form is visible or not.
222      * @param formIds Indicates the ID of the forms.
223      * @param isVisible Visible or not.
224      * @param callerToken Host client.
225      * @return Returns ERR_OK on success, others on failure.
226      */
227     virtual int NotifyFormsVisible(const std::vector<int64_t> &formIds, bool isVisible,
228                                    const sptr<IRemoteObject> &callerToken) override;
229 
230     /**
231      * @brief Notify the form is privacy protected or not.
232      * @param formIds Indicates the ID of the forms.
233      * @param isProtected isProtected or not.
234      * @param callerToken Host client.
235      * @return Returns ERR_OK on success, others on failure.
236      */
237     int NotifyFormsPrivacyProtected(const std::vector<int64_t> &formIds, bool isProtected,
238                                             const sptr<IRemoteObject> &callerToken) override;
239 
240     /**
241      * @brief Notify the form is enable to be updated or not.
242      * @param formIds Indicates the ID of the forms.
243      * @param isEnableUpdate enable update or not.
244      * @param callerToken Host client.
245      * @return Returns ERR_OK on success, others on failure.
246      */
247     virtual int NotifyFormsEnableUpdate(const std::vector<int64_t> &formIds, bool isEnableUpdate,
248                                         const sptr<IRemoteObject> &callerToken) override;
249 
250     /**
251      * @brief Get All FormsInfo.
252      * @param formInfos Return the forms' information of all forms provided.
253      * @return Returns ERR_OK on success, others on failure.
254      */
255     virtual int GetAllFormsInfo(std::vector<FormInfo> &formInfos) override;
256 
257     /**
258      * @brief Get forms info by bundle name .
259      * @param bundleName Application name.
260      * @param formInfos Return the forms' information of the specify application name.
261      * @return Returns ERR_OK on success, others on failure.
262      */
263     virtual int GetFormsInfoByApp(std::string &bundleName, std::vector<FormInfo> &formInfos) override;
264 
265     /**
266      * @brief Get forms info by bundle name and module name.
267      * @param bundleName bundle name.
268      * @param moduleName Module name of hap.
269      * @param formInfos Return the forms' information of the specify bundle name and module name.
270      * @return Returns ERR_OK on success, others on failure.
271      */
272     virtual int GetFormsInfoByModule(std::string &bundleName, std::string &moduleName,
273                                      std::vector<FormInfo> &formInfos) override;
274 
275     /**
276     * @brief This function is called by formProvider and gets forms info by the bundle name of the calling ability.
277     *        The bundle name will be retrieved by form service manager.
278     * @param filter Filter that contains attributes that the formInfos have to have.
279     * @param formInfos Return the forms' information of the calling bundle name
280     * @return Returns ERR_OK on success, others on failure.
281     */
282     int32_t GetFormsInfo(const FormInfoFilter &filter, std::vector<FormInfo> &formInfos) override;
283 
284     /**
285      * @brief Check if the request of publishing a form is supported by the host.
286      * @return Returns true if the request is supported and false otherwise.
287      */
288     bool IsRequestPublishFormSupported() override;
289 
290     /**
291      * @brief Start an ability. This function can only be called by a form extension of a system app.
292      * @param want includes ability name, parameters and relative info sending to an ability.
293      * @param callerToken token of the ability that initially calls this function.
294      * @return Returns ERR_OK on success, others on failure.
295      */
296     int32_t StartAbility(const Want &want, const sptr<IRemoteObject> &callerToken) override;
297 
298     /**
299      * @brief Share form by formID and deviceID.
300      * @param formId Indicates the unique id of form.
301      * @param deviceId Indicates the remote device ID.
302      * @param callerToken Host client.
303      * @param requestCode the request code of this share form.
304      * @return Returns ERR_OK on success, others on failure.
305      */
306     int32_t ShareForm(int64_t formId, const std::string &deviceId, const sptr<IRemoteObject> &callerToken,
307         int64_t requestCode) override;
308 
309     /**
310      * @brief Acquire form data by formId.
311      * @param formId The Id of the form to acquire data.
312      * @param requestCode The request code of this form.
313      * @param callerToken Indicates the host client.
314      * @param formData Return the forms' information of customization
315      * @return Returns ERR_OK on success, others on failure.
316      */
317     int32_t AcquireFormData(int64_t formId, int64_t requestCode, const sptr<IRemoteObject> &callerToken,
318          AAFwk::WantParams &formData) override;
319 
320     /**
321      * @brief Receive form sharing information from remote.
322      * @param info Indicates form sharing information.
323      * @return Returns ERR_OK on success, others on failure.
324      */
325     int32_t RecvFormShareInfoFromRemote(const FormShareInfo &info) override;
326 
327     /**
328     * @brief Check form manager service ready.
329     * @return Return true if form manager service Ready; return false otherwise.
330     */
331     bool CheckFMSReady() override;
332 
333     /**
334      * @brief Register form add observer by bundle.
335      * @param bundleName BundleName of the form host
336      * @param callerToken Caller ability token.
337      * @return Returns ERR_OK on success, others on failure.
338      */
339     ErrCode RegisterFormAddObserverByBundle(const std::string bundleName,
340         const sptr<IRemoteObject> &callerToken) override;
341 
342     /**
343      * @brief Register form remove observer by bundle.
344      * @param bundleName BundleName of the form host
345      * @param callerToken Caller ability token.
346      * @return Returns ERR_OK on success, others on failure.
347      */
348     ErrCode RegisterFormRemoveObserverByBundle(const std::string bundleName,
349         const sptr<IRemoteObject> &callerToken) override;
350 
351     /**
352      * @brief The Call Event triggers the callee method.
353      * @param funcName function name which is used by callee.
354      * @param params parameter which is used by callee.
355      * @return Returns ERR_OK on success, others on failure.
356      */
357     int32_t SetBackgroundFunction(const std::string funcName, const std::string params) override;
358 
359     /**
360     * @brief get forms count.
361     * @param isTempFormFlag Indicates temp form or not.
362     * @param formCount Returns the number of the cast or temp form.
363     * @return Returns ERR_OK on success, others on failure.
364     */
365     int32_t GetFormsCount(bool isTempFormFlag, int32_t &formCount) override;
366 
367     /**
368     * @brief get host forms count.
369     * @param bundleName Indicates form host bundleName.
370     * @param formCount Returns the number of the host form.
371     * @return Returns ERR_OK on success, others on failure.
372     */
373     int32_t GetHostFormsCount(std::string &bundleName, int32_t &formCount) override;
374 
375     /**
376      * @brief Get the running form infos.
377      * @param runningFormInfos Return the running forms' infos currently.
378      * @return Returns ERR_OK on success, others on failure.
379      */
380     ErrCode GetRunningFormInfos(std::vector<RunningFormInfo> &runningFormInfos) override;
381 
382     /**
383      * @brief Get the running form infos by bundle name.
384      * @param bundleName Application name.
385      * @param runningFormInfos Return the running forms' infos of the specify application name.
386      * @return Returns ERR_OK on success, others on failure.
387      */
388     ErrCode GetRunningFormInfosByBundleName(const std::string &bundleName,
389         std::vector<RunningFormInfo> &runningFormInfos) override;
390 
391     /**
392      * @brief Get form instances by filter info.
393      * @param formInstancesFilter includes bundleName, moduleName, formName, abilityName to get formInstances.
394      * @param formInstances return formInstances
395      * @return return ERR_OK on get info success, others on failure.
396      */
397     ErrCode GetFormInstancesByFilter(const FormInstancesFilter &formInstancesFilter,
398         std::vector<FormInstance> &formInstances) override;
399 
400    /**
401     * @brief Get form instance by formId.
402     * @param formId formId Indicates the unique id of form.
403     * @param formInstance return formInstance
404     * @return return ERR_OK on get info success, others on failure.
405     */
406     ErrCode GetFormInstanceById(const int64_t formId, FormInstance &formInstance) override;
407 
408     /**
409      * @brief Get form instance by formId, include form store in DB.
410      * @param formId formId Indicates the unique id of form.
411      * @param isIncludeUnused Indicates whether to include unused form.
412      * @param formInstance return formInstance
413      * @return return ERR_OK on get info success, others on failure.
414      */
415     ErrCode GetFormInstanceById(const int64_t formId, bool isIncludeUnused, FormInstance &formInstance) override;
416 
417     /**
418      * @brief Register form add observer.
419      * @param bundleName BundleName of the form host
420      * @param callerToken Caller ability token.
421      * @return Returns ERR_OK on success, others on failure.
422      */
423     ErrCode RegisterAddObserver(const std::string &bundleName, const sptr<IRemoteObject> &callerToken) override;
424 
425     /**
426      * @brief Register form remove observer.
427      * @param bundleName BundleName of the form host
428      * @param callerToken Caller ability token.
429      * @return Returns ERR_OK on success, others on failure.
430      */
431     ErrCode RegisterRemoveObserver(const std::string &bundleName, const sptr<IRemoteObject> &callerToken) override;
432 
433     /**
434      * @brief Update proxy form with formId, send formId to form manager service.
435      * @param formId The Id of the form to update.
436      * @param FormProviderData Form binding data.
437      * @param std::vector<FormDataProxy> Form proxy vector.
438      * @return Returns ERR_OK on success, others on failure.
439      */
440     ErrCode UpdateProxyForm(int64_t formId, const FormProviderData &FormProviderData,
441         const std::vector<FormDataProxy> &formDataProxies) override;
442 
443     /**
444      * @brief Request to publish a proxy form to the form host.
445      * @param want The want of the form to publish.
446      * @param withFormBindingData Indicates whether the formBindingData is carried with.
447      * @param formBindingData Indicates the form data.
448      * @param formId Return the form id to be published.
449      * @param std::vector<FormDataProxy> Form proxy vector.
450      * @return Returns ERR_OK on success, others on failure.
451      */
452     virtual ErrCode RequestPublishProxyForm(Want &want, bool withFormBindingData,
453         std::unique_ptr<FormProviderData> &formBindingData, int64_t &formId,
454         const std::vector<FormDataProxy> &formDataProxies) override;
455 
456     /**
457      * @brief Registers the callback to publish form. The callback is used to process the publish form request
458      * when the system handler is not found.
459      * @param interceptorCallback The injected callback, should implementation IFormPublishInterceptor.
460      * @return Returns ERR_OK on success, others on failure.
461      */
462     int32_t RegisterPublishFormInterceptor(const sptr<IRemoteObject> &interceptorCallback) override;
463 
464     /**
465      * @brief Unregisters the callback to publish form. The callback is used to process the publish form request
466      * when the system handler is not found.
467      * @param interceptorCallback The injected callback, should implementation IFormPublishInterceptor.
468      * @return Returns ERR_OK on success, others on failure.
469      */
470     int32_t UnregisterPublishFormInterceptor(const sptr<IRemoteObject> &interceptorCallback) override;
471 
472 private:
473     template<typename T>
474     int GetParcelableInfos(MessageParcel &reply, std::vector<T> &parcelableInfos);
475     bool WriteInterfaceToken(MessageParcel &data);
476     template<typename T>
477     int GetParcelableInfo(IFormMgr::Message code, MessageParcel &data, T &parcelableInfo);
478     int SendTransactCmd(IFormMgr::Message code, MessageParcel &data, MessageParcel &reply);
479     int GetStringInfo(IFormMgr::Message code, MessageParcel &data, std::string &stringInfo);
480     int32_t GetFormsInfo(IFormMgr::Message code, MessageParcel &data, std::vector<FormInfo> &formInfos);
481     ErrCode GetRunningFormInfos(IFormMgr::Message code, MessageParcel &data,
482         std::vector<RunningFormInfo> &runningFormInfos);
483     int32_t GetFormInstance(IFormMgr::Message code, MessageParcel &data, std::vector<FormInstance> &formInstances);
484     bool WriteFormDataProxies(MessageParcel &data, const std::vector<FormDataProxy> &formDataProxies);
485 private:
486     static inline BrokerDelegator<FormMgrProxy> delegator_;
487 };
488 }  // namespace AppExecFwk
489 }  // namespace OHOS
490 #endif  // OHOS_FORM_FWK_FORM_MGR_PROXY_H
491