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