1 /* 2 * Copyright (c) 2021-2024 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_H 17 #define OHOS_FORM_FWK_FORM_MGR_H 18 19 #include <mutex> 20 #include <shared_mutex> 21 #include <singleton.h> 22 #include <thread> 23 24 #include "form_callback_interface.h" 25 #include "form_constants.h" 26 #include "form_errors.h" 27 #include "form_death_callback.h" 28 #include "form_info.h" 29 #include "form_instance.h" 30 #include "form_instances_filter.h" 31 #include "form_js_info.h" 32 #include "form_mgr_interface.h" 33 #include "form_provider_data.h" 34 #include "form_provider_data_proxy.h" 35 #include "form_state_info.h" 36 #include "iremote_object.h" 37 #include "want.h" 38 39 namespace OHOS { 40 namespace AppExecFwk { 41 using OHOS::AAFwk::Want; 42 43 static volatile int recoverStatus_ = Constants::NOT_IN_RECOVERY; 44 45 /** 46 * @class FormMgr 47 * FormMgr is used to access form manager services. 48 */ 49 class FormMgr final : public DelayedRefSingleton<FormMgr> { 50 DECLARE_DELAYED_REF_SINGLETON(FormMgr) 51 public: 52 DISALLOW_COPY_AND_MOVE(FormMgr); 53 54 friend class FormMgrDeathRecipient; 55 56 /** 57 * @brief Register click callback observer. 58 * @param bundleName BundleName of the form host. 59 * @param formEventType Form event type. 60 * @param observer Form click event callback listener. 61 * @return Returns ERR_OK on success, others on failure. 62 */ 63 ErrCode RegisterClickEventObserver( 64 const std::string &bundleName, const std::string &formEventType, const sptr<IRemoteObject> &observer); 65 66 /** 67 * @brief Unregister click callback observer. 68 * @param bundleName BundleName of the form host. 69 * @param formEventType Form event type. 70 * @param observer Form click event callback listener. 71 * @return Returns ERR_OK on success, others on failure. 72 */ 73 ErrCode UnregisterClickEventObserver( 74 const std::string &bundleName, const std::string &formEventType, const sptr<IRemoteObject> &observer); 75 76 /** 77 * @brief Get the error message by error code. 78 * @param errorCode the error code return form fms. 79 * @return Returns the error message detail. 80 */ 81 std::string GetErrorMsg(int errorCode); 82 83 /** 84 * @brief Add form with want, send want to form manager service. 85 * @param formId The Id of the forms to add. 86 * @param want The want of the form to add. 87 * @param callerToken Caller ability token. 88 * @param formInfo Form info. 89 * @return Returns ERR_OK on success, others on failure. 90 */ 91 int AddForm(const int64_t formId, const Want &want, const sptr<IRemoteObject> &callerToken, 92 FormJsInfo &formInfo); 93 94 /** 95 * @brief Add form with want, send want to form manager service. 96 * @param want The want of the form to add. 97 * @param runningFormInfo Running form info. 98 * @return Returns ERR_OK on success, others on failure. 99 */ 100 int CreateForm(const Want &want, RunningFormInfo &runningFormInfo); 101 102 /** 103 * @brief Delete forms with formIds, send formIds to form manager service. 104 * @param formId The Id of the forms to delete. 105 * @param callerToken Caller ability token. 106 * @return Returns ERR_OK on success, others on failure. 107 */ 108 int DeleteForm(const int64_t formId, const sptr<IRemoteObject> &callerToken); 109 110 /** 111 * @brief Stop rendering form. 112 * @param formId The Id of the forms to delete. 113 * @param compId The compId of the forms to delete. 114 * @return Returns ERR_OK on success, others on failure. 115 */ 116 int StopRenderingForm(const int64_t formId, const std::string &compId); 117 118 /** 119 * @brief Release forms with formIds, send formIds to form manager service. 120 * @param formId The Id of the forms to release. 121 * @param callerToken Caller ability token. 122 * @param delCache Delete Cache or not. 123 * @return Returns ERR_OK on success, others on failure. 124 */ 125 int ReleaseForm(const int64_t formId, const sptr<IRemoteObject> &callerToken, const bool delCache); 126 127 /** 128 * @brief Update form with formId, send formId to form manager service. 129 * @param formId The Id of the form to update. 130 * @param formBindingData Form binding data. 131 * @param std::vector<FormDataProxy> Form proxy vector. 132 * @return Returns ERR_OK on success, others on failure. 133 */ 134 int UpdateForm(const int64_t formId, const FormProviderData &formBindingData, 135 const std::vector<FormDataProxy> &formDataProxies = {}); 136 137 /** 138 * @brief Notify the form service that the form user's lifecycle is updated. 139 * 140 * This should be called when form user request form. 141 * 142 * @param formId Indicates the unique id of form. 143 * @param callerToken Indicates the callback remote object of specified form user. 144 * @param want information passed to supplier. 145 * @return Returns ERR_OK on success, others on failure. 146 */ 147 int RequestForm(const int64_t formId, const sptr<IRemoteObject> &callerToken, const Want &want); 148 149 /** 150 * @brief Form visible/invisible notify, send formIds to form manager service. 151 * @param formIds The Id list of the forms to notify. 152 * @param callerToken Caller ability token. 153 * @param formVisibleType The form visible type, including FORM_VISIBLE and FORM_INVISIBLE. 154 * @return Returns ERR_OK on success, others on failure. 155 */ 156 int NotifyWhetherVisibleForms(const std::vector<int64_t> &formIds, const sptr<IRemoteObject> &callerToken, 157 const int32_t formVisibleType); 158 159 /** 160 * @brief Query whether has visible form by tokenId. 161 * @param tokenId Unique identification of application. 162 * @return Returns true if has visible form, false otherwise. 163 */ 164 bool HasFormVisible(const uint32_t tokenId); 165 166 /** 167 * @brief Release renderer. 168 * @param formId The Id of the forms to release. 169 * @param compId The compId of the forms to release. 170 * @return Returns ERR_OK on success, others on failure. 171 */ 172 int ReleaseRenderer(const int64_t formId, const std::string &compId); 173 174 /** 175 * @brief temp form to normal form. 176 * @param formId The Id of the form. 177 * @param callerToken Caller ability token. 178 * @return None. 179 */ 180 int CastTempForm(const int64_t formId, const sptr<IRemoteObject> &callerToken); 181 182 /** 183 * @brief Dump all of form storage infos. 184 * @param formInfos All of form storage infos. 185 * @return Returns ERR_OK on success, others on failure. 186 */ 187 int DumpStorageFormInfos(std::string &formInfos); 188 /** 189 * @brief Dump form info by a bundle name. 190 * @param bundleName The bundle name of form provider. 191 * @param formInfos Form infos. 192 * @return Returns ERR_OK on success, others on failure. 193 */ 194 int DumpFormInfoByBundleName(const std::string bundleName, std::string &formInfos); 195 /** 196 * @brief Dump form info by a bundle name. 197 * @param formId The id of the form. 198 * @param formInfo Form info. 199 * @return Returns ERR_OK on success, others on failure. 200 */ 201 int DumpFormInfoByFormId(const std::int64_t formId, std::string &formInfo); 202 /** 203 * @brief Dump form timer by form id. 204 * @param formId The id of the form. 205 * @param formInfo Form timer. 206 * @return Returns ERR_OK on success, others on failure. 207 */ 208 int DumpFormTimerByFormId(const std::int64_t formId, std::string &isTimingService); 209 /** 210 * @brief Process js message event. 211 * @param formId Indicates the unique id of form. 212 * @param want information passed to supplier. 213 * @param callerToken Caller ability token. 214 * @return Returns ERR_OK on success, others on failure. 215 */ 216 int MessageEvent(const int64_t formId, const Want &want, const sptr<IRemoteObject> &callerToken); 217 218 /** 219 * @brief Process js router event. 220 * @param formId Indicates the unique id of form. 221 * @param want the want of the ability to start. 222 * @param callerToken Caller ability token. 223 * @return Returns ERR_OK on success, others on failure. 224 */ 225 int RouterEvent(const int64_t formId, Want &want, const sptr<IRemoteObject> &callerToken); 226 227 /** 228 * @brief Process Background event. 229 * @param formId Indicates the unique id of form. 230 * @param want the want of the ability to start. 231 * @param callerToken Caller ability token. 232 * @return Returns true if execute success, false otherwise. 233 */ 234 int BackgroundEvent(const int64_t formId, Want &want, const sptr<IRemoteObject> &callerToken); 235 236 /** 237 * @brief Get fms recoverStatus. 238 * 239 * @return The current recover status. 240 */ 241 static int GetRecoverStatus(); 242 243 /** 244 * @brief Register death callback. 245 * 246 * @param formDeathCallback The death callback. 247 */ 248 void RegisterDeathCallback(const std::shared_ptr<FormCallbackInterface> &formDeathCallback); 249 250 /** 251 * @brief UnRegister death callback. 252 * 253 * @param formDeathCallback The death callback. 254 */ 255 void UnRegisterDeathCallback(const std::shared_ptr<FormCallbackInterface> &formDeathCallback); 256 257 /** 258 * @brief Set the next refresh time 259 * 260 * @param formId The id of the form. 261 * @param nextTime Next refresh time 262 * @return Returns ERR_OK on success, others on failure. 263 */ 264 int SetNextRefreshTime(const int64_t formId, const int64_t nextTime); 265 266 /** 267 * @brief Request to publish a form to the form host. 268 * 269 * @param want The want of the form to publish. 270 * @param withFormBindingData Indicates whether the formBindingData is carried with. 271 * @param formBindingData Indicates the form data. 272 * @param formId Return the form id to be published. 273 * @return Returns ERR_OK on success, others on failure. 274 */ 275 ErrCode RequestPublishForm(Want &want, bool withFormBindingData, 276 std::unique_ptr<FormProviderData> &formBindingData, int64_t &formId, 277 const std::vector<FormDataProxy> &formDataProxies = {}); 278 279 ErrCode SetPublishFormResult(const int64_t formId, Constants::PublishFormResult &errorCodeInfo); 280 281 ErrCode AcquireAddFormResult(const int64_t formId); 282 283 /** 284 * @brief Lifecycle Update. 285 * @param formIds The id of the forms. 286 * @param callerToken Host client. 287 * @param updateType update type, enable if true and disable if false. 288 * @return Returns ERR_OK on success, others on failure. 289 */ 290 int LifecycleUpdate(const std::vector<int64_t> &formIds, const sptr<IRemoteObject> &callerToken, 291 bool updateType); 292 293 /** 294 * @brief Set fms recoverStatus. 295 * 296 * @param recoverStatus The recover status. 297 */ 298 static void SetRecoverStatus(int recoverStatus); 299 300 /** 301 * @brief Set form mgr service for test. 302 */ 303 void SetFormMgrService(sptr<IFormMgr> formMgrService); 304 305 /** 306 * @brief Get death recipient. 307 * @return deathRecipient_. 308 */ 309 sptr<IRemoteObject::DeathRecipient> GetDeathRecipient() const; 310 311 /** 312 * @brief Check whether the specified death callback is registered in form mgr. 313 * @param formDeathCallback The specified death callback for checking. 314 * @return Return true on success, false on failure. 315 */ 316 bool CheckIsDeathCallbackRegistered(const std::shared_ptr<FormCallbackInterface> &formDeathCallback); 317 318 /** 319 * @brief Get the error message content. 320 * 321 * @param errCode Error code. 322 * @return Message content. 323 */ 324 std::string GetErrorMessage(int errCode); 325 326 /** 327 * @brief Delete the invalid forms. 328 * @param formIds Indicates the ID of the valid forms. 329 * @param callerToken Host client. 330 * @param numFormsDeleted Returns the number of the deleted forms. 331 * @return Returns ERR_OK on success, others on failure. 332 */ 333 int DeleteInvalidForms(const std::vector<int64_t> &formIds, const sptr<IRemoteObject> &callerToken, 334 int32_t &numFormsDeleted); 335 336 /** 337 * @brief Acquire form state info by passing a set of parameters (using Want) to the form provider. 338 * @param want Indicates a set of parameters to be transparently passed to the form provider. 339 * @param callerToken Host client. 340 * @param stateInfo Returns the form's state info of the specify. 341 * @return Returns ERR_OK on success, others on failure. 342 */ 343 int AcquireFormState(const Want &want, const sptr<IRemoteObject> &callerToken, FormStateInfo &stateInfo); 344 345 /** 346 * @brief Notify the form is visible or not. 347 * @param formIds Indicates the ID of the forms. 348 * @param isVisible Visible or not. 349 * @param callerToken Host client. 350 * @return Returns ERR_OK on success, others on failure. 351 */ 352 int NotifyFormsVisible(const std::vector<int64_t> &formIds, bool isVisible, const sptr<IRemoteObject> &callerToken); 353 354 /** 355 * @brief Notify the form is privacy protected or not. 356 * @param formIds Indicates the ID of the forms. 357 * @param isProtected isProtected or not. 358 * @param callerToken Host client. 359 * @return Returns ERR_OK on success, others on failure. 360 */ 361 int NotifyFormsPrivacyProtected(const std::vector<int64_t> &formIds, bool isProtected, 362 const sptr<IRemoteObject> &callerToken); 363 364 /** 365 * @brief Notify the form is enable to be updated or not. 366 * @param formIds Indicates the ID of the forms. 367 * @param isEnableUpdate enable update or not. 368 * @param callerToken Host client. 369 * @return Returns ERR_OK on success, others on failure. 370 */ 371 int NotifyFormsEnableUpdate(const std::vector<int64_t> &formIds, bool isEnableUpdate, 372 const sptr<IRemoteObject> &callerToken); 373 374 /** 375 * @brief Get All FormsInfo. 376 * @param formInfos Return the forms' information of all forms provided. 377 * @return Returns ERR_OK on success, others on failure. 378 */ 379 int GetAllFormsInfo(std::vector<FormInfo> &formInfos); 380 381 /** 382 * @brief Get forms info by bundle name . 383 * @param bundleName Application name. 384 * @param formInfos Return the forms' information of the specify application name. 385 * @return Returns ERR_OK on success, others on failure. 386 */ 387 int GetFormsInfoByApp(std::string &bundleName, std::vector<FormInfo> &formInfos); 388 389 /** 390 * @brief Get forms info by bundle name and module name. 391 * @param bundleName bundle name. 392 * @param moduleName Module name of hap. 393 * @param formInfos Return the forms' information of the specify bundle name and module name. 394 * @return Returns ERR_OK on success, others on failure. 395 */ 396 int GetFormsInfoByModule(std::string &bundleName, std::string &moduleName, std::vector<FormInfo> &formInfos); 397 398 /** 399 * @brief Get forms info specified by filter parameters. 400 * @param filter Filter that contains necessary conditions, such as bundle name, module name, dimensions. 401 * @param formInfos Return the forms' information specified by filter. 402 * @return Returns ERR_OK on success, others on failure. 403 */ 404 int GetFormsInfoByFilter(const FormInfoFilter &filter, std::vector<FormInfo> &formInfos); 405 406 /** 407 * @brief This function is called by formProvider and gets forms info by the bundle name of the calling ability. 408 * The bundle name will be retrieved by form service manager. 409 * @param filter filter that contains attributes that the formInfos have to have. 410 * @param formInfos Return the forms' information of the calling bundle name 411 * @return Returns ERR_OK on success, others on failure. 412 */ 413 int32_t GetFormsInfo(const FormInfoFilter &filter, std::vector<FormInfo> &formInfos); 414 415 /** 416 * @brief Get all running form infos. 417 * @param isUnusedIncluded Indicates whether to include unused forms. 418 * @param runningFormInfos Return the running forms' infos currently. 419 * @return Returns ERR_OK on success, others on failure. 420 */ 421 ErrCode GetRunningFormInfos(bool isUnusedIncluded, std::vector<RunningFormInfo> &runningFormInfos); 422 423 /** 424 * @brief Get the running form infos by bundle name. 425 * @param bundleName Application name. 426 * @param isUnusedIncluded Indicates whether to include unused forms. 427 * @param runningFormInfos Return the running forms' infos of the specify application name. 428 * @return Returns ERR_OK on success, others on failure. 429 */ 430 ErrCode GetRunningFormInfosByBundleName( 431 const std::string &bundleName, bool isUnusedIncluded, std::vector<RunningFormInfo> &runningFormInfos); 432 433 /** 434 * @brief Check if the request of publishing a form is supported by the host. 435 * @return Returns true if the request is supported and false otherwise. 436 */ 437 bool IsRequestPublishFormSupported(); 438 439 /** 440 * @brief Start an ability. This function can only be called by a form extension of a system app. 441 * @param want includes ability name, parameters and relative info sending to an ability. 442 * @param callerToken token of the ability that initially calls this function. 443 * @return Returns ERR_OK on success, others on failure. 444 */ 445 int32_t StartAbility(const Want &want, const sptr<IRemoteObject> &callerToken); 446 447 /** 448 * @brief Share form with formId and remote device id. 449 * @param formId The Id of the forms to share. 450 * @param remoteDeviceId The Id of the remote revice to share. 451 * @param callerToken Indicates the host client. 452 * @param requestCode The request code of this share form. 453 * @return Returns ERR_OK on success, others on failure. 454 */ 455 int32_t ShareForm(int64_t formId, const std::string &remoteDeviceId, const sptr<IRemoteObject> &callerToken, 456 int64_t requestCode); 457 458 /** 459 * @brief Acquire form data by formId. 460 * @param formId The Id of the form to acquire data. 461 * @param requestCode The request code of this acquire form. 462 * @param callerToken Indicates the host client. 463 * @param formData Return the forms' information of customization 464 * @return Returns ERR_OK on success, others on failure. 465 */ 466 int32_t AcquireFormData(int64_t formId, int64_t requestCode, const sptr<IRemoteObject> &callerToken, 467 AAFwk::WantParams &formData); 468 469 /** 470 * @brief Check form manager service ready. 471 * 472 * @return Return true if form manager service ready; returns false otherwise. 473 */ 474 bool CheckFMSReady(); 475 476 /** 477 * @brief Check whether the form is system app. 478 * @param bundleName The bundleName of the form. 479 * @return Returns true if the form app is system, others false. 480 */ 481 bool IsSystemAppForm(const std::string &bundleName); 482 483 /** 484 * @brief Registers the callback for publish form. The callback is used to process the publish form request 485 * when the system handler is not found. 486 * @param interceptorCallback The injected callback, should implementation IFormPublishInterceptor. 487 * @return Returns ERR_OK on success, others on failure. 488 */ 489 int32_t RegisterPublishFormInterceptor(const sptr<IRemoteObject> &interceptorCallback); 490 491 /** 492 * @brief Unregisters the callback for publish form. The callback is used to process the publish form request 493 * when the system handler is not found. 494 * @param interceptorCallback The injected callback, should implementation IFormPublishInterceptor. 495 * @return Returns ERR_OK on success, others on failure. 496 */ 497 int32_t UnregisterPublishFormInterceptor(const sptr<IRemoteObject> &interceptorCallback); 498 499 /** 500 * @brief Get external error from innerErrorCode. 501 * @param innerErrorCode innerErrorCode, get from FMS. 502 * @param externalErrorCode output externalErrorCode. 503 * @param errorMsg output errorMsg. 504 */ 505 void GetExternalError(int32_t innerErrorCode, int32_t &externalErrorCode, std::string &errorMsg); 506 507 /** 508 * @brief Get external error message by external error code. 509 * 510 * @param externalErrorCode External error code. 511 * @return External error message. 512 */ 513 std::string GetErrorMsgByExternalErrorCode(int32_t externalErrorCode); 514 515 /** 516 * @brief Register form add observer by bundle. 517 * @param bundleName BundleName of the form host 518 * @param callerToken Caller ability token. 519 * @return Returns ERR_OK on success, others on failure. 520 */ 521 ErrCode RegisterFormAddObserverByBundle(const std::string bundleName, const sptr<IRemoteObject> &callerToken); 522 523 /** 524 * @brief Register form remove observer by bundle. 525 * @param bundleName BundleName of the form host 526 * @param callerToken Caller ability token. 527 * @return Returns ERR_OK on success, others on failure. 528 */ 529 ErrCode RegisterFormRemoveObserverByBundle(const std::string bundleName, const sptr<IRemoteObject> &callerToken); 530 531 /** 532 * @brief get forms count. 533 * @param isTempFormFlag Indicates temp form or not. 534 * @param formCount Returns the number of the cast or temp form. 535 * @return Returns ERR_OK on success, others on failure. 536 */ 537 int32_t GetFormsCount(bool isTempFormFlag, int32_t &formCount); 538 539 /** 540 * @brief get host forms count. 541 * @param bundleName Indicates form host bundleName. 542 * @param formCount Returns the number of the host form. 543 * @return Returns ERR_OK on success, others on failure. 544 */ 545 int32_t GetHostFormsCount(std::string &bundleName, int32_t &formCount); 546 547 /** 548 * @brief Get form instances by filter info. 549 * @param formInstancesFilter includes bundleName, moduleName, formName, abilityName to get formInstances. 550 * @param formInstances return formInstances 551 * @return return ERR_OK on get info success, others on failure. 552 */ 553 ErrCode GetFormInstancesByFilter(const FormInstancesFilter &formInstancesFilter, 554 std::vector<FormInstance> &formInstances); 555 556 /** 557 * @brief Get form instance by formId. 558 * @param formId formId Indicates the unique id of form. 559 * @param formInstance return formInstance 560 * @return return ERR_OK on get info success, others on failure. 561 */ 562 ErrCode GetFormInstanceById(const int64_t formId, FormInstance &formInstance); 563 564 /** 565 * @brief Get form instance by formId, include form store in DB. 566 * @param formId formId Indicates the unique id of form. 567 * @param isUnusedIncluded Indicates whether to include unused form. 568 * @param formInstance return formInstance 569 * @return return ERR_OK on get info success, others on failure. 570 */ 571 ErrCode GetFormInstanceById(const int64_t formId, bool isUnusedIncluded, FormInstance &formInstance); 572 573 /** 574 * @brief Register form add observer. 575 * @param bundleName BundleName of the form host 576 * @param callerToken Caller ability token. 577 * @return Returns ERR_OK on success, others on failure. 578 */ 579 ErrCode RegisterAddObserver(const std::string &bundleName, const sptr<IRemoteObject> &callerToken); 580 581 /** 582 * @brief Register form remove observer. 583 * @param bundleName BundleName of the form host 584 * @param callerToken Caller ability token. 585 * @return Returns ERR_OK on success, others on failure. 586 */ 587 ErrCode RegisterRemoveObserver(const std::string &bundleName, const sptr<IRemoteObject> &callerToken); 588 589 /** 590 * @brief Register form router event proxy. 591 * @param formIds Indicates the ID of the forms. 592 * @param callerToken Router proxy call back client. 593 * @return Returns ERR_OK on success, others on failure. 594 */ 595 ErrCode RegisterFormRouterProxy(const std::vector<int64_t> &formIds, const sptr<IRemoteObject> &callerToken); 596 597 /** 598 * @brief Unregister form router event proxy. 599 * @param formIds Indicates the ID of the forms. 600 * @return Returns ERR_OK on success, others on failure. 601 */ 602 ErrCode UnregisterFormRouterProxy(const std::vector<int64_t> &formIds); 603 604 /** 605 * @brief Set forms recyclable 606 * @param formIds Indicates the id of the forms. 607 * @return Returns ERR_OK on success, others on failure. 608 */ 609 int32_t SetFormsRecyclable(const std::vector<int64_t> &formIds); 610 611 /** 612 * @brief Recycle forms 613 * @param formIds Indicates the id of the forms. 614 * @param want The want of forms to be recycled. 615 * @return Returns ERR_OK on success, others on failure. 616 */ 617 int32_t RecycleForms(const std::vector<int64_t> &formIds, const Want &want); 618 619 /** 620 * @brief Recover recycled forms 621 * @param formIds Indicates the id of the forms. 622 * @param want The want of forms to be recovered. 623 * @return Returns ERR_OK on success, others on failure. 624 */ 625 int32_t RecoverForms(const std::vector<int64_t> &formIds, const Want &want); 626 627 /** 628 * @brief Update formLocation with formId. 629 * @param formId The Id of the form to update. 630 * @param formLocation The FormLocation. 631 * @return Returns ERR_OK on success, others on failure. 632 */ 633 ErrCode UpdateFormLocation(const int64_t &formId, const int32_t &formLocation); 634 635 /** 636 * @brief Request to publish a form to the form host for normal authority. 637 * 638 * @param want The want of the form to publish. 639 * @param withFormBindingData Indicates whether the formBindingData is carried with. 640 * @param formBindingData Indicates the form data. 641 * @param formId Return the form id to be published. 642 * @return Returns ERR_OK on success, others on failure. 643 */ 644 ErrCode RequestPublishFormWithSnapshot(Want &want, bool withFormBindingData, 645 std::unique_ptr<FormProviderData> &formBindingData, int64_t &formId, 646 const std::vector<FormDataProxy> &formDataProxies = {}); 647 648 /** 649 * @brief Update form with formRefreshType, send to form manager service. 650 * @param formRefreshType The type of the form to refresh, 0: AllForm 1: 2: AppForm 2: AtomicServiceForm 651 * @return Returns ERR_OK on success, others on failure. 652 */ 653 int32_t BatchRefreshForms(const int32_t formRefreshType); 654 655 /** 656 * @brief enable/disable form update. 657 * @param bundleName BundleName of the form host. 658 * @param enable True for enable form, false for disable form. 659 * @return Returns ERR_OK on success, others on failure. 660 */ 661 int32_t EnableForms(const std::string bundleName, const bool enable); 662 663 /** 664 * @brief Check form bundle is controlled. 665 * @param bundleName The bundle name of form to be check. 666 * @return Returns true for form bundle is controlled. 667 */ 668 bool IsFormBundleForbidden(const std::string &bundleName); 669 670 /** 671 * @brief Update form size. 672 * @param formId The Id of the form to update. 673 * @param width The width value to be updated. 674 * @param height The height value to be updated. 675 * @param borderWidth The borderWidth value to be updated. 676 * @return Returns ERR_OK on success, others on failure. 677 */ 678 int32_t UpdateFormSize(const int64_t formId, float width, float height, float borderWidth); 679 private: 680 /** 681 * @brief Connect form manager service. 682 * @return Returns ERR_OK on success, others on failure. 683 */ 684 ErrCode Connect(); 685 686 /** 687 * @brief Reconnect form manager service once per 1000 milliseconds, 688 * until the connection succeeds or reaching the max retry times. 689 * @return Returns true if execute success, false otherwise. 690 */ 691 bool Reconnect(); 692 /** 693 * @brief Reset proxy. 694 * @param remote remote object. 695 */ 696 void ResetProxy(const wptr<IRemoteObject> &remote); 697 698 /** 699 * @class FormMgrDeathRecipient 700 * FormMgrDeathRecipient notices IRemoteBroker died. 701 */ 702 class FormMgrDeathRecipient : public IRemoteObject::DeathRecipient { 703 public: 704 FormMgrDeathRecipient() = default; 705 ~FormMgrDeathRecipient() = default; 706 707 /** 708 * @brief Notices IRemoteBroker died. 709 * @param remote remote object. 710 */ 711 void OnRemoteDied(const wptr<IRemoteObject> &remote) override; 712 private: 713 DISALLOW_COPY_AND_MOVE(FormMgrDeathRecipient); 714 }; 715 716 // Shared locks are used here, write locks are used for setting remoteProxy_ operations, 717 // and concurrent read locks are used for reading remoteProxy_ operations. 718 std::shared_mutex connectMutex_; 719 sptr<IFormMgr> remoteProxy_; 720 721 sptr<IRemoteObject::DeathRecipient> deathRecipient_ {nullptr}; 722 723 // True: need to get a new fms remote object, 724 // False: no need to get a new fms remote object. 725 volatile bool resetFlag_ = false; 726 727 std::vector<std::shared_ptr<FormCallbackInterface>> formDeathCallbacks_; 728 }; 729 } // namespace AppExecFwk 730 } // namespace OHOS 731 #endif // OHOS_FORM_FWK_FORM_MGR_H 732