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_ADAPTER_H 17 #define OHOS_FORM_FWK_FORM_MGR_ADAPTER_H 18 19 #include <singleton.h> 20 21 #include "bundle_info.h" 22 #include "bundle_mgr_interface.h" 23 #include "form_constants.h" 24 #include "form_info.h" 25 #include "form_instance.h" 26 #include "form_instances_filter.h" 27 #include "form_item_info.h" 28 #include "form_js_info.h" 29 #include "form_provider_data.h" 30 #include "form_publish_interceptor_interface.h" 31 #include "form_state_info.h" 32 #include "form_task_mgr.h" 33 #include "iremote_object.h" 34 #include "running_form_info.h" 35 #include "want.h" 36 37 namespace OHOS { 38 namespace AppExecFwk { 39 using Want = OHOS::AAFwk::Want; 40 using WantParams = OHOS::AAFwk::WantParams; 41 /** 42 * @class FormMgrAdapter 43 * Form request handler from form host. 44 */ 45 class FormMgrAdapter final : public DelayedRefSingleton<FormMgrAdapter> { 46 DECLARE_DELAYED_REF_SINGLETON(FormMgrAdapter) 47 public: 48 DISALLOW_COPY_AND_MOVE(FormMgrAdapter); 49 50 /** 51 * @brief Init properties like visibleNotifyDelayTime. 52 */ 53 void Init(); 54 55 /** 56 * @brief Add form with want, send want to form manager service. 57 * @param formId The Id of the forms to add. 58 * @param want The want of the form to add. 59 * @param callerToken Caller ability token. 60 * @param formInfo Form info. 61 * @return Returns ERR_OK on success, others on failure. 62 */ 63 int AddForm(const int64_t formId, const Want &want, const sptr<IRemoteObject> &callerToken, FormJsInfo &formInfo); 64 65 /** 66 * @brief Delete forms with formIds, send formIds to form manager service. 67 * @param formId The Id of the forms to delete. 68 * @param callerToken Caller ability token. 69 * @return Returns ERR_OK on success, others on failure. 70 */ 71 int DeleteForm(const int64_t formId, const sptr<IRemoteObject> &callerToken); 72 73 /** 74 * @brief Stop rendering form. 75 * @param formId The Id of the forms to delete. 76 * @param compId The compId of the forms to delete. 77 * @return Returns ERR_OK on success, others on failure. 78 */ 79 int StopRenderingForm(const int64_t formId, const std::string &compId); 80 81 /** 82 * @brief Release forms with formIds, send formIds to form Mgr service. 83 * @param formId The Id of the forms to release. 84 * @param callerToken Caller ability token. 85 * @param delCache Delete Cache or not. 86 * @return Returns ERR_OK on success, others on failure. 87 */ 88 int ReleaseForm(const int64_t formId, const sptr<IRemoteObject> &callerToken, const bool delCache); 89 90 /** 91 * @brief Update form with formId. 92 * @param formId The Id of the form to update. 93 * @param callingUid Provider ability uid. 94 * @param formProviderData form provider data. 95 * @param std::vector<FormDataProxy> Form proxy vector. 96 * @return Returns ERR_OK on success, others on failure. 97 */ 98 int UpdateForm(const int64_t formId, const int32_t callingUid, const FormProviderData &formProviderData, 99 const std::vector<FormDataProxy> &formDataProxies = {}); 100 101 /** 102 * @brief Request form with formId and want, send formId and want to form manager service. 103 * 104 * @param formId The Id of the form to update. 105 * @param callerToken Caller ability token. 106 * @param want The want of the form to request. 107 * @return Returns ERR_OK on success, others on failure. 108 */ 109 int RequestForm(const int64_t formId, const sptr<IRemoteObject> &callerToken, const Want &want); 110 111 /** 112 * @brief Form visible/invisible notify, send formIds to form manager service. 113 * 114 * @param formIds The vector of form Ids. 115 * @param callerToken Caller ability token. 116 * @param formVisibleType The form visible type, including FORM_VISIBLE and FORM_INVISIBLE. 117 * @return Returns ERR_OK on success, others on failure. 118 */ 119 ErrCode NotifyWhetherVisibleForms(const std::vector<int64_t> &formIds, const sptr<IRemoteObject> &callerToken, 120 const int32_t formVisibleType); 121 122 /** 123 * @brief Padding the formInstances map for visibleNotify. 124 * @param formVisibleType The form visible type, including FORM_VISIBLE and FORM_INVISIBLE. 125 * @param formId Form Id. 126 * @param formInstanceMaps formInstances for visibleNotify. 127 */ 128 void PaddingNotifyVisibleFormsMap(const int32_t formVisibleType, int64_t formId, 129 std::map<std::string, std::vector<FormInstance>> &formInstanceMaps); 130 131 /** 132 * @brief temp form to normal form. 133 * @param formId The Id of the form. 134 * @param callerToken Caller ability token. 135 * @return Returns ERR_OK on success, others on failure. 136 */ 137 int CastTempForm(const int64_t formId, const sptr<IRemoteObject> &callerToken); 138 139 /** 140 * @brief Dump all of form storage infos. 141 * @param formInfos All of form storage infos. 142 * @return Returns ERR_OK on success, others on failure. 143 */ 144 int DumpStorageFormInfos(std::string &formInfos) const; 145 /** 146 * @brief Dump all of temporary form infos. 147 * @param formInfos All of temporary form infos. 148 * @return Returns ERR_OK on success, others on failure. 149 */ 150 int DumpTemporaryFormInfos(std::string &formInfos) const; 151 /** 152 * @brief Dump form infos of all bundles, this is static info. 153 * @param formInfos All of static form infos. 154 * @return Returns ERR_OK on success, others on failure. 155 */ 156 int DumpStaticBundleFormInfos(std::string &formInfos) const; 157 /** 158 * @brief Dump form info by a bundle name. 159 * @param bundleName The bundle name of form provider. 160 * @param formInfos Form infos. 161 * @return Returns ERR_OK on success, others on failure. 162 */ 163 int DumpFormInfoByBundleName(const std::string &bundleName, std::string &formInfos) const; 164 /** 165 * @brief Dump form info by a bundle name. 166 * @param formId The id of the form. 167 * @param formInfo Form info. 168 * @return Returns ERR_OK on success, others on failure. 169 */ 170 int DumpFormInfoByFormId(const std::int64_t formId, std::string &formInfo) const; 171 /** 172 * @brief Dump form timer by form id. 173 * @param formId The id of the form. 174 * @param isTimingService "true" or "false". 175 * @return Returns ERR_OK on success, others on failure. 176 */ 177 int DumpFormTimerByFormId(const std::int64_t formId, std::string &isTimingService) const; 178 179 /** 180 * @brief set next refresh time. 181 * @param formId The id of the form. 182 * @param nextTime next refresh time. 183 * @return Returns ERR_OK on success, others on failure. 184 */ 185 int SetNextRefreshTime(const int64_t formId, const int64_t nextTime); 186 187 /** 188 * @brief Release renderer. 189 * @param formId The Id of the forms to release. 190 * @param compId The compId of the forms to release. 191 * @return Returns ERR_OK on success, others on failure. 192 */ 193 int ReleaseRenderer(int64_t formId, const std::string &compId); 194 195 /** 196 * @brief Request to publish a form to the form host. 197 * 198 * @param want The want of the form to publish. 199 * @param withFormBindingData Indicates whether the formBindingData is carried with. 200 * @param formBindingData Indicates the form data. 201 * @param formId Return the form id to be published. 202 * @return Returns ERR_OK on success, others on failure. 203 */ 204 ErrCode RequestPublishForm(Want &want, bool withFormBindingData, 205 std::unique_ptr<FormProviderData> &formBindingData, int64_t &formId, 206 const std::vector<FormDataProxy> &formDataProxies = {}); 207 208 /** 209 * @brief Check if the request of publishing a form is supported by the host. 210 * @return Returns true if the request is supported and false otherwise. 211 */ 212 bool IsRequestPublishFormSupported(); 213 214 /** 215 * @brief enable update form. 216 * @param formIDs The id of the forms. 217 * @param callerToken Caller ability token. 218 * @return Returns ERR_OK on success, others on failure. 219 */ 220 int EnableUpdateForm(const std::vector<int64_t> formIDs, const sptr<IRemoteObject> &callerToken); 221 222 /** 223 * @brief disable update form. 224 * @param formIDs The id of the forms. 225 * @param callerToken Caller ability token. 226 * @return Returns ERR_OK on success, others on failure. 227 */ 228 int DisableUpdateForm(const std::vector<int64_t> formIDs, const sptr<IRemoteObject> &callerToken); 229 230 /** 231 * @brief Process js message event. 232 * @param formId Indicates the unique id of form. 233 * @param want information passed to supplier. 234 * @param callerToken Caller ability token. 235 * @return Returns true if execute success, false otherwise. 236 */ 237 int MessageEvent(const int64_t formId, const Want &want, const sptr<IRemoteObject> &callerToken); 238 239 /** 240 * @brief Process js router event. 241 * @param formId Indicates the unique id of form. 242 * @param want the want of the ability to start. 243 * @param callerToken Caller ability token. 244 * @return Returns true if execute success, false otherwise. 245 */ 246 int RouterEvent(const int64_t formId, Want &want, const sptr<IRemoteObject> &callerToken); 247 248 /** 249 * @brief Process background router event. 250 * @param formId Indicates the unique id of form. 251 * @param want the want of the ability to start. 252 * @param callerToken Caller ability token. 253 * @return Returns true if execute success, false otherwise. 254 */ 255 int BackgroundEvent(const int64_t formId, Want &want, const sptr<IRemoteObject> &callerToken); 256 257 /** 258 * @brief Acquire form data from form provider. 259 * @param formId The Id of the from. 260 * @param want The want of the request. 261 * @param remoteObject Form provider proxy object. 262 */ 263 void AcquireProviderFormInfo(const int64_t formId, const Want &want, const sptr<IRemoteObject> &remoteObject); 264 /** 265 * @brief Notify form provider for delete form. 266 * @param formId The Id of the from. 267 * @param want The want of the form. 268 * @param remoteObject Form provider proxy object. 269 * @return none. 270 */ 271 void NotifyFormDelete(const int64_t formId, const Want &want, const sptr<IRemoteObject> &remoteObject); 272 273 /** 274 * @brief Delete the invalid forms. 275 * @param formIds Indicates the ID of the valid forms. 276 * @param callerToken Caller ability token. 277 * @param numFormsDeleted Returns the number of the deleted forms. 278 * @return Returns ERR_OK on success, others on failure. 279 */ 280 int DeleteInvalidForms(const std::vector<int64_t> &formIds, const sptr<IRemoteObject> &callerToken, 281 int32_t &numFormsDeleted); 282 283 /** 284 * @brief Acquire form state info by passing a set of parameters (using Want) to the form provider. 285 * @param want Indicates a set of parameters to be transparently passed to the form provider. 286 * @param callerToken Caller ability token. 287 * @param stateInfo Returns the form's state info of the specify. 288 * @return Returns ERR_OK on success, others on failure. 289 */ 290 int AcquireFormState(const Want &want, const sptr<IRemoteObject> &callerToken, FormStateInfo &stateInfo); 291 292 /** 293 * @brief Acquire form data by formId. 294 * @param formId The Id of the form to acquire data. 295 * @param callerToken Indicates the host client. 296 * @param requestCode The request code of this acquire form. 297 * @param formData Return the forms' information of customization 298 * @return Returns ERR_OK on success, others on failure. 299 */ 300 int AcquireFormData(int64_t formId, int64_t requestCode, const sptr<IRemoteObject> &callerToken, 301 AAFwk::WantParams &formData); 302 303 /** 304 * @brief Notify the form is visible or not. 305 * @param formIds Indicates the ID of the forms. 306 * @param isVisible Visible or not. 307 * @param callerToken Host client. 308 * @return Returns ERR_OK on success, others on failure. 309 */ 310 int NotifyFormsVisible(const std::vector<int64_t> &formIds, bool isVisible, const sptr<IRemoteObject> &callerToken); 311 312 /** 313 * @brief Notify the form is enable to be updated or not. 314 * @param formIds Indicates the ID of the forms. 315 * @param isEnableUpdate enable update or not. 316 * @param callerToken Host client. 317 * @return Returns ERR_OK on success, others on failure. 318 */ 319 int NotifyFormsEnableUpdate(const std::vector<int64_t> &formIds, bool isEnableUpdate, 320 const sptr<IRemoteObject> &callerToken); 321 322 /** 323 * @brief Get All FormsInfo. 324 * @param formInfos Return the forms' information of all forms provided. 325 * @return Returns ERR_OK on success, others on failure. 326 */ 327 int GetAllFormsInfo(std::vector<FormInfo> &formInfos); 328 329 /** 330 * @brief Get forms info by bundle name . 331 * @param bundleName Application name. 332 * @param formInfos Return the forms' information of the specify application name. 333 * @return Returns ERR_OK on success, others on failure. 334 */ 335 int GetFormsInfoByApp(const std::string &bundleName, std::vector<FormInfo> &formInfos); 336 337 /** 338 * @brief Get forms info by bundle name and module name. 339 * @param bundleName bundle name. 340 * @param moduleName Module name of hap. 341 * @param formInfos Return the forms' information of the specify bundle name and module name. 342 * @return Returns ERR_OK on success, others on failure. 343 */ 344 int GetFormsInfoByModule(const std::string &bundleName, const std::string &moduleName, 345 std::vector<FormInfo> &formInfos); 346 347 /** 348 * @brief get forms count. 349 * @param isTempFormFlag Indicates temp form or not. 350 * @param formCount Returns the number of the cast or temp form. 351 * @return Returns ERR_OK on success, others on failure. 352 */ 353 int32_t GetFormsCount(bool isTempFormFlag, int32_t &formCount); 354 355 /** 356 * @brief get host forms count. 357 * @param bundleName Indicates form host bundleName. 358 * @param formCount Returns the number of the host form. 359 * @return Returns ERR_OK on success, others on failure. 360 */ 361 int32_t GetHostFormsCount(std::string &bundleName, int32_t &formCount); 362 363 /** 364 * @brief Handle form add observer. 365 * @return Returns ERR_OK on success, others on failure. 366 */ 367 ErrCode HandleFormAddObserver(const int64_t formId); 368 369 /** 370 * @brief Handle form add observer. 371 * @param runningFormInfo the running forms' infos of the specify application name. 372 * @return Returns ERR_OK on success, others on failure. 373 */ 374 ErrCode HandleFormRemoveObserver(const RunningFormInfo runningFormInfo); 375 376 /** 377 * @brief Register form add observer by bundle. 378 * @param bundleName BundleName of the form host 379 * @param callerToken Caller ability token. 380 * @return Returns ERR_OK on success, others on failure. 381 */ 382 ErrCode RegisterFormAddObserverByBundle(const std::string bundleName, const sptr<IRemoteObject> &callerToken); 383 384 /** 385 * @brief Register form remove observer by bundle. 386 * @param bundleName BundleName of the form host 387 * @param callerToken Caller ability token. 388 * @return Returns ERR_OK on success, others on failure. 389 */ 390 ErrCode RegisterFormRemoveObserverByBundle(const std::string bundleName, const sptr<IRemoteObject> &callerToken); 391 392 /** 393 * @brief Get all running form infos. 394 * @param isUnusedIncluded Indicates whether to include unused forms. 395 * @param runningFormInfos Return the running forms' infos currently. 396 * @return Returns ERR_OK on success, others on failure. 397 */ 398 ErrCode GetRunningFormInfos(bool isUnusedIncluded, std::vector<RunningFormInfo> &runningFormInfos); 399 400 /** 401 * @brief Get the running form infos by bundle name. 402 * @param bundleName Application name. 403 * @param isUnusedIncluded Indicates whether to include unused forms. 404 * @param runningFormInfos Return the running forms' infos of the specify application name. 405 * @return Returns ERR_OK on success, others on failure. 406 */ 407 ErrCode GetRunningFormInfosByBundleName( 408 const std::string &bundleName, bool isUnusedIncluded, std::vector<RunningFormInfo> &runningFormInfos); 409 410 /** 411 * @brief Get form instances by filter info. 412 * @param formInstancesFilter includes bundleName, moduleName, formName, abilityName to get formInstances. 413 * @param formInstances return formInstances 414 * @return return ERR_OK on get info success, others on failure. 415 */ 416 ErrCode GetFormInstancesByFilter(const FormInstancesFilter &formInstancesFilter, 417 std::vector<FormInstance> &formInstances); 418 419 /** 420 * @brief Get form instance by formId. 421 * @param formId formId Indicates the unique id of form. 422 * @param formInstance return formInstance 423 * @return return ERR_OK on get info success, others on failure. 424 */ 425 ErrCode GetFormInstanceById(const int64_t formId, FormInstance &formInstance); 426 427 /** 428 * @brief Get form instance by formId, include form store in DB. 429 * @param formId formId Indicates the unique id of form. 430 * @param isUnusedIncluded Indicates whether to include unused form. 431 * @param formInstance return formInstance 432 * @return return ERR_OK on get info success, others on failure. 433 */ 434 ErrCode GetFormInstanceById(const int64_t formId, bool isUnusedIncluded, FormInstance &formInstance); 435 436 /** 437 * @brief Register form add observer. 438 * @param bundleName BundleName of the form host 439 * @param callerToken Caller ability token. 440 * @return Returns ERR_OK on success, others on failure. 441 */ 442 ErrCode RegisterAddObserver(const std::string &bundleName, const sptr<IRemoteObject> &callerToken); 443 444 /** 445 * @brief Register form remove observer. 446 * @param bundleName BundleName of the form host 447 * @param callerToken Caller ability token. 448 * @return Returns ERR_OK on success, others on failure. 449 */ 450 ErrCode RegisterRemoveObserver(const std::string &bundleName, const sptr<IRemoteObject> &callerToken); 451 452 /** 453 * @brief Register form router event proxy. 454 * @param formIds Indicates the ID of the forms. 455 * @param callerToken Router proxy call back client. 456 * @return Returns ERR_OK on success, others on failure. 457 */ 458 ErrCode RegisterFormRouterProxy(const std::vector<int64_t> &formIds, const sptr<IRemoteObject> &callerToken); 459 460 /** 461 * @brief Unregister form router event proxy. 462 * @param formIds Indicates the ID of the forms. 463 * @return Returns ERR_OK on success, others on failure. 464 */ 465 ErrCode UnregisterFormRouterProxy(const std::vector<int64_t> &formIds); 466 467 /** 468 * @brief Registers the callback for publish form. The callback is used to process the publish form request 469 * when the system handler is not found. 470 * @param interceptorCallback The injected callback, should implementation IFormPublishInterceptor. 471 * @return Returns ERR_OK on success, others on failure. 472 */ 473 int32_t RegisterPublishFormInterceptor(const sptr<IRemoteObject> &interceptorCallback); 474 475 /** 476 * @brief Unregisters the callback for publish form. The callback is used to process the publish form request 477 * when the system handler is not found. 478 * @param interceptorCallback The injected callback, should implementation IFormPublishInterceptor. 479 * @return Returns ERR_OK on success, others on failure. 480 */ 481 int32_t UnregisterPublishFormInterceptor(const sptr<IRemoteObject> &interceptorCallback); 482 483 /** 484 * @brief Register click callback observer. 485 * @param bundleName BundleName of the form host. 486 * @param formEventType Form event type. 487 * @param callerToken Caller ability token. 488 * @return Returns ERR_OK on success, others on failure. 489 */ 490 ErrCode RegisterClickEventObserver( 491 const std::string &bundleName, const std::string &formEventType, const sptr<IRemoteObject> &observer); 492 493 /** 494 * @brief Unregister click callback observer. 495 * @param bundleName BundleName of the form host. 496 * @param formEventType Form event type. 497 * @param callerToken Caller ability token. 498 * @return Returns ERR_OK on success, others on failure. 499 */ 500 ErrCode UnregisterClickEventObserver( 501 const std::string &bundleName, const std::string &formEventType, const sptr<IRemoteObject> &observer); 502 503 /** 504 * @brief Compare the locally configured update duration with the update duration in additionalInfo and 505 * return a larger value. 506 * @param formId The Id of the form. 507 * @param updateDuration The valid form update duration. 508 * @return Returns true on success, false on failure. 509 */ 510 bool GetValidFormUpdateDuration(const int64_t formId, int64_t &updateDuration) const; 511 512 /** 513 * @brief Handle forms visible/invisible notify after delay time, notification will be cancelled when 514 * formVisibleState recovered during the delay time. 515 * @param formIds the Ids of forms need to notify. 516 * @param formInstanceMaps formInstances for visibleNotify. 517 * @param eventMaps eventMaps for event notify. 518 * @param formVisibleType The form visible type, including FORM_VISIBLE and FORM_INVISIBLE. 519 */ 520 void HandlerNotifyWhetherVisibleForms(const std::vector<int64_t> &formIds, 521 std::map<std::string, std::vector<FormInstance>> formInstanceMaps, 522 std::map<std::string, std::vector<int64_t>> eventMaps, const int32_t formVisibleType); 523 524 /** 525 * @brief Set forms recyclable 526 * @param formIds Indicates the id of the forms. 527 * @return Returns ERR_OK on success, others on failure. 528 */ 529 int32_t SetFormsRecyclable(const std::vector<int64_t> &formIds); 530 531 /** 532 * @brief Recycle forms 533 * @param formIds Indicates the id of the forms. 534 * @param want The want of forms to be recycled. 535 * @return Returns ERR_OK on success, others on failure. 536 */ 537 int32_t RecycleForms(const std::vector<int64_t> &formIds, const Want &want); 538 539 /** 540 * @brief Recover recycled forms 541 * @param formIds Indicates the id of the forms. 542 * @param want The want of forms to be recovered. 543 * @return Returns ERR_OK on success, others on failure. 544 */ 545 int32_t RecoverForms(const std::vector<int64_t> &formIds, const Want &want); 546 547 /** 548 * @brief Update form cloud update duration when additionalInfo changed. 549 * @param bundleName The bundleName of the form with a specified update duration in app gallery. 550 */ 551 void UpdateFormCloudUpdateDuration(const std::string &bundleName); 552 553 private: 554 /** 555 * @brief Get form configure info. 556 * @param want The want of the request. 557 * @param formItemInfo Form configure info. 558 * @return Returns ERR_OK on success, others on failure. 559 */ 560 ErrCode GetFormConfigInfo(const Want& want, FormItemInfo &formItemInfo); 561 /** 562 * @brief Get bundle info. 563 * @param want The want of the request. 564 * @param bundleInfo Bundle info. 565 * @param packageName Package name. 566 * @return Returns ERR_OK on success, others on failure. 567 */ 568 ErrCode GetBundleInfo(const AAFwk::Want &want, BundleInfo &bundleInfo, std::string &packageName); 569 /** 570 * @brief Get form info. 571 * @param want The want of the request. 572 * @param formInfo Form info. 573 * @return Returns ERR_OK on success, others on failure. 574 */ 575 ErrCode GetFormInfo(const AAFwk::Want &want, FormInfo &formInfo); 576 /** 577 * @brief Get form configure info. 578 * @param want The want of the request. 579 * @param bundleInfo Bundle info. 580 * @param formInfo Form info. 581 * @param formItemInfo Form configure info. 582 * @return Returns ERR_OK on success, others on failure. 583 */ 584 ErrCode GetFormItemInfo(const AAFwk::Want &want, const BundleInfo &bundleInfo, const FormInfo &formInfo, 585 FormItemInfo &formItemInfo); 586 /** 587 * @brief Dimension valid check. 588 * @param formInfo Form info. 589 * @param dimensionId Dimension id. 590 * @return Returns true on success, false on failure. 591 */ 592 bool IsDimensionValid(const FormInfo &formInfo, int dimensionId) const; 593 /** 594 * @brief Create form configure info. 595 * @param bundleInfo Bundle info. 596 * @param formInfo Form info. 597 * @param itemInfo Form configure info. 598 * @param want The want of the request. 599 * @return Returns ERR_OK on success, others on failure. 600 */ 601 ErrCode CreateFormItemInfo(const BundleInfo& bundleInfo, const FormInfo& formInfo, FormItemInfo& itemInfo, 602 const AAFwk::Want &want); 603 /** 604 * @brief Allocate form by formId. 605 * @param info Form configure info. 606 * @param callerToken Caller ability token. 607 * @param wantParams WantParams of the request. 608 * @param formInfo Form info for form host. 609 * @return Returns ERR_OK on success, others on failure. 610 */ 611 ErrCode AllotFormById(const FormItemInfo &info, const sptr<IRemoteObject> &callerToken, 612 const WantParams &wantParams, FormJsInfo &formInfo); 613 /** 614 * @brief Allocate form by form configure info. 615 * @param info Form configure info. 616 * @param callerToken Caller ability token. 617 * @param wantParams WantParams of the request. 618 * @param formInfo Form info for form host. 619 * @return Returns ERR_OK on success, others on failure. 620 */ 621 ErrCode AllotFormByInfo(const FormItemInfo &info, const sptr<IRemoteObject> &callerToken, 622 const WantParams& wantParams, FormJsInfo &formInfo); 623 /** 624 * @brief Acquire form data from form provider. 625 * @param formId The Id of the form.. 626 * @param info Form configure info. 627 * @param wantParams WantParams of the request. 628 * @return Returns ERR_OK on success, others on failure. 629 */ 630 ErrCode AcquireProviderFormInfoAsync(const int64_t formId, const FormItemInfo &info, const WantParams &wantParams); 631 632 ErrCode InnerAcquireProviderFormInfoAsync(const int64_t formId, 633 const FormItemInfo &info, const WantParams &wantParams); 634 635 /** 636 * @brief Handle release form. 637 * @param formId The form id. 638 * @param callerToken Caller ability token. 639 * @return Returns ERR_OK on success, others on failure. 640 */ 641 ErrCode HandleReleaseForm(const int64_t formId, const sptr<IRemoteObject> &callerToken); 642 643 /** 644 * @brief Handle delete form. 645 * @param formId The form id. 646 * @param callerToken Caller ability token. 647 * @return Returns ERR_OK on success, others on failure. 648 */ 649 ErrCode HandleDeleteForm(const int64_t formId, const sptr<IRemoteObject> &callerToken); 650 651 /** 652 * @brief Handle delete temp form. 653 * @param formId The form id. 654 * @param callerToken Caller ability token. 655 * @return Returns ERR_OK on success, others on failure. 656 */ 657 ErrCode HandleDeleteTempForm(const int64_t formId, const sptr<IRemoteObject> &callerToken); 658 659 /** 660 * @brief Handle delete form storage. 661 * @param dbRecord Form storage information. 662 * @param uid calling user id. 663 * @param formId The form id. 664 * @return Function result and has other host flag. 665 */ 666 ErrCode HandleDeleteFormCache(FormRecord &dbRecord, const int uid, const int64_t formId); 667 668 /** 669 * @brief Add existed form record. 670 * @param info Form configure info. 671 * @param callerToken Caller ability token. 672 * @param record Form data. 673 * @param formId The form id. 674 * @param wantParams WantParams of the request. 675 * @param formInfo Form info for form host. 676 * @return Returns ERR_OK on success, others on failure. 677 */ 678 ErrCode AddExistFormRecord(const FormItemInfo &info, const sptr<IRemoteObject> &callerToken, 679 const FormRecord &record, const int64_t formId, const WantParams &wantParams, FormJsInfo &formInfo); 680 681 /** 682 * @brief Add new form record. 683 * @param info Form configure info. 684 * @param formId The form id. 685 * @param callerToken Caller ability token. 686 * @param wantParams WantParams of the request. 687 * @param formInfo Form info for form host. 688 * @return Returns ERR_OK on success, others on failure. 689 */ 690 ErrCode AddNewFormRecord(const FormItemInfo &info, const int64_t formId, 691 const sptr<IRemoteObject> &callerToken, const WantParams &wantParams, FormJsInfo &formInfo); 692 693 /** 694 * @brief Send event notify to form provider. The event notify type include FORM_VISIBLE and FORM_INVISIBLE. 695 * 696 * @param providerKey The provider key string which consists of the provider bundle name and ability name. 697 * @param formIdsByProvider The map of form Ids and their event type which have the same provider. 698 * @param formVisibleType The form visible type, including FORM_VISIBLE and FORM_INVISIBLE. 699 * @return Returns ERR_OK on success, others on failure. 700 */ 701 ErrCode HandleEventNotify(const std::string &providerKey, const std::vector<int64_t> &formIdsByProvider, 702 const int32_t formVisibleType); 703 704 /** 705 * @brief Increase the timer refresh count. 706 * 707 * @param formId The form id. 708 */ 709 void IncreaseTimerRefreshCount(const int64_t formId); 710 711 /** 712 * @brief handle update form flag. 713 * @param formIDs The id of the forms. 714 * @param callerToken Caller ability token. 715 * @param flag form flag. 716 * @param isOnlyEnableUpdate form enable update form flag. 717 * @return Returns ERR_OK on success, others on failure. 718 */ 719 ErrCode HandleUpdateFormFlag(const std::vector<int64_t> &formIds, const sptr<IRemoteObject> &callerToken, 720 bool flag, bool isOnlyEnableUpdate); 721 722 /** 723 * @brief check form cached. 724 * @param record Form information. 725 * @return Returns true on cached, false on not. 726 */ 727 bool IsFormCached(const FormRecord record); 728 729 /** 730 * @brief set next refresh time locked. 731 * @param formId The form's id. 732 * @param nextTime next refresh time. 733 * @param userId User ID. 734 * @return Returns ERR_OK on success, others on failure. 735 */ 736 int SetNextRefreshTimeLocked(const int64_t formId, const int64_t nextTime, const int32_t userId = 0); 737 738 /** 739 * @brief check if update is valid. 740 * @param formId The form's id. 741 * @param bundleName Provider ability bundleName. 742 * @return Returns true or false. 743 */ 744 bool IsUpdateValid(const int64_t formId, const std::string &bundleName); 745 /** 746 * @brief Handle cast temp form. 747 * @param formId The form id. 748 * @param record Form information. 749 * @return Returns ERR_OK on success, others on failure. 750 */ 751 ErrCode HandleCastTempForm(const int64_t formId, const FormRecord &record); 752 753 /** 754 * @brief Add form timer. 755 * @param formRecord Form information. 756 * @return Returns ERR_OK on success, others on failure. 757 */ 758 ErrCode AddFormTimer(const FormRecord &formRecord); 759 760 /** 761 * @brief check the publish form. 762 * @param want The want of the form to publish. 763 * @return Returns ERR_OK on success, others on failure. 764 */ 765 ErrCode CheckPublishForm(Want &want); 766 767 /** 768 * @brief Query the request host. 769 * @param want The want of the form to publish. 770 * @return Returns ERR_OK on success, others on failure. 771 */ 772 ErrCode QueryPublishFormToHost(Want &want); 773 774 /** 775 * @brief Post request publish form to host. 776 * @param want The want of the form to publish. 777 * @return Returns ERR_OK on success, others on failure. 778 */ 779 ErrCode RequestPublishFormToHost(Want &want); 780 781 /** 782 * @brief check the argv of AddRequestPublishForm. 783 * @param want The want of the form to add. 784 * @param formProviderWant The want of the form to publish from provider. 785 * @return Returns ERR_OK on success, others on failure. 786 */ 787 ErrCode CheckAddRequestPublishForm(const Want &want, const Want &formProviderWant); 788 789 /** 790 * @brief add request publish form. 791 * @param formItemInfo Form configure info. 792 * @param want The want of the form to add. 793 * @param callerToken Caller ability token. 794 * @param formJsInfo Return form info to form host. 795 * @return Returns ERR_OK on success, others on failure. 796 */ 797 ErrCode AddRequestPublishForm(const FormItemInfo &formItemInfo, const Want &want, 798 const sptr<IRemoteObject> &callerToken, FormJsInfo &formJsInfo); 799 800 /** 801 * @brief get bundleName. 802 * @param bundleName for output. 803 * @return Returns true on success, others on failure. 804 */ 805 bool GetBundleName(std::string &bundleName); 806 807 /** 808 * @brief Check if the form should update information to the host. 809 * 810 * @param matchedFormId The Id of the form 811 * @param userId User ID. 812 * @param callerToken Caller ability token. 813 * @param formRecord Form storage information 814 * @return Returns true on success, false on failure. 815 */ 816 bool isFormShouldUpdateProviderInfoToHost(const int64_t &matchedFormId, const int32_t &userId, 817 const sptr<IRemoteObject> &callerToken, FormRecord &formRecord); 818 819 /** 820 * @brief Update provider info to host 821 * 822 * @param matchedFormId The Id of the form 823 * @param userId User ID. 824 * @param callerToken Caller ability token. 825 * @param formVisibleType The form visible type, including FORM_VISIBLE and FORM_INVISIBLE. 826 * @param formRecord Form storage information 827 * @return Returns true on success, false on failure. 828 */ 829 bool UpdateProviderInfoToHost(const int64_t &matchedFormId, const int32_t &userId, 830 const sptr<IRemoteObject> &callerToken, const int32_t &formVisibleType, FormRecord &formRecord); 831 832 /** 833 * @brief if the ability have permission for keeping background running is true, 834 * @param iBundleMgr BundleManagerProxy 835 * @param bundleName BundleName 836 * @param userId UserId 837 * @return Returns true if the form provider is system app, false if not. 838 */ 839 bool CheckIsSystemAppByBundleName(const sptr<IBundleMgr> &iBundleMgr, 840 const int32_t &userId, const std::string &bundleName); 841 842 /** 843 * @brief if the ability have permission for keeping background running is true, 844 * @param iBundleMgr BundleManagerProxy 845 * @param bundleName BundleName 846 * @return Returns true if the ability have permission for keeping background running, false if not. 847 */ 848 bool CheckKeepBackgroundRunningPermission(const sptr<IBundleMgr> &iBundleMgr, const std::string &bundleName); 849 /** 850 * @brief Create eventMaps for event notify. 851 * 852 * @param matchedFormId The Id of the form 853 * @param formRecord Form storage information 854 * @param eventMaps eventMaps for event notify 855 * @return Returns true on success, false on failure. 856 */ 857 bool CreateHandleEventMap(const int64_t matchedFormId, const FormRecord &formRecord, 858 std::map<std::string, std::vector<int64_t>> &eventMaps); 859 /** 860 * @brief Get current user ID. 861 * @param callingUid calling Uid. 862 * @return Returns user ID. 863 */ 864 int32_t GetCurrentUserId(const int callingUid); 865 /** 866 * @brief AcquireFormState want check. 867 * @param bundleName The bundle name of the form. 868 * @param abilityName The ability name of the form. 869 * @param want The want of the form. 870 * @param provider the provider info. 871 * @return Returns ERR_OK on success, others on failure. 872 */ 873 ErrCode AcquireFormStateCheck(const std::string &bundleName, const std::string &abilityName, const Want &want, 874 std::string &provider); 875 /** 876 * @brief check if the form host is system app 877 * @param formRecord Form storage information 878 * @return Returns true if the form host is system app, false if not. 879 */ 880 bool checkFormHostHasSaUid(const FormRecord &formRecord); 881 882 /** 883 * @brief Check whether the caller for publish form is in the whitelist. 884 * @param iBundleMgr BundleManagerProxy 885 * @param bundleName BundleName of caller 886 * @param want want of target form 887 * @return Returns true if the caller is in the whitelist, others if not. 888 */ 889 bool IsValidPublishEvent(const sptr<IBundleMgr> &iBundleMgr, const std::string &bundleName, const Want &want); 890 891 /** 892 * @brief Allocate form by specific Id. 893 * @param info Form configure info. 894 * @param callerToken Caller ability token. 895 * @param wantParams WantParams of the request. 896 * @param formInfo Form info for form host. 897 * @return Returns ERR_OK on success, others on failure. 898 */ 899 ErrCode AllotFormBySpecificId(const FormItemInfo &info, 900 const sptr<IRemoteObject> &callerToken, const WantParams &wantParams, FormJsInfo &formInfo); 901 902 /** 903 * @brief when form observer died clean the resource. 904 * @param remote remote object. 905 */ 906 void CleanResource(const wptr<IRemoteObject> &remote); 907 908 /** 909 * @brief Set value of deathRecipient_. 910 * @param callerToken Caller ability token. 911 * @param deathRecipient DeathRecipient object. 912 */ 913 void SetDeathRecipient(const sptr<IRemoteObject> &callerToken, 914 const sptr<IRemoteObject::DeathRecipient> &deathRecipient); 915 mutable std::mutex formObserversMutex_; 916 mutable std::mutex deathRecipientsMutex_; 917 std::map<std::string, std::vector<sptr<IRemoteObject>>> formObservers_; 918 std::map<sptr<IRemoteObject>, sptr<IRemoteObject::DeathRecipient>> deathRecipients_; 919 920 void NotifyFormClickEvent(int64_t formId, const std::string &formClickType); 921 922 /** 923 * @brief Get caller type. 924 * @param bundleName the caller's bundle name. 925 */ 926 int32_t GetCallerType(std::string bundleName); 927 928 /** 929 * @brief Check if the form is allow to publish. 930 * @param bundleName the caller's bundle name. 931 * @param wants Wants of the request. 932 */ 933 bool IsErmsSupportPublishForm(std::string bundleName, std::vector<Want> wants); 934 935 /** 936 * @brief Notify forms visible/invisible to remoteCallers. 937 * @param bundleName the caller's bundle name. 938 * @param remoteObjects refs of remoteCallers. 939 * @param formInstanceMaps formInstances for visibleNotify. 940 * @param formVisibleType The form visible type, including FORM_VISIBLE and FORM_INVISIBLE. 941 */ 942 void NotifyWhetherFormsVisible(const std::string &bundleName, 943 std::vector<sptr<IRemoteObject>> &remoteObjects, 944 std::map<std::string, std::vector<FormInstance>> &formInstanceMaps, const int32_t formVisibleType); 945 946 /** 947 * @brief Forms formInstanceMaps or eventMaps should remove when visible/invisible status recovered. 948 * @param formInstanceMaps formInstances for visibleNotify. 949 * @param eventMaps eventMaps for event notify. 950 * @param formVisibleType The form visible type, including FORM_VISIBLE and FORM_INVISIBLE. 951 */ 952 void FilterDataByVisibleType(std::map<std::string, std::vector<FormInstance>> &formInstanceMaps, 953 std::map<std::string, std::vector<int64_t>> &eventMaps, const int32_t formVisibleType); 954 955 /** 956 * @brief Forms formInstanceMaps should remove when visible/invisible status recovered. 957 * @param formInstanceMaps formInstances for visibleNotify. 958 * @param formVisibleType The form visible type, including FORM_VISIBLE and FORM_INVISIBLE. 959 * @param restoreFormRecords formRecords of forms no need to notify. 960 */ 961 void FilterFormInstanceMapsByVisibleType(std::map<std::string, std::vector<FormInstance>> &formInstanceMaps, 962 const int32_t formVisibleType, std::map<int64_t, FormRecord> &restoreFormRecords); 963 964 /** 965 * @brief Forms eventMaps should remove when visible/invisible status recovered. 966 * @param eventMaps eventMaps for event notify. 967 * @param formVisibleType The form visible type, including FORM_VISIBLE and FORM_INVISIBLE. 968 * @param restoreFormRecords formRecords of forms no need to notify. 969 */ 970 void FilterEventMapsByVisibleType(std::map<std::string, std::vector<int64_t>> &eventMaps, 971 const int32_t formVisibleType, std::map<int64_t, FormRecord> &restoreFormRecords); 972 973 ErrCode CheckFormCountLimit(const int64_t formId, const Want &want); 974 975 ErrCode AllotForm(const int64_t formId, const Want &want, 976 const sptr<IRemoteObject> &callerToken, FormJsInfo &formInfo, const FormItemInfo &formItemInfo); 977 978 void GetUpdateDurationFromAdditionalInfo(const std::string &additionalInfo, std::vector<int> &durationArray) const; 979 /** 980 * @class ClientDeathRecipient 981 * notices IRemoteBroker died. 982 */ 983 class ClientDeathRecipient : public IRemoteObject::DeathRecipient { 984 public: 985 /** 986 * @brief Constructor 987 */ 988 ClientDeathRecipient() = default; 989 virtual ~ClientDeathRecipient() = default; 990 /** 991 * @brief handle remote object died event. 992 * @param remote remote object. 993 */ 994 void OnRemoteDied(const wptr<IRemoteObject> &remote) override; 995 }; 996 997 private: 998 sptr<IFormPublishInterceptor> formPublishInterceptor_ = nullptr; 999 int32_t visibleNotifyDelay_ = Constants::DEFAULT_VISIBLE_NOTIFY_DELAY; 1000 }; 1001 } // namespace AppExecFwk 1002 } // namespace OHOS 1003 1004 #endif // OHOS_FORM_FWK_FORM_MGR_ADAPTER_H 1005