• 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 #include "form_mgr.h"
17 
18 #include <thread>
19 
20 #include "appexecfwk_errors.h"
21 #include "form_errors.h"
22 #include "hilog_wrapper.h"
23 #include "if_system_ability_manager.h"
24 #include "ipc_skeleton.h"
25 #include "iservice_registry.h"
26 #include "string_ex.h"
27 #include "system_ability_definition.h"
28 
29 namespace OHOS {
30 namespace AppExecFwk {
FormMgr()31 FormMgr::FormMgr(){}
~FormMgr()32 FormMgr::~FormMgr()
33 {
34     if (remoteProxy_ != nullptr) {
35         auto remoteObject = remoteProxy_->AsObject();
36         if (remoteObject != nullptr) {
37             remoteObject->RemoveDeathRecipient(deathRecipient_);
38         }
39     }
40 }
41 
42 /**
43  * @brief Get the error message by error code.
44  * @param errorCode the error code return form fms.
45  * @return Returns the error message detail.
46  */
GetErrorMsg(int errorCode)47 std::string FormMgr::GetErrorMsg(int errorCode)
48 {
49     return "unknown error";
50 }
51 
52 /**
53  * @brief Add form with want, send want to form manager service.
54  * @param formId The Id of the forms to add.
55  * @param want The want of the form to add.
56  * @param callerToken Caller ability token.
57  * @param formInfo Form info.
58  * @return Returns ERR_OK on success, others on failure.
59  */
AddForm(const int64_t formId,const Want & want,const sptr<IRemoteObject> & callerToken,FormJsInfo & formInfo)60 int FormMgr::AddForm(
61     const int64_t formId,
62     const Want &want,
63     const sptr<IRemoteObject> &callerToken,
64     FormJsInfo &formInfo)
65 {
66     HILOG_INFO("%{public}s called.", __func__);
67     int errCode = Connect();
68     if (errCode != ERR_OK) {
69         HILOG_ERROR("%{public}s failed errCode:%{public}d.", __func__, errCode);
70         return errCode;
71     }
72     return remoteProxy_->AddForm(formId, want, callerToken, formInfo);
73 }
74 
75 /**
76  * @brief Delete forms with formIds, send formIds to form manager service.
77  * @param formId The Id of the forms to delete.
78  * @param callerToken Caller ability token.
79  * @return Returns ERR_OK on success, others on failure.
80  */
DeleteForm(const int64_t formId,const sptr<IRemoteObject> & callerToken)81 int FormMgr::DeleteForm(const int64_t formId, const sptr<IRemoteObject> &callerToken)
82 {
83     HILOG_INFO("%{public}s called.", __func__);
84     int errCode = Connect();
85     if (errCode != ERR_OK) {
86         HILOG_ERROR("%{public}s failed errCode:%{public}d.", __func__, errCode);
87         return errCode;
88     }
89     return remoteProxy_->DeleteForm(formId, callerToken);
90 }
91 
92 /**
93  * @brief Release forms with formIds, send formIds to form manager service.
94  * @param formId The Id of the forms to release.
95  * @param callerToken Caller ability token.
96  * @param delCache Delete Cache or not.
97  * @return Returns ERR_OK on success, others on failure.
98  */
ReleaseForm(const int64_t formId,const sptr<IRemoteObject> & callerToken,const bool delCache)99 int FormMgr::ReleaseForm(const int64_t formId, const sptr<IRemoteObject> &callerToken, const bool delCache)
100 {
101     HILOG_INFO("%{public}s called.", __func__);
102     int errCode = Connect();
103     if (errCode != ERR_OK) {
104         HILOG_ERROR("%{public}s failed errCode:%{public}d.", __func__, errCode);
105         return errCode;
106     }
107     return remoteProxy_->ReleaseForm(formId, callerToken, delCache);
108 }
109 
110 /**
111  * @brief Update form with formId, send formId to form manager service.
112  * @param formId The Id of the form to update.
113  * @param formBindingData Form binding data.
114  * @return Returns ERR_OK on success, others on failure.
115  */
UpdateForm(const int64_t formId,const FormProviderData & formBindingData)116 int FormMgr::UpdateForm(const int64_t formId, const FormProviderData &formBindingData)
117 {
118     HILOG_INFO("%{public}s called.", __func__);
119     int errCode = Connect();
120     if (errCode != ERR_OK) {
121         HILOG_ERROR("%{public}s failed errCode:%{public}d.", __func__, errCode);
122         return errCode;
123     }
124     return remoteProxy_->UpdateForm(formId, formBindingData);
125 }
126 
127 /**
128  * @brief Notify the form service that the form user's lifecycle is updated.
129  *
130  * This should be called when form user request form.
131  *
132  * @param formId Indicates the unique id of form.
133  * @param callerToken Indicates the callback remote object of specified form user.
134  * @param want information passed to supplier.
135  * @return Returns true if execute success, false otherwise.
136  */
RequestForm(const int64_t formId,const sptr<IRemoteObject> & callerToken,const Want & want)137 int FormMgr::RequestForm(const int64_t formId, const sptr<IRemoteObject> &callerToken, const Want &want)
138 {
139     HILOG_INFO("%{public}s called.", __func__);
140     int errCode = Connect();
141     if (errCode != ERR_OK) {
142         HILOG_ERROR("%{public}s failed errCode:%{public}d.", __func__, errCode);
143         return errCode;
144     }
145     return remoteProxy_->RequestForm(formId, callerToken, want);
146 }
147 
148 /**
149  * @brief Form visible/invisible notify, send formIds to form manager service.
150  * @param formIds The Id list of the forms to notify.
151  * @param callerToken Caller ability token.
152  * @param formVisibleType The form visible type, including FORM_VISIBLE and FORM_INVISIBLE.
153  * @return Returns ERR_OK on success, others on failure.
154  */
NotifyWhetherVisibleForms(const std::vector<int64_t> & formIds,const sptr<IRemoteObject> & callerToken,const int32_t formVisibleType)155 int FormMgr::NotifyWhetherVisibleForms(
156     const std::vector<int64_t> &formIds,
157     const sptr<IRemoteObject> &callerToken,
158     const int32_t formVisibleType)
159 {
160     HILOG_INFO("%{public}s called.", __func__);
161     int errCode = Connect();
162     if (errCode != ERR_OK) {
163         HILOG_ERROR("%{public}s failed errCode:%{public}d.", __func__, errCode);
164         return errCode;
165     }
166     return remoteProxy_->NotifyWhetherVisibleForms(formIds, callerToken, formVisibleType);
167 }
168 
169 /**
170  * @brief temp form to normal form.
171  * @param formId The Id of the form.
172  * @param callerToken Caller ability token.
173  * @return None.
174  */
CastTempForm(const int64_t formId,const sptr<IRemoteObject> & callerToken)175 int FormMgr::CastTempForm(const int64_t formId, const sptr<IRemoteObject> &callerToken)
176 {
177     HILOG_INFO("%{public}s called.", __func__);
178     int errCode = Connect();
179     if (errCode != ERR_OK) {
180         HILOG_ERROR("%{public}s failed errCode:%{public}d.", __func__, errCode);
181         return errCode;
182     }
183     return remoteProxy_->CastTempForm(formId, callerToken);
184 }
185 
186 /**
187  * @brief Dump all of form storage infos.
188  * @param formInfos All of form storage infos.
189  * @return Returns ERR_OK on success, others on failure.
190  */
DumpStorageFormInfos(std::string & formInfos)191 int FormMgr::DumpStorageFormInfos(std::string &formInfos)
192 {
193     HILOG_INFO("%{public}s called.", __func__);
194     int errCode = Connect();
195     if (errCode != ERR_OK) {
196         HILOG_ERROR("%{public}s failed errCode:%{public}d.", __func__, errCode);
197         return errCode;
198     }
199     return remoteProxy_->DumpStorageFormInfos(formInfos);
200 }
201 /**
202  * @brief Dump form info by a bundle name.
203  * @param bundleName The bundle name of form provider.
204  * @param formInfos Form infos.
205  * @return Returns ERR_OK on success, others on failure.
206  */
DumpFormInfoByBundleName(const std::string bundleName,std::string & formInfos)207 int FormMgr::DumpFormInfoByBundleName(const std::string bundleName, std::string &formInfos)
208 {
209     HILOG_INFO("%{public}s called.", __func__);
210     int errCode = Connect();
211     if (errCode != ERR_OK) {
212         HILOG_ERROR("%{public}s failed errCode:%{public}d.", __func__, errCode);
213         return errCode;
214     }
215     return remoteProxy_->DumpFormInfoByBundleName(bundleName, formInfos);
216 }
217 /**
218  * @brief Dump form info by a bundle name.
219  * @param formId The id of the form.
220  * @param formInfo Form info.
221  * @return Returns ERR_OK on success, others on failure.
222  */
DumpFormInfoByFormId(const std::int64_t formId,std::string & formInfo)223 int FormMgr::DumpFormInfoByFormId(const std::int64_t formId, std::string &formInfo)
224 {
225     HILOG_INFO("%{public}s called.", __func__);
226     int errCode = Connect();
227     if (errCode != ERR_OK) {
228         HILOG_ERROR("%{public}s failed errCode:%{public}d.", __func__, errCode);
229         return errCode;
230     }
231     return remoteProxy_->DumpFormInfoByFormId(formId, formInfo);
232 }
233 /**
234  * @brief Dump form timer by form id.
235  * @param formId The id of the form.
236  * @param formInfo Form timer.
237  * @return Returns ERR_OK on success, others on failure.
238  */
DumpFormTimerByFormId(const std::int64_t formId,std::string & isTimingService)239 int FormMgr::DumpFormTimerByFormId(const std::int64_t formId, std::string &isTimingService)
240 {
241     HILOG_INFO("%{public}s called.", __func__);
242     int errCode = Connect();
243     if (errCode != ERR_OK) {
244         HILOG_ERROR("%{public}s failed errCode:%{public}d.", __func__, errCode);
245         return errCode;
246     }
247     return remoteProxy_->DumpFormTimerByFormId(formId, isTimingService);
248 }
249 /**
250  * @brief Process js message event.
251  * @param formId Indicates the unique id of form.
252  * @param want information passed to supplier.
253  * @param callerToken Caller ability token.
254  * @return Returns true if execute success, false otherwise.
255  */
MessageEvent(const int64_t formId,const Want & want,const sptr<IRemoteObject> & callerToken)256 int FormMgr::MessageEvent(const int64_t formId, const Want &want, const sptr<IRemoteObject> &callerToken)
257 {
258     HILOG_INFO("%{public}s called.", __func__);
259     int errCode = Connect();
260     if (errCode != ERR_OK) {
261         HILOG_ERROR("%{public}s failed errCode:%{public}d.", __func__, errCode);
262         return errCode;
263     }
264     return remoteProxy_->MessageEvent(formId, want, callerToken);
265 }
266 
267 /**
268  * @brief Process js router event.
269  * @param formId Indicates the unique id of form.
270  * @param want the want of the ability to start.
271  * @return Returns true if execute success, false otherwise.
272  */
RouterEvent(const int64_t formId,Want & want)273 int FormMgr::RouterEvent(const int64_t formId, Want &want)
274 {
275     HILOG_INFO("%{public}s called.", __func__);
276     int errCode = Connect();
277     if (errCode != ERR_OK) {
278         HILOG_ERROR("%{public}s failed errCode:%{public}d.", __func__, errCode);
279         return errCode;
280     }
281     return remoteProxy_->RouterEvent(formId, want);
282 }
283 
284 /**
285  * @brief Set next refresh time.
286  * @param formId The id of the form.
287  * @param nextTime Next refresh time.
288  * @return Returns ERR_OK on success, others on failure.
289  */
SetNextRefreshTime(const int64_t formId,const int64_t nextTime)290 int FormMgr::SetNextRefreshTime(const int64_t formId, const int64_t nextTime)
291 {
292     HILOG_INFO("%{public}s called.", __func__);
293     int errCode = Connect();
294     if (errCode != ERR_OK) {
295         HILOG_ERROR("%{public}s failed errCode:%{public}d.", __func__, errCode);
296         return errCode;
297     }
298     return remoteProxy_->SetNextRefreshTime(formId, nextTime);
299 }
300 
301 /**
302  * @brief Lifecycle Update.
303  * @param formIds The id of the forms.
304  * @param callerToken Host client.
305  * @param updateType Next refresh time.
306  * @return Returns ERR_OK on success, others on failure.
307  */
LifecycleUpdate(const std::vector<int64_t> & formIds,const sptr<IRemoteObject> & callerToken,const int32_t updateType)308 int FormMgr::LifecycleUpdate(
309     const std::vector<int64_t> &formIds,
310     const sptr<IRemoteObject> &callerToken,
311     const int32_t updateType)
312 {
313     HILOG_INFO("%{public}s called.", __func__);
314     int errCode = Connect();
315     if (errCode != ERR_OK) {
316         HILOG_ERROR("%{public}s failed errCode:%{public}d.", __func__, errCode);
317         return errCode;
318     }
319     return remoteProxy_->LifecycleUpdate(formIds, callerToken, updateType);
320 }
321 /**
322  * @brief Get fms recoverStatus.
323  *
324  * @return The current recover status.
325  */
GetRecoverStatus()326 int FormMgr::GetRecoverStatus()
327 {
328     HILOG_INFO("%{public}s called.", __func__);
329     return recoverStatus_;
330 }
331 
332 /**
333  * @brief Set fms recoverStatus.
334  *
335  * @param recoverStatus The recover status.
336  */
SetRecoverStatus(int recoverStatus)337 void FormMgr::SetRecoverStatus(int recoverStatus)
338 {
339     HILOG_INFO("%{public}s called.", __func__);
340     recoverStatus_ = recoverStatus;
341 }
342 
343 /**
344  * @brief Get the error message content.
345  *
346  * @param errCode Error code.
347  * @return Message content.
348  */
GetErrorMessage(int errCode)349 std::string FormMgr::GetErrorMessage(int errCode)
350 {
351     HILOG_INFO("%{public}s called.", __func__);
352     return FormErrors::GetInstance().GetErrorMessage(errCode);
353 }
354 
355 /**
356  * @brief Register death callback.
357  *
358  * @param deathCallback Death callback.
359  */
RegisterDeathCallback(const std::shared_ptr<FormCallbackInterface> & formDeathCallback)360 void FormMgr::RegisterDeathCallback(const std::shared_ptr<FormCallbackInterface> &formDeathCallback)
361 {
362     HILOG_INFO("%{public}s called.", __func__);
363     if (formDeathCallback == nullptr) {
364         HILOG_ERROR("%{public}s error, form death callback is nullptr.", __func__);
365         return;
366     }
367     formDeathCallbacks_.emplace_back(formDeathCallback);
368 }
369 
370 /**
371  * @brief UnRegister death callback.
372  *
373  * @param deathCallback Death callback.
374  */
UnRegisterDeathCallback(const std::shared_ptr<FormCallbackInterface> & formDeathCallback)375 void FormMgr::UnRegisterDeathCallback(const std::shared_ptr<FormCallbackInterface> &formDeathCallback)
376 {
377     HILOG_INFO("%{public}s called.", __func__);
378     if (formDeathCallback == nullptr) {
379         HILOG_ERROR("%{public}s error, form death callback is nullptr.", __func__);
380         return;
381     }
382 
383     // Remove the specified death callback in the vector of death callback
384     auto iter = std::find(formDeathCallbacks_.begin(), formDeathCallbacks_.end(), formDeathCallback);
385     if (iter != formDeathCallbacks_.end()) {
386         formDeathCallbacks_.erase(iter);
387     }
388     HILOG_INFO("%{public}s end.", __func__);
389 }
390 
391 /**
392  * @brief Get death recipient.
393  * @return deathRecipient_.
394  */
GetDeathRecipient() const395 sptr<IRemoteObject::DeathRecipient> FormMgr::GetDeathRecipient() const
396 {
397     return deathRecipient_;
398 }
399 
400 /**
401  * @brief Check whether the specified death callback is registered in form mgr.
402  * @param formDeathCallback The specified death callback for checking.
403  * @return Return true on success, false on failure.
404  */
CheckIsDeathCallbackRegistered(const std::shared_ptr<FormCallbackInterface> & formDeathCallback)405 bool FormMgr::CheckIsDeathCallbackRegistered(const std::shared_ptr<FormCallbackInterface> &formDeathCallback)
406 {
407     HILOG_INFO("%{public}s called.", __func__);
408     auto iter = std::find(formDeathCallbacks_.begin(), formDeathCallbacks_.end(), formDeathCallback);
409     if (iter != formDeathCallbacks_.end()) {
410         return true;
411     }
412     return false;
413 }
414 
415 /**
416  * @brief Notices IRemoteBroker died.
417  * @param remote remote object.
418  */
OnRemoteDied(const wptr<IRemoteObject> & remote)419 void FormMgr::FormMgrDeathRecipient::OnRemoteDied(const wptr<IRemoteObject> &remote)
420 {
421     HILOG_INFO("%{public}s called.", __func__);
422     if (remote == nullptr) {
423         HILOG_ERROR("%{public}s failed, remote is nullptr.", __func__);
424         return;
425     }
426 
427     if (FormMgr::GetInstance().GetRecoverStatus() == Constants::IN_RECOVERING) {
428         HILOG_WARN("%{public}s, fms in recovering.", __func__);
429         return;
430     }
431     // Reset proxy
432     FormMgr::GetInstance().ResetProxy(remote);
433 
434     if (!FormMgr::GetInstance().Reconnect()) {
435         HILOG_ERROR("%{public}s, form mgr service died, try to reconnect to fms failed.", __func__);
436         FormMgr::GetInstance().SetRecoverStatus(Constants::RECOVER_FAIL);
437         return;
438     }
439 
440     // refresh form host.
441     for (auto &deathCallback : FormMgr::GetInstance().formDeathCallbacks_) {
442         deathCallback->OnDeathReceived();
443     }
444     FormMgr::GetInstance().SetRecoverStatus(Constants::NOT_IN_RECOVERY);
445 }
446 
447 /**
448  * @brief Reconnect form manager service once per 1000 milliseconds,
449  *        until the connection succeeds or reaching the max retry times.
450  * @return Returns true if execute success, false otherwise.
451  */
Reconnect()452 bool FormMgr::Reconnect()
453 {
454     HILOG_INFO("%{public}s called.", __func__);
455     for (int i = 0; i < Constants::MAX_RETRY_TIME; i++) {
456         // Sleep 1000 milliseconds before reconnect.
457         std::this_thread::sleep_for(std::chrono::milliseconds(Constants::SLEEP_TIME));
458 
459         // try to connect fms
460         if (Connect() != ERR_OK) {
461             HILOG_ERROR("%{public}s, get fms proxy fail, try again.", __func__);
462             continue;
463         }
464 
465         HILOG_INFO("%{public}s, get fms proxy success.", __func__);
466         return true;
467     }
468 
469     return false;
470 }
471 
472 /**
473  * @brief Connect form manager service.
474  * @return Returns ERR_OK on success, others on failure.
475  */
Connect()476 ErrCode FormMgr::Connect()
477 {
478     std::lock_guard<std::mutex> lock(connectMutex_);
479     if (remoteProxy_ != nullptr && !resetFlag_) {
480         return ERR_OK;
481     }
482 
483     sptr<ISystemAbilityManager> systemManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
484     if (systemManager == nullptr) {
485         HILOG_ERROR("%{private}s fail to get registry", __func__);
486         return ERR_APPEXECFWK_FORM_GET_SYSMGR_FAILED;
487     }
488     sptr<IRemoteObject> remoteObject = systemManager->GetSystemAbility(FORM_MGR_SERVICE_ID);
489     if (remoteObject == nullptr) {
490         HILOG_ERROR("%{private}s fail to connect FormMgrService", __func__);
491         return ERR_APPEXECFWK_FORM_GET_FMS_FAILED;
492     }
493     deathRecipient_ = sptr<IRemoteObject::DeathRecipient>(new FormMgrDeathRecipient());
494     if (deathRecipient_ == nullptr) {
495         HILOG_ERROR("%{public}s Failed to create FormMgrDeathRecipient!", __func__);
496         return ERR_APPEXECFWK_FORM_COMMON_CODE;
497     }
498     if ((remoteObject->IsProxyObject()) && (!remoteObject->AddDeathRecipient(deathRecipient_))) {
499         HILOG_ERROR("%{public}s Add death recipient to FormMgrService failed.", __func__);
500         return ERR_APPEXECFWK_FORM_COMMON_CODE;
501     }
502 
503     remoteProxy_ = iface_cast<IFormMgr>(remoteObject);
504     HILOG_DEBUG("%{public}s Connecting FormMgrService success.", __func__);
505     return ERR_OK;
506 }
507 
508 /**
509  * @brief Reset proxy.
510  * @param remote remote object.
511  */
ResetProxy(const wptr<IRemoteObject> & remote)512 void FormMgr::ResetProxy(const wptr<IRemoteObject> &remote)
513 {
514     HILOG_INFO("%{public}s called.", __func__);
515     std::lock_guard<std::mutex> lock(connectMutex_);
516     if (remoteProxy_ == nullptr) {
517         HILOG_ERROR("%{public}s failed, remote proxy is nullptr.", __func__);
518         return;
519     }
520 
521     // set formMgr's recover status to IN_RECOVERING.
522     recoverStatus_ = Constants::IN_RECOVERING;
523 
524     // remove the death recipient
525     auto serviceRemote = remoteProxy_->AsObject();
526     if ((serviceRemote != nullptr) && (serviceRemote == remote.promote())) {
527         serviceRemote->RemoveDeathRecipient(deathRecipient_);
528     }
529     // clearn the remote proxy
530     remoteProxy_ = nullptr;
531 }
532 
533 /**
534  * @brief Set form mgr service for test.
535  */
SetFormMgrService(sptr<IFormMgr> formMgrService)536 void FormMgr::SetFormMgrService(sptr<IFormMgr> formMgrService)
537 {
538     HILOG_INFO("%{public}s called.", __func__);
539     remoteProxy_ = formMgrService;
540 }
541 
542 /**
543  * @brief  Add forms to storage for st .
544  * @param Want The Want of the form to add.
545  * @return Returns ERR_OK on success, others on failure.
546  */
DistributedDataAddForm(const Want & want)547 int FormMgr::DistributedDataAddForm(const Want &want)
548 {
549     HILOG_INFO("%{public}s called.", __func__);
550     int errCode = Connect();
551     if (errCode != ERR_OK) {
552         HILOG_ERROR("%{public}s failed errCode:%{public}d.", __func__, errCode);
553         return errCode;
554     }
555     return remoteProxy_->DistributedDataAddForm(want);
556 }
557 
558 /**
559  * @brief  Delete form form storage for st.
560  * @param formId The formId of the form to delete.
561  * @return Returns ERR_OK on success, others on failure.
562  */
DistributedDataDeleteForm(const std::string & formId)563 int FormMgr::DistributedDataDeleteForm(const std::string &formId)
564 {
565     HILOG_INFO("%{public}s called.", __func__);
566     int errCode = Connect();
567     if (errCode != ERR_OK) {
568         HILOG_ERROR("%{public}s failed errCode:%{public}d.", __func__, errCode);
569         return errCode;
570     }
571     return remoteProxy_->DistributedDataDeleteForm(formId);
572 }
573 
574 /**
575  * @brief Delete the invalid forms.
576  * @param formIds Indicates the ID of the valid forms.
577  * @param callerToken Host client.
578  * @param numFormsDeleted Returns the number of the deleted forms.
579  * @return Returns ERR_OK on success, others on failure.
580  */
DeleteInvalidForms(const std::vector<int64_t> & formIds,const sptr<IRemoteObject> & callerToken,int32_t & numFormsDeleted)581 int FormMgr::DeleteInvalidForms(const std::vector<int64_t> &formIds, const sptr<IRemoteObject> &callerToken,
582                                 int32_t &numFormsDeleted)
583 {
584     HILOG_INFO("%{public}s start.", __func__);
585     int errCode = Connect();
586     if (errCode != ERR_OK) {
587         HILOG_ERROR("%{public}s failed, errCode: %{public}d.", __func__, errCode);
588         return errCode;
589     }
590     return remoteProxy_->DeleteInvalidForms(formIds, callerToken, numFormsDeleted);
591 }
592 
593 /**
594  * @brief Acquire form state info by passing a set of parameters (using Want) to the form provider.
595  * @param want Indicates a set of parameters to be transparently passed to the form provider.
596  * @param callerToken Host client.
597  * @param stateInfo Returns the form's state info of the specify.
598  * @return Returns ERR_OK on success, others on failure.
599  */
AcquireFormState(const Want & want,const sptr<IRemoteObject> & callerToken,FormStateInfo & stateInfo)600 int FormMgr::AcquireFormState(const Want &want, const sptr<IRemoteObject> &callerToken, FormStateInfo &stateInfo)
601 {
602     HILOG_INFO("%{public}s start.", __func__);
603     int errCode = Connect();
604     if (errCode != ERR_OK) {
605         HILOG_ERROR("%{public}s failed, errCode: %{public}d.", __func__, errCode);
606         return errCode;
607     }
608     return remoteProxy_->AcquireFormState(want, callerToken, stateInfo);
609 }
610 
611 /**
612  * @brief Notify the form is visible or not.
613  * @param formIds Indicates the ID of the forms.
614  * @param isVisible Visible or not.
615  * @param callerToken Host client.
616  * @return Returns ERR_OK on success, others on failure.
617  */
NotifyFormsVisible(const std::vector<int64_t> & formIds,bool isVisible,const sptr<IRemoteObject> & callerToken)618 int FormMgr::NotifyFormsVisible(const std::vector<int64_t> &formIds, bool isVisible,
619                                 const sptr<IRemoteObject> &callerToken)
620 {
621     HILOG_INFO("%{public}s start.", __func__);
622     int errCode = Connect();
623     if (errCode != ERR_OK) {
624         HILOG_ERROR("%{public}s failed, errCode: %{public}d.", __func__, errCode);
625         return errCode;
626     }
627     return remoteProxy_->NotifyFormsVisible(formIds, isVisible, callerToken);
628 }
629 
630 /**
631  * @brief Notify the form is enable to be updated or not.
632  * @param formIds Indicates the ID of the forms.
633  * @param isEnableUpdate enable update or not.
634  * @param callerToken Host client.
635  * @return Returns ERR_OK on success, others on failure.
636  */
NotifyFormsEnableUpdate(const std::vector<int64_t> & formIds,bool isEnableUpdate,const sptr<IRemoteObject> & callerToken)637 int FormMgr::NotifyFormsEnableUpdate(const std::vector<int64_t> &formIds, bool isEnableUpdate,
638                                      const sptr<IRemoteObject> &callerToken)
639 {
640     HILOG_INFO("%{public}s start.", __func__);
641     int errCode = Connect();
642     if (errCode != ERR_OK) {
643         HILOG_ERROR("%{public}s failed, errCode: %{public}d.", __func__, errCode);
644         return errCode;
645     }
646     return remoteProxy_->NotifyFormsEnableUpdate(formIds, isEnableUpdate, callerToken);
647 }
648 
649 /**
650  * @brief Get All FormsInfo.
651  * @param formInfos Return the forms' information of all forms provided.
652  * @return Returns ERR_OK on success, others on failure.
653  */
GetAllFormsInfo(std::vector<FormInfo> & formInfos)654 int FormMgr::GetAllFormsInfo(std::vector<FormInfo> &formInfos)
655 {
656     HILOG_INFO("%{public}s start.", __func__);
657     int errCode = Connect();
658     if (errCode != ERR_OK) {
659         HILOG_INFO("%{public}s failed, errCode: %{public}d.", __func__, errCode);
660         return errCode;
661     }
662     return remoteProxy_->GetAllFormsInfo(formInfos);
663 }
664 
665 /**
666  * @brief Get forms info by bundle name .
667  * @param bundleName Application name.
668  * @param formInfos Return the forms' information of the specify application name.
669  * @return Returns ERR_OK on success, others on failure.
670  */
GetFormsInfoByApp(std::string & bundleName,std::vector<FormInfo> & formInfos)671 int FormMgr::GetFormsInfoByApp(std::string &bundleName, std::vector<FormInfo> &formInfos)
672 {
673     HILOG_INFO("%{public}s start.", __func__);
674     int errCode = Connect();
675     if (errCode != ERR_OK) {
676         HILOG_ERROR("%{public}s failed errCode:%{public}d.", __func__, errCode);
677         return errCode;
678     }
679     return remoteProxy_->GetFormsInfoByApp(bundleName, formInfos);
680 }
681 
682 /**
683  * @brief Get forms info by bundle name and module name.
684  * @param bundleName bundle name.
685  * @param moduleName Module name of hap.
686  * @param formInfos Return the forms' information of the specify bundle name and module name.
687  * @return Returns ERR_OK on success, others on failure.
688  */
GetFormsInfoByModule(std::string & bundleName,std::string & moduleName,std::vector<FormInfo> & formInfos)689 int FormMgr::GetFormsInfoByModule(std::string &bundleName, std::string &moduleName, std::vector<FormInfo> &formInfos)
690 {
691     HILOG_INFO("%{public}s start.", __func__);
692     int errCode = Connect();
693     if (errCode != ERR_OK) {
694         HILOG_ERROR("%{public}s failed errCode:%{public}d.", __func__, errCode);
695         return errCode;
696     }
697     return remoteProxy_->GetFormsInfoByModule(bundleName, moduleName, formInfos);
698 }
699 
700 /**
701  * @brief Update action string for router event.
702  * @param formId Indicates the unique id of form.
703  * @param action Indicates the origin action string.
704  * @return Returns ERR_OK on success, others on failure.
705  */
UpdateRouterAction(const int64_t formId,std::string & action)706 int FormMgr::UpdateRouterAction(const int64_t formId, std::string &action)
707 {
708     HILOG_INFO("%{public}s start.", __func__);
709     int errCode = Connect();
710     if (errCode != ERR_OK) {
711         HILOG_ERROR("%{public}s failed errCode:%{public}d.", __func__, errCode);
712         return errCode;
713     }
714     return remoteProxy_->UpdateRouterAction(formId, action);
715 }
716 }  // namespace AppExecFwk
717 }  // namespace OHOS
718