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_SERVICE_H 17 #define OHOS_FORM_FWK_FORM_MGR_SERVICE_H 18 19 #include <singleton.h> 20 #include <system_ability.h> 21 22 #include "form_event_handler.h" 23 #include "form_instance.h" 24 #include "form_instances_filter.h" 25 #include "form_mgr_stub.h" 26 #include "form_provider_data.h" 27 #include "form_serial_queue.h" 28 #include "form_sys_event_receiver.h" 29 #include "running_form_info.h" 30 #include "iremote_object.h" 31 #include "mem_status_listener.h" 32 namespace OHOS { 33 namespace AppExecFwk { 34 enum class ServiceRunningState { 35 STATE_NOT_START, 36 STATE_RUNNING, 37 }; 38 39 enum class ConNetStatus { 40 DIS_CONNECT_NETWORK = 0, 41 CONNECT_NETWORK, 42 PRE_CONNECT_NETWORK, 43 PRE_DISCONNECT_NETWORK, 44 }; 45 46 /** 47 * @class FormMgrService 48 * FormMgrService provides a facility for managing form life cycle. 49 */ 50 class FormMgrService : public SystemAbility, 51 public FormMgrStub, 52 public std::enable_shared_from_this<FormMgrService> { 53 DECLARE_DELAYED_SINGLETON(FormMgrService); 54 DECLEAR_SYSTEM_ABILITY(FormMgrService); 55 public: 56 /** 57 * @brief Start event for the form manager service. 58 */ 59 void OnStart() override; 60 /** 61 * @brief Stop event for the form manager service. 62 */ 63 void OnStop() override; 64 65 /** 66 * @brief Add form with want, send want to form manager service. 67 * @param formId The Id of the forms to add. 68 * @param want The want of the form to add. 69 * @param callerToken Caller ability token. 70 * @param formInfo Form info. 71 * @return Returns ERR_OK on success, others on failure. 72 */ 73 int AddForm(const int64_t formId, const Want &want, const sptr<IRemoteObject> &callerToken, 74 FormJsInfo &formInfo) override; 75 76 /** 77 * @brief Add form with want, send want to form manager service. 78 * @param want The want of the form to add. 79 * @param runningFormInfo Running form info. 80 * @return Returns ERR_OK on success, others on failure. 81 */ 82 int CreateForm(const Want &want, RunningFormInfo &runningFormInfo) override; 83 84 /** 85 * @brief Delete forms with formIds, send formIds to form manager service. 86 * @param formId The Id of the forms to delete. 87 * @param callerToken Caller ability token. 88 * @return Returns ERR_OK on success, others on failure. 89 */ 90 int DeleteForm(const int64_t formId, const sptr<IRemoteObject> &callerToken) override; 91 92 /** 93 * @brief Stop rendering form. 94 * @param formId The Id of the forms to delete. 95 * @param compId The compId of the forms to delete. 96 * @return Returns ERR_OK on success, others on failure. 97 */ 98 int StopRenderingForm(const int64_t formId, const std::string &compId) override; 99 100 /** 101 * @brief Release forms with formIds, send formIds to form manager service. 102 * @param formId The Id of the forms to release. 103 * @param callerToken Caller ability token. 104 * @param delCache Delete Cache or not. 105 * @return Returns ERR_OK on success, others on failure. 106 */ 107 int ReleaseForm(const int64_t formId, const sptr<IRemoteObject> &callerToken, const bool delCache) override; 108 109 /** 110 * @brief Update form with formId, send formId to form manager service. 111 * @param formId The Id of the form to update. 112 * @param bundleName Provider ability bundleName. 113 * @param FormProviderData Form binding data. 114 * @return Returns ERR_OK on success, others on failure. 115 */ 116 int UpdateForm(const int64_t formId, const FormProviderData &FormProviderData) override; 117 118 /** 119 * @brief set next refresh time. 120 * @param formId The id of the form. 121 * @param nextTime next refresh time. 122 * @return Returns ERR_OK on success, others on failure. 123 */ 124 int SetNextRefreshTime(const int64_t formId, const int64_t nextTime) override; 125 126 /** 127 * @brief Release renderer. 128 * @param formId The Id of the forms to release. 129 * @param compId The compId of the forms to release. 130 * @return Returns ERR_OK on success, others on failure. 131 */ 132 int ReleaseRenderer(int64_t formId, const std::string &compId) override; 133 134 /** 135 * @brief Request to publish a form to the form host. 136 * 137 * @param want The want of the form to publish. 138 * @param withFormBindingData Indicates whether the formBindingData is carried with. 139 * @param formBindingData Indicates the form data. 140 * @param formId Return the form id to be published. 141 * @return Returns ERR_OK on success, others on failure. 142 */ 143 ErrCode RequestPublishForm(Want &want, bool withFormBindingData, 144 std::unique_ptr<FormProviderData> &formBindingData, int64_t &formId) override; 145 146 ErrCode SetPublishFormResult(const int64_t formId, Constants::PublishFormResult &errorCodeInfo) override; 147 148 ErrCode AcquireAddFormResult(const int64_t formId) override; 149 150 /** 151 * @brief Request to publish a form to the form host for normal authority. 152 * 153 * @param want The want of the form to publish. 154 * @param withFormBindingData Indicates whether the formBindingData is carried with. 155 * @param formBindingData Indicates the form data. 156 * @param formId Return the form id to be published. 157 * @return Returns ERR_OK on success, others on failure. 158 */ 159 ErrCode RequestPublishFormWithSnapshot(Want &want, bool withFormBindingData, 160 std::unique_ptr<FormProviderData> &formBindingData, int64_t &formId) override; 161 /** 162 * @brief lifecycle update. 163 * @param formIds formIds of host client. 164 * @param callerToken Caller ability token. 165 * @param updateType update type, enable if true and disable if false. 166 * @return Returns true on success, false on failure. 167 */ 168 int LifecycleUpdate(const std::vector<int64_t> &formIds, const sptr<IRemoteObject> &callerToken, 169 bool updateType) override; 170 171 /** 172 * @brief Request form with formId and want, send formId and want to form manager service. 173 * @param formId The Id of the form to update. 174 * @param callerToken Caller ability token. 175 * @param want The want of the form to add. 176 * @return Returns ERR_OK on success, others on failure. 177 */ 178 int RequestForm(const int64_t formId, const sptr<IRemoteObject> &callerToken, const Want &want) override; 179 180 /** 181 * @brief Form visible/invisible notify, send formIds to form manager service. 182 * @param formIds The Id list of the forms to notify. 183 * @param callerToken Caller ability token. 184 * @param formVisibleType The form visible type, including FORM_VISIBLE and FORM_INVISIBLE. 185 * @return Returns ERR_OK on success, others on failure. 186 */ 187 int NotifyWhetherVisibleForms(const std::vector<int64_t> &formIds, const sptr<IRemoteObject> &callerToken, 188 const int32_t formVisibleType) override; 189 190 /** 191 * @brief temp form to normal form. 192 * @param formId The Id of the form. 193 * @param callerToken Caller ability token. 194 * @return Returns ERR_OK on success, others on failure. 195 */ 196 int CastTempForm(const int64_t formId, const sptr<IRemoteObject> &callerToken) override; 197 198 /** 199 * @brief Query whether has visible form by tokenId. 200 * @param tokenId Unique identification of application. 201 * @return Returns true if has visible form, false otherwise. 202 */ 203 bool HasFormVisible(const uint32_t tokenId) override; 204 205 /** 206 * @brief Dump all of form storage infos. 207 * @param formInfos All of form storage infos. 208 * @return Returns ERR_OK on success, others on failure. 209 */ 210 int DumpStorageFormInfos(std::string &formInfos) override; 211 /** 212 * @brief Dump form info by a bundle name. 213 * @param bundleName The bundle name of form provider. 214 * @param formInfos Form infos. 215 * @return Returns ERR_OK on success, others on failure. 216 */ 217 int DumpFormInfoByBundleName(const std::string &bundleName, std::string &formInfos) override; 218 /** 219 * @brief Dump form info by a bundle name. 220 * @param formId The id of the form. 221 * @param formInfo Form info. 222 * @return Returns ERR_OK on success, others on failure. 223 */ 224 int DumpFormInfoByFormId(const std::int64_t formId, std::string &formInfo) override; 225 /** 226 * @brief Dump form timer by form id. 227 * @param formId The id of the form. 228 * @param formInfo Form info. 229 * @return Returns ERR_OK on success, others on failure. 230 */ 231 int DumpFormTimerByFormId(const std::int64_t formId, std::string &isTimingService) override; 232 /** 233 * @brief Process js message event. 234 * @param formId Indicates the unique id of form. 235 * @param want information passed to supplier. 236 * @param callerToken Caller ability token. 237 * @return Returns true if execute success, false otherwise. 238 */ 239 int MessageEvent(const int64_t formId, const Want &want, const sptr<IRemoteObject> &callerToken) override; 240 241 /** 242 * @brief Process js router event. 243 * @param formId Indicates the unique id of form. 244 * @param want the want of the ability to start. 245 * @param callerToken Caller ability token. 246 * @return Returns true if execute success, false otherwise. 247 */ 248 int RouterEvent(const int64_t formId, Want &want, const sptr<IRemoteObject> &callerToken) override; 249 250 /** 251 * @brief Process Background event. 252 * @param formId Indicates the unique id of form. 253 * @param want the want of the ability to start. 254 * @param callerToken Caller ability token. 255 * @return Returns true if execute success, false otherwise. 256 */ 257 int BackgroundEvent(const int64_t formId, Want &want, const sptr<IRemoteObject> &callerToken) override; 258 259 /** 260 * @brief Delete the invalid forms. 261 * @param formIds Indicates the ID of the valid forms. 262 * @param callerToken Caller ability token. 263 * @param numFormsDeleted Returns the number of the deleted forms. 264 * @return Returns ERR_OK on success, others on failure. 265 */ 266 virtual int DeleteInvalidForms(const std::vector<int64_t> &formIds, const sptr<IRemoteObject> &callerToken, 267 int32_t &numFormsDeleted) override; 268 269 /** 270 * @brief Acquire form state info by passing a set of parameters (using Want) to the form provider. 271 * @param want Indicates a set of parameters to be transparently passed to the form provider. 272 * @param callerToken Caller ability token. 273 * @param stateInfo Returns the form's state info of the specify. 274 * @return Returns ERR_OK on success, others on failure. 275 */ 276 virtual int AcquireFormState(const Want &want, const sptr<IRemoteObject> &callerToken, 277 FormStateInfo &stateInfo) override; 278 279 /** 280 * @brief Register form router event proxy. 281 * @param formIds Indicates the ID of the forms. 282 * @param callerToken Host client. 283 * @return Returns ERR_OK on success, others on failure. 284 */ 285 virtual ErrCode RegisterFormRouterProxy(const std::vector<int64_t> &formIds, 286 const sptr<IRemoteObject> &callerToken) override; 287 288 /** 289 * @brief Unregister form router event proxy. 290 * @param formIds Indicates the ID of the forms. 291 * @return Returns ERR_OK on success, others on failure. 292 */ 293 virtual ErrCode UnregisterFormRouterProxy(const std::vector<int64_t> &formIds) override; 294 295 /** 296 * @brief Notify the form is visible or not. 297 * @param formIds Indicates the ID of the forms. 298 * @param isVisible Visible or not. 299 * @param callerToken Host client. 300 * @return Returns ERR_OK on success, others on failure. 301 */ 302 virtual int NotifyFormsVisible(const std::vector<int64_t> &formIds, bool isVisible, 303 const sptr<IRemoteObject> &callerToken) override; 304 305 /** 306 * @brief Notify the form is privacy protected or not. 307 * @param formIds Indicates the ID of the forms. 308 * @param isProtected isProtected or not. 309 * @param callerToken Host client. 310 * @return Returns ERR_OK on success, others on failure. 311 */ 312 int NotifyFormsPrivacyProtected(const std::vector<int64_t> &formIds, bool isProtected, 313 const sptr<IRemoteObject> &callerToken) override; 314 315 /** 316 * @brief Notify the form is enable to be updated or not. 317 * @param formIds Indicates the ID of the forms. 318 * @param isEnableUpdate enable update or not. 319 * @param callerToken Host client. 320 * @return Returns ERR_OK on success, others on failure. 321 */ 322 virtual int NotifyFormsEnableUpdate(const std::vector<int64_t> &formIds, bool isEnableUpdate, 323 const sptr<IRemoteObject> &callerToken) override; 324 325 /** 326 * @brief Get All FormsInfo. 327 * @param formInfos Return the forms' information of all forms provided. 328 * @return Returns ERR_OK on success, others on failure. 329 */ 330 int GetAllFormsInfo(std::vector<FormInfo> &formInfos) override; 331 332 /** 333 * @brief Get forms info by bundle name . 334 * @param bundleName Application name. 335 * @param formInfos Return the forms' information of the specify application name. 336 * @return Returns ERR_OK on success, others on failure. 337 */ 338 int GetFormsInfoByApp(std::string &bundleName, std::vector<FormInfo> &formInfos) override; 339 340 /** 341 * @brief Get forms info by bundle name and module name. 342 * @param bundleName bundle name. 343 * @param moduleName Module name of hap. 344 * @param formInfos Return the forms' information of the specify bundle name and module name. 345 * @return Returns ERR_OK on success, others on failure. 346 */ 347 int GetFormsInfoByModule(std::string &bundleName, std::string &moduleName, 348 std::vector<FormInfo> &formInfos) override; 349 350 /** 351 * @brief This function is called by host and gets formsInfos info specifild by filter. 352 * @param filter Filter that contains necessary conditions, such as bundle name, module name, dimensions. 353 * @param formInfos Return the forms' information specified by filter. 354 * @return Returns ERR_OK on success, others on failure. 355 */ 356 int GetFormsInfoByFilter(const FormInfoFilter &filter, std::vector<FormInfo> &formInfos) override; 357 358 /** 359 * @brief This function is called by formProvider and gets forms info by the bundle name of the calling ability. 360 * The bundle name will be retrieved here. 361 * @param filter Filter that contains attributes that the formInfos have to have. 362 * @param formInfos Return the forms' information of the calling bundle name 363 * @return Returns ERR_OK on success, others on failure. 364 */ 365 int32_t GetFormsInfo(const FormInfoFilter &filter, std::vector<FormInfo> &formInfos) override; 366 367 /** 368 * @brief This function is called by formProvider and gets forms info by the formId of the calling ability. 369 * The formId will be retrieved here. 370 * @param formId Filter that contains attributes that the formInfos have to have. 371 * @param formInfo Return the forms' information of the calling formId 372 * @return Returns ERR_OK on success, others on failure. 373 */ 374 int32_t GetPublishedFormInfoById(const int64_t formId, RunningFormInfo &formInfo) override; 375 376 /** 377 * @brief This function is called by formProvider and gets forms info by the bundle name of the calling ability. 378 * The bundle name will be retrieved here. 379 * @param filter Filter that contains attributes that the formInfos have to have. 380 * @param formInfos Return the forms' information of the calling bundle name 381 * @return Returns ERR_OK on success, others on failure. 382 */ 383 int32_t GetPublishedFormInfos(std::vector<RunningFormInfo> &formInfos) override; 384 385 /** 386 * @brief Acquire form data by formId. 387 * @param formId The Id of the form to acquire data. 388 * @param callerToken Indicates the host client. 389 * @param requestCode The request code of this acquire form. 390 * @param formData Return the forms' information of customization 391 * @return Returns ERR_OK on success, others on failure. 392 */ 393 int32_t AcquireFormData(int64_t formId, int64_t requestCode, const sptr<IRemoteObject> &callerToken, 394 AAFwk::WantParams &formData) override; 395 396 /** 397 * @brief Check if the request of publishing a form is supported by the host. 398 * @return Returns true if the request is supported and false otherwise. 399 */ 400 bool IsRequestPublishFormSupported() override; 401 402 /** 403 * @brief Start an ability. This function can only be called by a form extension of a system app. 404 * @param want includes ability name, parameters and relative info sending to an ability. 405 * @param callerToken token of the ability that initially calls this function. 406 * @return Returns ERR_OK on success, others on failure. 407 */ 408 int32_t StartAbility(const Want &want, const sptr<IRemoteObject> &callerToken) override; 409 410 /** 411 * @brief Start an ability by form manager service. 412 * @param want includes ability name, parameters and relative info sending to an ability. 413 * @return Returns ERR_OK on success, others on failure. 414 */ 415 int32_t StartAbilityByFms(const Want &want) override; 416 417 /** 418 * @brief Share form by formID and deviceID. 419 * @param formId Indicates the unique id of form. 420 * @param deviceId Indicates the remote device ID. 421 * @param callerToken Indicates the host client. 422 * @param requestCode The request code of this share form. 423 * @return Returns ERR_OK on success, others on failure. 424 */ 425 int32_t ShareForm(int64_t formId, const std::string &deviceId, 426 const sptr<IRemoteObject> &callerToken, int64_t requestCode) override; 427 428 /** 429 * @brief Receive form sharing information from remote. 430 * @param info Indicates form sharing information. 431 * @return Returns ERR_OK on success, others on failure. 432 */ 433 int32_t RecvFormShareInfoFromRemote(const FormShareInfo &info) override; 434 435 /** 436 * @brief Dump form. 437 * @param fd Indicates the file descriptor for result. 438 * @param args Indicates the input arguments. 439 * @return Returns ERR_OK on success, others on failure. 440 */ 441 int Dump(int fd, const std::vector<std::u16string> &args) override; 442 443 /** 444 * @brief Register form add observer by bundle. 445 * @param bundleName BundleName of the form host 446 * @param callerToken Caller ability token. 447 * @return Returns ERR_OK on success, others on failure. 448 */ 449 ErrCode RegisterFormAddObserverByBundle(const std::string bundleName, 450 const sptr<IRemoteObject> &callerToken) override; 451 452 /** 453 * @brief Register form remove observer by bundle. 454 * @param bundleName BundleName of the form host 455 * @param callerToken Caller ability token. 456 * @return Returns ERR_OK on success, others on failure. 457 */ 458 ErrCode RegisterFormRemoveObserverByBundle(const std::string bundleName, 459 const sptr<IRemoteObject> &callerToken) override; 460 461 /** 462 * @brief Check form manager service ready. 463 * @return Return true if form manager service Ready; return false otherwise. 464 */ 465 bool CheckFMSReady() override; 466 467 /** 468 * @brief Check whether the form is system app. 469 * @param bundleName The bundleName of the form. 470 * @return Returns true if the form app is system, others false. 471 */ 472 bool IsSystemAppForm(const std::string &bundleName) override; 473 474 /** 475 * @brief The Call Event triggers the callee method. 476 * @param funcName function name which is used by callee. 477 * @param params parameter which is used by callee. 478 * @return Returns ERR_OK on success, others on failure. 479 */ SetBackgroundFunction(const std::string funcName,const std::string params)480 int32_t SetBackgroundFunction(const std::string funcName, const std::string params) override 481 { 482 return ERR_OK; 483 } 484 /** 485 * @brief get forms count. 486 * @param isTempFormFlag Indicates temp form or not. 487 * @param formCount Returns the number of the cast or temp form. 488 * @return Returns ERR_OK on success, others on failure. 489 */ 490 int32_t GetFormsCount(bool isTempFormFlag, int32_t &formCount) override; 491 492 /** 493 * @brief get host forms count. 494 * @param bundleName Indicates form host bundleName. 495 * @param formCount Returns the number of the host form. 496 * @return Returns ERR_OK on success, others on failure. 497 */ 498 int32_t GetHostFormsCount(std::string &bundleName, int32_t &formCount) override; 499 500 /** 501 * @brief Get all running form infos. 502 * @param isUnusedIncluded Indicates whether to include unused forms. 503 * @param runningFormInfos Return the running forms' infos currently. 504 * @return Returns ERR_OK on success, others on failure. 505 */ 506 ErrCode GetRunningFormInfos(bool isUnusedIncluded, std::vector<RunningFormInfo> &runningFormInfos) override; 507 508 /** 509 * @brief Get the running form infos by bundle name. 510 * @param bundleName Application name. 511 * @param isUnusedIncluded Indicates whether to include unused forms. 512 * @param runningFormInfos Return the running forms' infos of the specify application name. 513 * @return Returns ERR_OK on success, others on failure. 514 */ 515 ErrCode GetRunningFormInfosByBundleName( 516 const std::string &bundleName, bool isUnusedIncluded, std::vector<RunningFormInfo> &runningFormInfos) override; 517 518 /** 519 * @brief Get form instances by filter info. 520 * @param formInstancesFilter include bundleName, moduleName, formName, abilityName to get formInstances. 521 * @param formInstances return formInstances 522 * @return return ERR_OK on get info success,other on failure. 523 */ 524 ErrCode GetFormInstancesByFilter(const FormInstancesFilter &formInstancesFilter, 525 std::vector<FormInstance> &formInstances) override; 526 527 /** 528 * @brief Get form instances by formId. 529 * @param formId formId Indicates the unique id of form. 530 * @param formInstance return formInstance 531 * @return return ERR_OK on get info success, others on failure. 532 */ 533 ErrCode GetFormInstanceById(const int64_t formId, FormInstance &formInstance) override; 534 535 /** 536 * @brief Get form instance by formId, include form store in DB. 537 * @param formId formId Indicates the unique id of form. 538 * @param isUnusedIncluded Indicates whether to include unused form instances. 539 * @param formInstance return formInstance 540 * @return return ERR_OK on get info success, others on failure. 541 */ 542 ErrCode GetFormInstanceById(const int64_t formId, bool isUnusedIncluded, FormInstance &formInstance) override; 543 544 /** 545 * @brief Register form add observer. 546 * @param bundleName BundleName of the form host 547 * @param callerToken Caller ability token. 548 * @return Returns ERR_OK on success, others on failure. 549 */ 550 ErrCode RegisterAddObserver(const std::string &bundleName, const sptr<IRemoteObject> &callerToken) override; 551 552 /** 553 * @brief Register form remove observer. 554 * @param bundleName BundleName of the form host 555 * @param callerToken Caller ability token. 556 * @return Returns ERR_OK on success, others on failure. 557 */ 558 ErrCode RegisterRemoveObserver(const std::string &bundleName, const sptr<IRemoteObject> &callerToken) override; 559 560 /** 561 * @brief Update proxy form with formId. 562 * @param formId The Id of the form to update. 563 * @param FormProviderData Form binding data. 564 * @param std::vector<FormDataProxy> Form proxy vector. 565 * @return Returns ERR_OK on success, others on failure. 566 */ 567 ErrCode UpdateProxyForm(int64_t formId, const FormProviderData &FormProviderData, 568 const std::vector<FormDataProxy> &formDataProxies) override; 569 570 /** 571 * @brief Request to publish a proxy form to the form host. 572 * @param want The want of the form to publish. 573 * @param withFormBindingData Indicates whether the formBindingData is carried with. 574 * @param formBindingData Indicates the form data. 575 * @param formId Return the form id to be published. 576 * @param std::vector<FormDataProxy> Form proxy vector. 577 * @return Returns ERR_OK on success, others on failure. 578 */ 579 ErrCode RequestPublishProxyForm(Want &want, bool withFormBindingData, 580 std::unique_ptr<FormProviderData> &formBindingData, int64_t &formId, 581 const std::vector<FormDataProxy> &formDataProxies) override; 582 583 /** 584 * @brief Read the form_config.xml. 585 * @return Returns ERR_OK on success, others on failure. 586 */ 587 ErrCode ReadFormConfigXML(); 588 589 /** 590 * @brief Registers the callback for publish form. The callback is used to process the publish form request 591 * when the system handler is not found. 592 * @param interceptorCallback The injected callback, should implementation IFormPublishInterceptor. 593 * @return Returns ERR_OK on success, others on failure. 594 */ 595 int32_t RegisterPublishFormInterceptor(const sptr<IRemoteObject> &interceptorCallback) override; 596 597 /** 598 * @brief Unregisters the callback for publish form. The callback is used to process the publish form request 599 * when the system handler is not found. 600 * @param interceptorCallback The injected callback, should implementation IFormPublishInterceptor. 601 * @return Returns ERR_OK on success, others on failure. 602 */ 603 int32_t UnregisterPublishFormInterceptor(const sptr<IRemoteObject> &interceptorCallback) override; 604 605 /** 606 * @brief Register click callback observer. 607 * @param observer Form click event callback listener. 608 * @param bundleName BundleName of the form host. 609 * @param formEventType Form event type. 610 * @return Returns ERR_OK on success, others on failure. 611 */ 612 ErrCode RegisterClickEventObserver( 613 const std::string &bundleName, const std::string &formEventType, const sptr<IRemoteObject> &observer) override; 614 615 /** 616 * @brief Unregister click callback observer. 617 * @param bundleName BundleName of the form host. 618 * @param formEventType Form event type. 619 * @param observer Form click event callback listener. 620 * @return Returns ERR_OK on success, others on failure. 621 */ 622 ErrCode UnregisterClickEventObserver( 623 const std::string &bundleName, const std::string &formEventType, const sptr<IRemoteObject> &observer) override; 624 625 /** 626 * @brief Set forms recyclable 627 * @param formIds Indicates the id of the forms. 628 * @return Returns ERR_OK on success, others on failure. 629 */ 630 int32_t SetFormsRecyclable(const std::vector<int64_t> &formIds) override; 631 632 /** 633 * @brief Recycle forms 634 * @param formIds Indicates the id of the forms. 635 * @param want The want of forms to be recycled. 636 * @return Returns ERR_OK on success, others on failure. 637 */ 638 int32_t RecycleForms(const std::vector<int64_t> &formIds, const Want &want) override; 639 640 /** 641 * @brief Recover recycled forms 642 * @param formIds Indicates the id of the forms. 643 * @param want The want of forms to be recovered. 644 * @return Returns ERR_OK on success, others on failure. 645 */ 646 int32_t RecoverForms(const std::vector<int64_t> &formIds, const Want &want) override; 647 648 /** 649 * @brief Update formLocation with formId. 650 * @param formId The Id of the form to update. 651 * @param formLocation The FormLocation. 652 * @return Returns ERR_OK on success, others on failure. 653 */ 654 ErrCode UpdateFormLocation(const int64_t &formId, const int32_t &formLocation) override; 655 656 /** 657 * @brief Update form with formRefreshType, send to form manager service. 658 * @param formRefreshType The type of the form to refresh, 0: AllForm 1: 2: AppForm 2: AtomicServiceForm 659 * @return Returns ERR_OK on success, others on failure. 660 */ 661 ErrCode BatchRefreshForms(const int32_t formRefreshType) override; 662 663 #ifdef RES_SCHEDULE_ENABLE 664 /** 665 * @brief Update refresh_Timer_task_needed_flag depend on the systemload level. 666 * @param level The value of the systemload level. 667 */ 668 void OnSystemloadLevel(int32_t level); 669 #endif // RES_SCHEDULE_ENABLE 670 671 /** 672 * @brief enable/disable form update. 673 * @param bundleName BundleName of the form host. 674 * @param enable True for enable form, false for disable form. 675 * @return Returns ERR_OK on success, others on failure. 676 */ 677 int32_t EnableForms(const std::string bundleName, const bool enable) override; 678 679 /** 680 * @brief Check form bundle is controlled. 681 * @param bundleName The bundle name of form to be check. 682 * @return Returns true for form bundle is controlled. 683 */ 684 bool IsFormBundleForbidden(const std::string &bundleName) override; 685 686 /** 687 * @brief lock/unlock form update. 688 * @param formLockInfos Indicates the lockForm data. 689 * @param type Indicates the Lock Type. 690 * @return Returns ERR_OK on success, others on failure. 691 */ 692 int32_t LockForms(const std::vector<FormLockInfo> &formLockInfos, LockChangeType type) override; 693 694 /** 695 * @brief Check form bundle is lock. 696 * @param bundleName The bundle name of form to be check. 697 * @param formId The Id of the form to query. 698 * @return Returns true for form bundle is lock. 699 */ 700 bool IsFormBundleProtected(const std::string &bundleName, int64_t formId) override; 701 702 /** 703 * @brief Check form bundle is exempt. 704 * @param formId The Id of the form to query. 705 * @return Returns true for form bundle is exempt. 706 */ 707 bool IsFormBundleExempt(int64_t formId) override; 708 709 /** 710 * @brief Notify the form is locked or not. 711 * @param formId Indicates the ID of the form. 712 * @param isLocked locked or not. 713 * @return Returns ERR_OK on success, others on failure. 714 */ 715 int32_t NotifyFormLocked(const int64_t &formId, bool isLocked) override; 716 717 /** 718 * @brief Update form size. 719 * @param formId The Id of the form to update. 720 * @param width The width value to be updated. 721 * @param height The height value to be updated. 722 * @param borderWidth The borderWidth value to be updated. 723 * @return Returns ERR_OK on success, others on failure. 724 */ 725 ErrCode UpdateFormSize(const int64_t &formId, float width, float height, float borderWidth) override; 726 727 void SubscribeNetConn(); 728 729 /** 730 * @brief Handle open form edit ability. 731 * @param abilityName The form edit ability name. 732 * @param formId The edit form ID. 733 * @param isMainPage Open the main edit page. 734 * @return Returns ERR_OK on success, others on failure. 735 */ 736 ErrCode OpenFormEditAbility(const std::string &abilityName, const int64_t &formId, bool isMainPage) override; 737 738 friend class NetConnCallbackObserver; 739 private: 740 /** 741 * OnAddSystemAbility, OnAddSystemAbility will be called when the listening SA starts. 742 * 743 * @param systemAbilityId, The said being listened to. 744 * @param deviceId, deviceId is empty. 745 * @return void. 746 */ 747 virtual void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; 748 749 enum class DumpKey { 750 KEY_DUMP_HELP = 0, 751 KEY_DUMP_STORAGE, 752 KEY_DUMP_BY_BUNDLE_NAME, 753 KEY_DUMP_BY_FORM_ID, 754 KEY_DUMP_TEMPORARY, 755 KEY_DUMP_STATIC, 756 KEY_DUMP_VISIBLE, 757 KEY_DUMP_RUNNING, 758 KEY_DUMP_BLOCKED_APPS, 759 }; 760 /** 761 * @brief initialization of form manager service. 762 */ 763 ErrCode Init(); 764 765 ErrCode CheckFormPermission( 766 const std::string &permission = AppExecFwk::Constants::PERMISSION_REQUIRE_FORM); 767 768 bool CheckAcrossLocalAccountsPermission() const; 769 770 void InitFormShareMgrSerialQueue(); 771 772 void Dump(const std::vector<std::u16string> &args, std::string &result); 773 bool ParseOption(const std::vector<std::u16string> &args, DumpKey &key, std::string &value, std::string &result); 774 void HiDumpHelp([[maybe_unused]] const std::string &args, std::string &result); 775 void HiDumpStorageFormInfos([[maybe_unused]] const std::string &args, std::string &result); 776 void HiDumpTemporaryFormInfos([[maybe_unused]] const std::string &args, std::string &result); 777 void HiDumpStaticBundleFormInfos([[maybe_unused]] const std::string &args, std::string &result); 778 void HiDumpHasFormVisible(const std::string &args, std::string &result); 779 void HiDumpFormInfoByBundleName(const std::string &args, std::string &result); 780 void HiDumpFormInfoByFormId(const std::string &args, std::string &result); 781 void HiDumpFormRunningFormInfos([[maybe_unused]] const std::string &args, std::string &result); 782 void HiDumpFormBlockedApps([[maybe_unused]] const std::string &args, std::string &result); 783 bool CheckCallerIsSystemApp() const; 784 static std::string GetCurrentDateTime(); 785 void SetNetConnect(); 786 void SetDisConnectTypeTime(); 787 788 private: 789 static const int32_t ENABLE_FORM_UPDATE = 5; 790 const static std::map<std::string, DumpKey> dumpKeyMap_; 791 std::string onStartBeginTime_; 792 std::string onStartPublishTime_; 793 std::string onStartEndTime_; 794 std::string onKvDataServiceAddTime_; 795 ServiceRunningState state_ = ServiceRunningState::STATE_NOT_START; 796 std::shared_ptr<FormEventHandler> handler_ = nullptr; 797 std::shared_ptr<FormSerialQueue> serialQueue_ = nullptr; 798 std::shared_ptr<FormSysEventReceiver> formSysEventReceiver_ = nullptr; 799 uint32_t NetSceneCallbackId_ = 0; 800 int32_t netConTime = 0; 801 int64_t lastNetLostTime_ = FormUtil::GetCurrentMillisecond(); 802 mutable std::mutex instanceMutex_; 803 DISALLOW_COPY_AND_MOVE(FormMgrService); 804 #ifdef MEM_MGR_ENABLE 805 std::shared_ptr<MemStatusListener> memStatusListener_ = nullptr; 806 #endif 807 void SubscribeSysEventReceiver(); 808 809 /** 810 * @brief report add form event 811 * @param formId Indicates the id of form. 812 * @param want The want of form. 813 */ 814 void ReportAddFormEvent(const int64_t formId, const Want &want); 815 }; 816 } // namespace AppExecFwk 817 } // namespace OHOS 818 #endif // OHOS_FORM_FWK_FORM_MGR_SERVICE_H 819