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_PROVIDER_MGR_H 17 #define OHOS_FORM_FWK_FORM_PROVIDER_MGR_H 18 #include <set> 19 #include <singleton.h> 20 #include "ability_connect_callback_interface.h" 21 #include "form_provider_info.h" 22 #include "form_record.h" 23 #include "form_state_info.h" 24 #include "want.h" 25 26 namespace OHOS { 27 namespace AppExecFwk { 28 using Want = OHOS::AAFwk::Want; 29 /** 30 * @class FormProviderMgr 31 * Form provider manager. 32 */ 33 class FormProviderMgr final : public DelayedRefSingleton<FormProviderMgr> { 34 DECLARE_DELAYED_REF_SINGLETON(FormProviderMgr) 35 public: 36 DISALLOW_COPY_AND_MOVE(FormProviderMgr); 37 38 /** 39 * @brief handle for acquire back event from provider. 40 * @param formId The id of the form. 41 * @param providerFormInfo provider form info. 42 * @return Returns ERR_OK on success, others on failure. 43 */ 44 ErrCode AcquireForm(const int64_t formId, const FormProviderInfo &formProviderInfo); 45 /** 46 * @brief handle for update form event from provider. 47 * @param formId The id of the form. 48 * @param providerFormInfo provider form info. 49 * @return Returns ERR_OK on success, others on failure. 50 */ 51 ErrCode UpdateForm(const int64_t formId, const FormProviderInfo &formProviderInfo); 52 /** 53 * handle for update form event from provider. 54 * 55 * @param formId The id of the form. 56 * @param formRecord The form's record. 57 * @param formProviderData provider form info. 58 * @return Returns ERR_OK on success, others on failure. 59 */ 60 ErrCode UpdateForm(const int64_t formId, FormRecord &formRecord, const FormProviderData &formProviderData); 61 /** 62 * @brief Refresh form. 63 * @param formId The form id. 64 * @param want The want of the form to request. 65 * @param isVisibleToFresh The form is visible to fresh. 66 * @return Returns ERR_OK on success, others on failure. 67 */ 68 ErrCode RefreshForm(const int64_t formId, const Want &want, bool isVisibleToFresh); 69 /** 70 * @brief Connect ams for refresh form 71 * @param formId The form id. 72 * @param record Form data. 73 * @param want The want of the form. 74 * @param isCountTimerRefresh The flag of timer refresh. 75 * @return Returns ERR_OK on success, others on failure. 76 */ 77 ErrCode ConnectAmsForRefresh(const int64_t formId, const FormRecord &record, const Want &want, 78 const bool isCountTimerRefresh); 79 /** 80 * @brief Notify provider form delete. 81 * @param formId The form id. 82 * @param record Form information. 83 * @return Returns ERR_OK on success, others on failure. 84 */ 85 ErrCode NotifyProviderFormDelete(const int64_t formId, const FormRecord &formRecord); 86 /** 87 * @brief Notify provider forms batch delete. 88 * @param bundleName BundleName. 89 * @param bundleName AbilityName. 90 * @param formIds form id list. 91 * @return Returns ERR_OK on success, others on failure. 92 */ 93 ErrCode NotifyProviderFormsBatchDelete(const std::string &bundleName, const std::string &abilityName, 94 const std::set<int64_t> &formIds); 95 /** 96 * @brief Acquire form state. 97 * @param state form state. 98 * @param provider provider info. 99 * @param wantArg The want of onAcquireFormState. 100 * @return Returns ERR_OK on success, others on failure. 101 */ 102 ErrCode AcquireFormStateBack(FormState state, const std::string& provider, const Want &wantArg); 103 /** 104 * @brief Process js message event. 105 * @param formId Indicates the unique id of form. 106 * @param record Form record. 107 * @param want information passed to supplier. 108 * @return Returns true if execute success, false otherwise. 109 */ 110 int MessageEvent(const int64_t formId, const FormRecord &record, const Want &want); 111 private: 112 bool IsNeedToFresh(FormRecord &record, int64_t formId, bool isVisibleToFresh); 113 114 FormRecord GetFormAbilityInfo(const FormRecord &record) const; 115 /** 116 * @brief Increase the timer refresh count. 117 * @param formId The form id. 118 */ 119 void IncreaseTimerRefreshCount(const int64_t formId); 120 bool IsFormCached(const FormRecord &record); 121 122 /** 123 * @brief Rebind form to provider by free install. 124 * @param want Indicates the want containing information about free install. 125 * @return Returns true if execute success, false otherwise. 126 */ 127 ErrCode RebindByFreeInstall(const FormRecord &record, Want &want, 128 const sptr<AAFwk::IAbilityConnection> formRefreshConnection); 129 }; 130 } // namespace AppExecFwk 131 } // namespace OHOS 132 133 #endif // OHOS_FORM_FWK_FORM_PROVIDER_MGR_H 134