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 #ifndef FOUNDATION_APPEXECFWK_SERVICES_FORMMGR_INCLUDE_FORM_TASK_MGR_H 17 #define FOUNDATION_APPEXECFWK_SERVICES_FORMMGR_INCLUDE_FORM_TASK_MGR_H 18 19 #include <singleton.h> 20 #include <vector> 21 22 #include "event_handler.h" 23 #include "form_item_info.h" 24 #include "form_js_info.h" 25 #include "form_provider_info.h" 26 #include "form_record.h" 27 #include "ipc_types.h" 28 #include "iremote_object.h" 29 #include "form_record.h" 30 #include "want.h" 31 32 namespace OHOS { 33 namespace AppExecFwk { 34 using Want = OHOS::AAFwk::Want; 35 using WantParams = OHOS::AAFwk::WantParams; 36 /** 37 * @class FormTaskMgr 38 * form task manager. 39 */ 40 class FormTaskMgr final : public DelayedRefSingleton<FormTaskMgr> { 41 DECLARE_DELAYED_REF_SINGLETON(FormTaskMgr) 42 43 public: 44 DISALLOW_COPY_AND_MOVE(FormTaskMgr); 45 46 /** 47 * @brief SetEventHandler. 48 * @param handler event handler 49 */ SetEventHandler(const std::shared_ptr<AppExecFwk::EventHandler> & handler)50 inline void SetEventHandler(const std::shared_ptr<AppExecFwk::EventHandler> &handler) 51 { 52 eventHandler_ = handler; 53 } 54 55 /** 56 * @brief Acquire form data from form provider(task). 57 * @param formId The Id of the form. 58 * @param want The want of the request. 59 * @param remoteObject Form provider proxy object. 60 */ 61 void PostAcquireTask(const int64_t formId, const Want &want, const sptr<IRemoteObject> &remoteObject); 62 63 /** 64 * @brief Delete form data from form provider(task). 65 * @param formId The Id of the form. 66 * @param want The want of the request. 67 * @param remoteObject Form provider proxy object. 68 */ 69 void PostDeleteTask(const int64_t formId, const Want &want, const sptr<IRemoteObject> &remoteObject); 70 /** 71 * @brief Notify provider batch delete. 72 * @param formIds The Id list. 73 * @param want The want of the request. 74 * @param remoteObject Form provider proxy object. 75 */ 76 void PostProviderBatchDeleteTask(std::set<int64_t> &formIds, const Want &want, 77 const sptr<IRemoteObject> &remoteObject); 78 /** 79 * @brief Refresh form data from form provider(task). 80 * 81 * @param formId The Id of the form. 82 * @param want The want of the form. 83 * @param remoteObject Form provider proxy object. 84 * @return none. 85 */ 86 void PostRefreshTask(const int64_t formId, const Want &want, const sptr<IRemoteObject> &remoteObject); 87 88 /** 89 * @brief Cast temp form data from form provider(task). 90 * 91 * @param formId The Id of the form. 92 * @param want The want of the request. 93 * @param remoteObject Form provider proxy object. 94 * @return none. 95 */ 96 void PostCastTempTask(const int64_t formId, const Want &want, const sptr<IRemoteObject> &remoteObject); 97 98 /** 99 * @brief Post form data to form host(task) when acquire form. 100 * @param formId The Id of the form. 101 * @param callingUid Calling uid. 102 * @param info Form configure info. 103 * @param wantParams WantParams of the request. 104 * @param remoteObject Form provider proxy object. 105 */ 106 107 void PostAcquireTaskToHost(const int64_t formId, const FormRecord &record, const sptr<IRemoteObject> &remoteObject); 108 109 /** 110 * @brief Post form data to form host(task) when update form. 111 * @param formId The Id of the form. 112 * @param callingUid Calling uid. 113 * @param info Form configure info. 114 * @param wantParams WantParams of the request. 115 * @param remoteObject Form provider proxy object. 116 */ 117 void PostUpdateTaskToHost(const int64_t formId, const FormRecord &record, const sptr<IRemoteObject> &remoteObject); 118 119 /** 120 * @brief Handel form host died(task). 121 * @param remoteHost Form host proxy object. 122 */ 123 void PostHostDiedTask(const sptr<IRemoteObject> &remoteHost); 124 125 /** 126 * @brief Post event notify to form provider. 127 * 128 * @param formEvent The vector of form ids. 129 * @param formVisibleType The form visible type, including FORM_VISIBLE and FORM_INVISIBLE. 130 * @param want The want of the form. 131 * @param remoteObject The form provider proxy object. 132 * @return none. 133 */ 134 void PostEventNotifyTask(const std::vector<int64_t> &formEvent, const int32_t formVisibleType, const Want &want, 135 const sptr<IRemoteObject> &remoteObject); 136 137 /** 138 * @brief Post message event to form provider. 139 * @param formId The Id of the from. 140 * @param message Event message. 141 * @param want The want of the request. 142 * @param remoteObject Form provider proxy object. 143 */ 144 void PostFormEventTask(const int64_t formId, const std::string &message, const Want &want, 145 const sptr<IRemoteObject> &remoteObject); 146 147 /** 148 * @brief Post uninstall message to form host(task). 149 * @param formIds The Id list of the forms. 150 * @param remoteObject Form provider proxy object. 151 */ 152 void PostUninstallTaskToHost(const std::vector<int64_t> &formIds, const sptr<IRemoteObject> &remoteObject); 153 private: 154 /** 155 * @brief Acquire form data from form provider. 156 * @param formId The Id of the from. 157 * @param want The want of the request. 158 * @param remoteObject Form provider proxy object. 159 */ 160 void AcquireProviderFormInfo(const int64_t formId, const Want &want, const sptr<IRemoteObject> &remoteObject); 161 162 /** 163 * @brief Notify form provider for delete form. 164 * @param formId The Id of the from. 165 * @param want The want of the form. 166 * @param remoteObject Form provider proxy object. 167 * @return none. 168 */ 169 void NotifyFormDelete(const int64_t formId, const Want &want, const sptr<IRemoteObject> &remoteObject); 170 171 /** 172 * @brief Notify form provider for updating form. 173 * @param formId The Id of the from. 174 * @param want The want of the form. 175 * @param remoteObject Form provider proxy object. 176 * @return none. 177 */ 178 void NotifyFormUpdate(const int64_t formId, const Want &want, const sptr<IRemoteObject> &remoteObject); 179 180 /** 181 * @brief Event notify to form provider. 182 * 183 * @param formEvents The vector of form ids. 184 * @param formVisibleType The form visible type, including FORM_VISIBLE and FORM_INVISIBLE. 185 * @param want The want of the form. 186 * @param remoteObject The form provider proxy object. 187 * @return none. 188 */ 189 void EventNotify(const std::vector<int64_t> &formEvents, const int32_t formVisibleType, const Want &want, 190 const sptr<IRemoteObject> &remoteObject); 191 192 /** 193 * @brief Notify form provider for cast temp form. 194 * 195 * @param formId The Id of the from. 196 * @param want The want of the form. 197 * @param remoteObject Form provider proxy object. 198 * @return none. 199 */ 200 void NotifyCastTemp(const int64_t formId, const Want &want, const sptr<IRemoteObject> &remoteObject); 201 /** 202 * @brief Post form data to form host when acquire form.. 203 * @param formId The Id of the form. 204 * @param callingUid Calling uid. 205 * @param info Form configure info. 206 * @param wantParams WantParams of the request. 207 * @param remoteObject Form provider proxy object. 208 */ 209 void AcquireTaskToHost(const int64_t formId, const FormRecord &record, const sptr<IRemoteObject> &remoteObject); 210 211 /** 212 * @brief Post form data to form host when update form. 213 * @param formId The Id of the form. 214 * @param callingUid Calling uid. 215 * @param info Form configure info. 216 * @param wantParams WantParams of the request. 217 * @param remoteObject Form provider proxy object. 218 */ 219 void UpdateTaskToHost(const int64_t formId, const FormRecord &record, const sptr<IRemoteObject> &remoteObject); 220 221 /** 222 * @brief Handle form host died. 223 * @param remoteHost Form host proxy object. 224 */ 225 void HostDied(const sptr<IRemoteObject> &remoteHost); 226 227 /** 228 * @brief Post provider batch delete. 229 * @param formIds The Id list. 230 * @param want The want of the request. 231 * @param remoteObject Form provider proxy object. 232 */ 233 void ProviderBatchDelete(std::set<int64_t> &formIds, const Want &want, const sptr<IRemoteObject> &remoteObject); 234 /** 235 * @brief Fire message event to form provider. 236 * @param formId The Id of the from. 237 * @param message Event message. 238 * @param want The want of the request. 239 * @param remoteObject Form provider proxy object. 240 */ 241 void FireFormEvent(const int64_t formId, const std::string &message, const Want &want, 242 const sptr<IRemoteObject> &remoteObject); 243 244 /** 245 * @brief Handle uninstall message. 246 * @param formIds The Id list of the forms. 247 * @param remoteObject Form provider proxy object. 248 */ 249 void FormUninstall(const std::vector<int64_t> &formIds, const sptr<IRemoteObject> &remoteObject); 250 251 /** 252 * @brief Create form data for form host. 253 * @param formId The Id of the form. 254 * @param record Form record. 255 * @return Form data. 256 */ 257 FormJsInfo CreateFormJsInfo(const int64_t formId, const FormRecord &record); 258 259 private: 260 std::shared_ptr<AppExecFwk::EventHandler> eventHandler_ = nullptr; 261 }; 262 } // namespace AppExecFwk 263 } // namespace OHOS 264 #endif // FOUNDATION_APPEXECFWK_SERVICES_FORMMGR_INCLUDE_FORM_TASK_MGR_H 265