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_TASK_MGR_H 17 #define OHOS_FORM_FWK_FORM_TASK_MGR_H 18 19 #include <singleton.h> 20 #include <vector> 21 22 #include "form_event_handler.h" 23 #include "form_js_info.h" 24 #include "form_record.h" 25 #include "form_serial_queue.h" 26 #include "form_state_info.h" 27 #include "iremote_object.h" 28 #include "running_form_info.h" 29 #include "want.h" 30 31 namespace OHOS { 32 namespace AppExecFwk { 33 using Want = OHOS::AAFwk::Want; 34 using WantParams = OHOS::AAFwk::WantParams; 35 /** 36 * @class FormTaskMgr 37 * form task manager. 38 */ 39 class FormTaskMgr final : public DelayedRefSingleton<FormTaskMgr> { 40 DECLARE_DELAYED_REF_SINGLETON(FormTaskMgr) 41 42 public: 43 DISALLOW_COPY_AND_MOVE(FormTaskMgr); 44 45 /** 46 * @brief SetSerialQueue. 47 * @param serialQueue serial queue 48 */ SetSerialQueue(const std::shared_ptr<FormSerialQueue> & serialQueue)49 inline void SetSerialQueue(const std::shared_ptr<FormSerialQueue> &serialQueue) 50 { 51 serialQueue_ = serialQueue; 52 } 53 54 /** 55 * @brief Acquire form data from form provider(task). 56 * @param formId The Id of the form. 57 * @param want The want of the request. 58 * @param remoteObject Form provider proxy object. 59 */ 60 void PostAcquireTask(const int64_t formId, const Want &want, const sptr<IRemoteObject> &remoteObject); 61 62 /** 63 * @brief Acquire share form data from form provider(task). 64 * @param formId The Id of the form. 65 * @param remoteDeviceId The device ID to share. 66 * @param want The want of the request. 67 * @param remoteObject Form provider proxy object. 68 */ 69 void PostShareAcquireTask(int64_t formId, const std::string &remoteDeviceId, const Want &want, 70 const sptr<IRemoteObject> &remoteObject); 71 72 /** 73 * @brief Delete form data from form provider(task). 74 * @param formId The Id of the form. 75 * @param want The want of the request. 76 * @param remoteObject Form provider proxy object. 77 */ 78 void PostDeleteTask(const int64_t formId, const Want &want, const sptr<IRemoteObject> &remoteObject); 79 /** 80 * @brief Notify provider batch delete. 81 * @param formIds The Id list. 82 * @param want The want of the request. 83 * @param remoteObject Form provider proxy object. 84 */ 85 void PostProviderBatchDeleteTask(std::set<int64_t> &formIds, const Want &want, 86 const sptr<IRemoteObject> &remoteObject); 87 /** 88 * @brief Refresh form data from form provider(task). 89 * 90 * @param formId The Id of the form. 91 * @param want The want of the form. 92 * @param remoteObject Form provider proxy object. 93 * @return none. 94 */ 95 void PostRefreshTask(const int64_t formId, const Want &want, const sptr<IRemoteObject> &remoteObject); 96 97 /** 98 * @brief Cast temp form data from form provider(task). 99 * 100 * @param formId The Id of the form. 101 * @param want The want of the request. 102 * @param remoteObject Form provider proxy object. 103 * @return none. 104 */ 105 void PostCastTempTask(const int64_t formId, const Want &want, const sptr<IRemoteObject> &remoteObject); 106 107 /** 108 * @brief Post form data to form host(task) when acquire form. 109 * @param formId The Id of the form. 110 * @param record form record. 111 * @param remoteObject Form provider proxy object. 112 */ 113 void PostAcquireTaskToHost(const int64_t formId, const FormRecord &record, const sptr<IRemoteObject> &remoteObject); 114 115 /** 116 * @brief Post form data to form host(task) when update form. 117 * @param formId The Id of the form. 118 * @param record form record. 119 * @param remoteObject Form provider proxy object. 120 */ 121 void PostUpdateTaskToHost(const int64_t formId, const FormRecord &record, const sptr<IRemoteObject> &remoteObject); 122 123 /** 124 * @brief Handel form host died(task). 125 * @param remoteHost Form host proxy object. 126 */ 127 void PostHostDiedTask(const sptr<IRemoteObject> &remoteHost); 128 129 /** 130 * @brief Post event notify to form provider. 131 * 132 * @param formEvent The vector of form ids. 133 * @param formVisibleType The form visible type, including FORM_VISIBLE and FORM_INVISIBLE. 134 * @param want The want of the form. 135 * @param remoteObject The form provider proxy object. 136 */ 137 void PostEventNotifyTask(const std::vector<int64_t> &formEvent, const int32_t formVisibleType, const Want &want, 138 const sptr<IRemoteObject> &remoteObject); 139 140 /** 141 * @brief Post message event to form provider. 142 * @param formId The Id of the from. 143 * @param message Event message. 144 * @param want The want of the request. 145 * @param remoteObject Form provider proxy object. 146 */ 147 void PostFormEventTask(const int64_t formId, const std::string &message, const Want &want, 148 const sptr<IRemoteObject> &remoteObject); 149 150 /** 151 * @brief Post acquire state to form provider. 152 * @param wantArg The want of onAcquireFormState. 153 * @param provider The provider info. 154 * @param want The want of the request. 155 * @param remoteObject Form provider proxy object. 156 */ 157 void PostAcquireStateTask(const Want &wantArg, const std::string &provider, const Want &want, 158 const sptr <IRemoteObject> &remoteObject); 159 160 /** 161 * @brief Post acquire data to form provider. 162 * @param formId The Id of the from. 163 * @param want The want of the request. 164 * @param remoteObject Form provider proxy object. 165 */ 166 void PostAcquireDataTask(const int64_t formId, const Want &want, const sptr<IRemoteObject> &remoteObject); 167 168 /** 169 * @brief Post uninstall message to form host(task). 170 * @param formIds The Id list of the forms. 171 * @param remoteObject Form provider proxy object. 172 */ 173 void PostUninstallTaskToHost(const std::vector<int64_t> &formIds, const sptr<IRemoteObject> &remoteObject); 174 175 /** 176 * @brief Post acquire form state message to form host(task). 177 * @param state The form state. 178 * @param want The want of onAcquireFormState. 179 * @param remoteObject Form provider proxy object. 180 */ 181 void PostAcquireStateTaskToHost(AppExecFwk::FormState state, const AAFwk::Want &want, 182 const sptr<IRemoteObject> &remoteObject); 183 184 /** 185 * @brief Post acquire form data message to form host(task). 186 * @param wantParams Indicates the data information acquired by the form. 187 * @param requestCode Indicates the requested id. 188 * @param remoteObject Form provider proxy object. 189 */ 190 void PostAcquireDataTaskToHost(const AAFwk::WantParams &wantParams, int64_t requestCode, 191 const sptr<IRemoteObject> &remoteObject); 192 193 /** 194 * @brief Post form share error code to form host(task). 195 * @param formShareRequestCode The request code for this share. 196 * @param result The error code of this share. 197 */ 198 void PostFormShareSendResponse(int64_t formShareRequestCode, int32_t result); 199 200 void PostRenderForm(const FormRecord &formRecord, const Want &want, const sptr<IRemoteObject> &remoteObject); 201 202 void PostStopRenderingForm(const FormRecord &formRecord, const Want &want, const sptr<IRemoteObject> &remoteObject); 203 204 void PostReloadForm(const std::vector<FormRecord> &&formRecords, const Want &want, 205 const sptr<IRemoteObject> &remoteObject); 206 207 void PostAddTaskToHost(const std::string bundleName, const sptr<IRemoteObject> &remoteObject, 208 const RunningFormInfo &runningFormInfo); 209 210 void PostRemoveTaskToHost(const std::string bundleName, const sptr<IRemoteObject> &remoteObject, 211 const RunningFormInfo &runningFormInfo); 212 213 void PostReleaseRenderer( 214 int64_t formId, const std::string &compId, const std::string &uid, const sptr<IRemoteObject> &remoteObject); 215 216 void PostOnUnlock(const sptr<IRemoteObject> &remoteObject); 217 218 private: 219 /** 220 * @brief Acquire form data from form provider. 221 * @param formId The Id of the from. 222 * @param want The want of the request. 223 * @param remoteObject Form provider proxy object. 224 */ 225 void AcquireProviderFormInfo(const int64_t formId, const Want &want, const sptr<IRemoteObject> &remoteObject); 226 227 /** 228 * @brief Acquire share form data from form provider(task). 229 * @param formId The Id of the form. 230 * @param remoteDeviceId The device ID to share. 231 * @param want The want of the request. 232 * @param remoteObject Form provider proxy object. 233 */ 234 void AcquireShareFormData(int64_t formId, const std::string &remoteDeviceId, const Want &want, 235 const sptr<IRemoteObject> &remoteObject); 236 237 /** 238 * @brief Notify form provider for delete form. 239 * @param formId The Id of the from. 240 * @param want The want of the form. 241 * @param remoteObject Form provider proxy object. 242 */ 243 void NotifyFormDelete(const int64_t formId, const Want &want, const sptr<IRemoteObject> &remoteObject); 244 245 /** 246 * @brief Notify form provider for updating form. 247 * @param formId The Id of the from. 248 * @param want The want of the form. 249 * @param remoteObject Form provider proxy object. 250 */ 251 void NotifyFormUpdate(const int64_t formId, const Want &want, const sptr<IRemoteObject> &remoteObject); 252 253 /** 254 * @brief Event notify to form provider. 255 * 256 * @param formEvents The vector of form ids. 257 * @param formVisibleType The form visible type, including FORM_VISIBLE and FORM_INVISIBLE. 258 * @param want The want of the form. 259 * @param remoteObject The form provider proxy object. 260 */ 261 void EventNotify(const std::vector<int64_t> &formEvents, const int32_t formVisibleType, const Want &want, 262 const sptr<IRemoteObject> &remoteObject); 263 264 /** 265 * @brief Notify form provider for cast temp form. 266 * 267 * @param formId The Id of the from. 268 * @param want The want of the form. 269 * @param remoteObject Form provider proxy object. 270 * @return none. 271 */ 272 void NotifyCastTemp(const int64_t formId, const Want &want, const sptr<IRemoteObject> &remoteObject); 273 /** 274 * @brief Post form data to form host when acquire form.. 275 * @param formId The Id of the form. 276 * @param record form record. 277 * @param remoteObject Form provider proxy object. 278 */ 279 void AcquireTaskToHost(const int64_t formId, const FormRecord &record, const sptr<IRemoteObject> &remoteObject); 280 281 /** 282 * @brief Post form data to form host when update form. 283 * @param formId The Id of the form. 284 * @param record form record. 285 * @param remoteObject Form provider proxy object. 286 */ 287 void UpdateTaskToHost(const int64_t formId, const FormRecord &record, const sptr<IRemoteObject> &remoteObject); 288 289 /** 290 * @brief Handle form host died. 291 * @param remoteHost Form host proxy object. 292 */ 293 void HostDied(const sptr<IRemoteObject> &remoteHost); 294 295 /** 296 * @brief Post provider batch delete. 297 * @param formIds The Id list. 298 * @param want The want of the request. 299 * @param remoteObject Form provider proxy object. 300 */ 301 void ProviderBatchDelete(std::set<int64_t> &formIds, const Want &want, const sptr<IRemoteObject> &remoteObject); 302 /** 303 * @brief Fire message event to form provider. 304 * @param formId The Id of the from. 305 * @param message Event message. 306 * @param want The want of the request. 307 * @param remoteObject Form provider proxy object. 308 */ 309 void FireFormEvent(const int64_t formId, const std::string &message, const Want &want, 310 const sptr<IRemoteObject> &remoteObject); 311 312 /** 313 * @brief Acquire form state to form provider. 314 * @param wantArg The want of onAcquireFormState. 315 * @param provider The provider info. 316 * @param want The want of the request. 317 * @param remoteObject Form provider proxy object. 318 */ 319 void AcquireState(const Want &wantArg, const std::string &provider, const Want &want, 320 const sptr <IRemoteObject> &remoteObject); 321 /** 322 * @brief Handle acquire data. 323 * @param wantParams Indicates the data information acquired by the form. 324 * @param requestCode Indicates the requested id. 325 * @param remoteObject Form provider proxy object. 326 */ 327 void AcquireFormDataBack(const AAFwk::WantParams &wantParams, int64_t requestCode, 328 const sptr<IRemoteObject> &remoteObject); 329 330 /** 331 * @brief Acquire form data to form provider. 332 * @param formId The Id of the form. 333 * @param want The want of the request. 334 * @param remoteObject Form provider proxy object. 335 */ 336 void AcquireFormData(const int64_t formId, const Want &want, const sptr<IRemoteObject> &remoteObject); 337 338 /** 339 * @brief Handle uninstall message. 340 * @param formIds The Id list of the forms. 341 * @param remoteObject Form provider proxy object. 342 */ 343 void FormUninstall(const std::vector<int64_t> &formIds, const sptr<IRemoteObject> &remoteObject); 344 345 /** 346 * @brief Handle acquire state. 347 * @param state the form state. 348 * @param want The want of onAcquireFormState. 349 * @param remoteObject Form provider proxy object. 350 */ 351 void AcquireStateBack(AppExecFwk::FormState state, const AAFwk::Want &want, 352 const sptr <IRemoteObject> &remoteObject); 353 354 /** 355 * @brief Create form data for form host. 356 * @param formId The Id of the form. 357 * @param record Form record. 358 * @return Form data. 359 */ 360 FormJsInfo CreateFormJsInfo(const int64_t formId, const FormRecord &record); 361 362 /** 363 * @brief Post form share error code to form host(task). 364 * @param formShareRequestCode The request code for this share. 365 * @param result The error code of this share. 366 */ 367 void FormShareSendResponse(int64_t formShareRequestCode, int32_t result); 368 369 /** 370 * @brief Post form share error code to form host(task). 371 * @param formShareRequestCode The request code for this share. 372 * @param result The error code of this share. 373 */ 374 void RenderForm(const FormRecord &formRecord, const Want &want, const sptr<IRemoteObject> &remoteObject); 375 376 void StopRenderingForm(const FormRecord &formRecord, const Want &want, const sptr<IRemoteObject> &remoteObject); 377 378 void ReloadForm(const std::vector<FormRecord> &&formRecords, const Want &want, 379 const sptr<IRemoteObject> &remoteObject); 380 381 void FormAdd(const std::string bundleName, const sptr<IRemoteObject> &remoteObject, 382 const RunningFormInfo &runningFormInfo); 383 384 void FormRemove(const std::string bundleName, const sptr<IRemoteObject> &remoteObject, 385 const RunningFormInfo &runningFormInfo); 386 387 void ReleaseRenderer( 388 int64_t formId, const std::string &compId, const std::string &uid, const sptr<IRemoteObject> &remoteObject); 389 390 void OnUnlock(const sptr<IRemoteObject> &remoteObject); 391 private: 392 std::shared_ptr<FormSerialQueue> serialQueue_ = nullptr; 393 }; 394 } // namespace AppExecFwk 395 } // namespace OHOS 396 #endif // OHOS_FORM_FWK_FORM_TASK_MGR_H 397