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_FORM_DATA_MGR_H 17 #define OHOS_FORM_FWK_FORM_FORM_DATA_MGR_H 18 19 #include <map> 20 #include <mutex> 21 #include <set> 22 #include <singleton.h> 23 #include <string> 24 25 #include "bundle_pack_info.h" 26 #include "form_constants.h" 27 #include "form_host_record.h" 28 #include "form_id_key.h" 29 #include "form_info.h" 30 #include "form_instance.h" 31 #include "form_instances_filter.h" 32 #include "form_item_info.h" 33 #include "form_js_info.h" 34 #include "form_record.h" 35 #include "form_state_info.h" 36 #include "iremote_object.h" 37 #include "libxml/parser.h" 38 #include "libxml/tree.h" 39 #include "running_form_info.h" 40 41 namespace OHOS { 42 namespace AppExecFwk { 43 using Want = AAFwk::Want; 44 45 /** 46 * @class FormDataMgr 47 * form data manager. 48 */ 49 class FormDataMgr final : public DelayedRefSingleton<FormDataMgr> { 50 DECLARE_DELAYED_REF_SINGLETON(FormDataMgr) 51 public: 52 DISALLOW_COPY_AND_MOVE(FormDataMgr); 53 /** 54 * @brief Allot form info by item info. 55 * @param formInfo Form item info. 56 * @param callingUid The UID of the proxy. 57 * @param userId User ID. 58 * @return Returns form record. 59 */ 60 FormRecord AllotFormRecord(const FormItemInfo &formInfo, const int callingUid, 61 const int32_t userId = Constants::DEFAULT_USER_ID); 62 /** 63 * @brief Create form js info by form record. 64 * @param formId The Id of the form. 65 * @param record Form record. 66 * @param formInfo Js info. 67 */ 68 void CreateFormJsInfo(const int64_t formId, const FormRecord &record, FormJsInfo &formInfo); 69 /** 70 * @brief Delete form js info by form record. 71 * @param formId The Id of the form. 72 * @return Returns true if this function is successfully called; returns false otherwise. 73 */ 74 bool DeleteFormRecord(const int64_t formId); 75 /** 76 * @brief Clean removed forms for host. 77 * @param removedFormIds The id list of the forms. 78 */ 79 void CleanHostRemovedForms(const std::vector<int64_t> &removedFormIds); 80 /** 81 * @brief Allot form host record by caller token. 82 * @param info The form item info. 83 * @param callerToken callerToken 84 * @param formId The Id of the form. 85 * @param callingUid The UID of the proxy. 86 * @return Returns true if this function is successfully called; returns false otherwise. 87 */ 88 bool AllotFormHostRecord(const FormItemInfo &info, const sptr<IRemoteObject> &callerToken, 89 const int64_t formId, const int callingUid); 90 /** 91 * @brief Check temp form count is max. 92 * @return Returns ERR_OK if the temp form not reached; returns ERR_MAX_SYSTEM_TEMP_FORMS is reached. 93 */ 94 int CheckTempEnoughForm() const; 95 /** 96 * @brief Check form count is max. 97 * @param currentUserId The current userId. 98 * @param callingUid The UID of the proxy. 99 * @return Returns true if this function is successfully called; returns false otherwise. 100 */ 101 int CheckEnoughForm(const int callingUid, const int32_t currentUserId = Constants::DEFAULT_USER_ID) const; 102 /** 103 * @brief Delete temp form. 104 * @param formId The Id of the form. 105 * @return Returns true if this function is successfully called; returns false otherwise. 106 */ 107 bool DeleteTempForm(const int64_t formId); 108 /** 109 * @brief Check temp form is exist. 110 * @param formId The Id of the form. 111 * @return Returns true if the temp form is exist; returns false is not exist. 112 */ 113 bool ExistTempForm(const int64_t formId) const; 114 /** 115 * @brief Modify form temp flag by formId. 116 * @param formId The Id of the form. 117 * @param formTempFlag The form temp flag. 118 * @return Returns true if this function is successfully called; returns false otherwise. 119 */ 120 bool ModifyFormTempFlag(const int64_t formId, const bool formTempFlag); 121 /** 122 * @brief Add form user uid from form record. 123 * @param formId The Id of the form. 124 * @param formUserUid The form user uid. 125 * @return Returns true if this function is successfully called; returns false otherwise. 126 */ 127 bool AddFormUserUid(const int64_t formId, const int formUserUid); 128 /** 129 * @brief Delete form user uid from form record. 130 * @param formId The Id of the form. 131 * @param uid calling user id. 132 * @return Returns true if this function is successfully called; returns false otherwise. 133 */ 134 bool DeleteFormUserUid(const int64_t formId, const int uid); 135 /** 136 * @brief Update form record. 137 * @param formId The Id of the form. 138 * @param formRecord The form record. 139 * @return Returns true if this function is successfully called; returns false otherwise. 140 */ 141 bool UpdateFormRecord(const int64_t formId, const FormRecord &formRecord); 142 /** 143 * @brief Get form record. 144 * @param formId The Id of the form. 145 * @param formRecord The form record. 146 * @return Returns true if this function is successfully called; returns false otherwise. 147 */ 148 bool GetFormRecord(const int64_t formId, FormRecord &formRecord) const; 149 /** 150 * @brief Get form record. 151 * @param bundleName Bundle name. 152 * @param formInfos The form record list. 153 * @return Returns true if this function is successfully called; returns false otherwise. 154 */ 155 bool GetFormRecord(const std::string &bundleName, std::vector<FormRecord> &formInfos, 156 int32_t userId = Constants::INVALID_USER_ID) const; 157 /** 158 * @brief Get temporary form record. 159 * @param formTempRecords The temp form record. 160 * @return Returns true if this function is successfully called; returns false otherwise. 161 */ 162 bool GetTempFormRecord(std::vector<FormRecord> &formTempRecords); 163 /** 164 * @brief Check form record is exist. 165 * @param formId The Id of the form. 166 * @return Returns true if the form record is exist; returns false is not exist. 167 */ 168 bool ExistFormRecord(const int64_t formId) const; 169 /** 170 * @brief Has form user uids in form record. 171 * @param formId The Id of the form. 172 * @return Returns true if this form has form user uids; returns false is not has. 173 */ 174 bool HasFormUserUids(const int64_t formId) const; 175 /** 176 * @brief Get form host record. 177 * @param formId The id of the form. 178 * @param formHostRecords The form host records. 179 */ 180 void GetFormHostRecord(const int64_t formId, std::vector<FormHostRecord> &formHostRecords) const; 181 /** 182 * @brief Get form host remote object. 183 * @param formId The id of the form. 184 * @param formHostObjs The form host remote object. 185 */ 186 void GetFormHostRemoteObj(const int64_t formId, std::vector<sptr<IRemoteObject>> &formHostObjs) const; 187 /** 188 * @brief Delete form host record. 189 * @param callerToken The client stub of the form host record. 190 * @param formId The id of the form. 191 * @return Returns true if this function is successfully called; returns false otherwise. 192 */ 193 bool DeleteHostRecord(const sptr<IRemoteObject> &callerToken, const int64_t formId); 194 /** 195 * @brief Handle form host died. 196 * @param remoteHost Form host proxy object. 197 */ 198 void HandleHostDied(const sptr<IRemoteObject> &remoteHost); 199 /** 200 * @brief Refresh enable or not. 201 * @param formId The Id of the form. 202 * @return true on enable, false on disable. 203 */ 204 bool IsEnableRefresh(int64_t formId); 205 /** 206 * @brief update enable or not. 207 * @param formId The Id of the form. 208 * @return true on enable, false on disable. 209 */ 210 bool IsEnableUpdate(int64_t formId); 211 /** 212 * @brief Check calling uid is valid. 213 * @param formUserUids The form user uids. 214 * @return Returns true if this user uid is valid; returns false otherwise. 215 */ 216 bool IsCallingUidValid(const std::vector<int> &formUserUids) const; 217 /** 218 * @brief Generate udid. 219 * @return Returns true if this function is successfully called; returns false otherwise. 220 */ 221 bool GenerateUdidHash(); 222 /** 223 * @brief Padding udid hash. 224 * @param formId The form id. 225 * @return Padded form id. 226 */ 227 int64_t PaddingUdidHash(int64_t formId); 228 /** 229 * @brief Generate form id. 230 * @return form id. 231 */ 232 int64_t GenerateFormId(); 233 /** 234 * @brief Get udid. 235 * @return udid. 236 */ 237 int64_t GetUdidHash() const; 238 /** 239 * @brief Set udid. 240 * @param udidHash udid. 241 */ 242 void SetUdidHash(const int64_t udidHash); 243 244 /** 245 * @brief Get the matched form host record by client stub. 246 * 247 * @param callerToken The client stub of the form host record. 248 * @param formHostRecord The form host record. 249 * @return Returns true if this function is successfully called, returns false otherwise. 250 */ 251 bool GetMatchedHostClient(const sptr<IRemoteObject> &callerToken, FormHostRecord &formHostRecord) const; 252 253 /** 254 * @brief Set needRefresh for FormRecord. 255 * @param formId The Id of the form. 256 * @param needRefresh true or false. 257 */ 258 void SetNeedRefresh(const int64_t formId, const bool needRefresh); 259 /** 260 * @brief Set isCountTimerRefresh for FormRecord. 261 * @param formId The Id of the form. 262 * @param countTimerRefresh true or false. 263 */ 264 void SetCountTimerRefresh(const int64_t formId, const bool countTimerRefresh); 265 266 /** 267 * @brief Set timerRefresh for FormRecord. 268 * @param formId The Id of the form. 269 * @param timerRefresh true or false. 270 */ 271 void SetTimerRefresh(const int64_t formId, const bool timerRefresh); 272 273 /** 274 * @brief Get updated form info. 275 * @param record FormRecord. 276 * @param targetForms Target forms. 277 * @param updatedForm Updated form info. 278 * @return Returns true on success, false on failure. 279 */ 280 bool GetUpdatedForm(const FormRecord &record, const std::vector<FormInfo> &targetForms, FormInfo &updatedForm); 281 /** 282 * @brief Set isEnableUpdate for FormRecord. 283 * @param formId The Id of the form. 284 * @param enableUpdate true or false. 285 */ 286 void SetEnableUpdate(const int64_t formId, const bool enableUpdate); 287 /** 288 * @brief Set update info for FormRecord. 289 * @param formId The Id of the form. 290 * @param enableUpdate true or false. 291 * @param updateDuration Update duration. 292 * @param updateAtHour Update at hour. 293 * @param updateAtMin Update at minute. 294 */ 295 void SetUpdateInfo(const int64_t formId, const bool enableUpdate, const long updateDuration, 296 const int updateAtHour, const int updateAtMin); 297 /** 298 * @brief Clean removed form records. 299 * @param bundleName BundleName. 300 * @param removedForms The id list of the forms. 301 */ 302 void CleanRemovedFormRecords(const std::string &bundleName, std::set<int64_t> &removedForms); 303 /** 304 * @brief Clean removed temp form records. 305 * @param bundleName BundleName. 306 * @param removedForms The id list of the forms. 307 */ 308 void CleanRemovedTempFormRecords(const std::string &bundleName, const int32_t userId, 309 std::set<int64_t> &removedForms); 310 /** 311 * @brief Get recreate form records. 312 * @param reCreateForms The id list of the forms. 313 */ 314 void GetReCreateFormRecordsByBundleName(const std::string &bundleName, std::set<int64_t> &reCreateForms); 315 /** 316 * @brief Set form isInited = true. 317 * @param formId The Id of the form. 318 * @param isInited isInited property 319 */ 320 void SetFormCacheInited(const int64_t formId, const bool isInited); 321 /** 322 * @brief Set versionUpgrade. 323 * @param formId The Id of the form. 324 * @param versionUpgrade true or false 325 */ 326 void SetVersionUpgrade(const int64_t formId, const bool versionUpgrade); 327 /** 328 * @brief Update form for host clients. 329 * @param formId The Id of the form. 330 * @param needRefresh true or false 331 */ 332 void UpdateHostNeedRefresh(const int64_t formId, const bool needRefresh); 333 /** 334 * @brief Update form for host clients. 335 * @param formId The Id of the form. 336 * @param formRecord The form info. 337 * @return Returns true if form update, false if other. 338 */ 339 bool UpdateHostForm(const int64_t formId, const FormRecord &formRecord); 340 /** 341 * @brief handle update form flag. 342 * @param formIDs The id of the forms. 343 * @param callerToken Caller ability token. 344 * @param flag form flag. 345 * @param isOnlyEnableUpdate form enable update form flag. 346 * @param refreshForms Refresh forms 347 * @return Returns ERR_OK on success, others on failure. 348 */ 349 ErrCode UpdateHostFormFlag(const std::vector<int64_t> &formIds, const sptr<IRemoteObject> &callerToken, 350 bool flag, bool isOnlyEnableUpdate, std::vector<int64_t> &refreshForms); 351 /** 352 * @brief Find matched form id. 353 * @param formId The form id. 354 * @return Matched form id. 355 */ 356 int64_t FindMatchedFormId(const int64_t formId); 357 /** 358 * @brief Clear host data by uId. 359 * @param uId The caller uId. 360 */ 361 void ClearHostDataByUId(const int uId); 362 /** 363 * @brief Get no host temp forms. 364 * @param uid The caller uid. 365 * @param noHostTempFormsMap no host temp forms. 366 * @param foundFormsMap Form Id list. 367 */ 368 void GetNoHostTempForms(const int uid, std::map<FormIdKey, std::set<int64_t>> &noHostTempFormsMap, 369 std::map<int64_t, bool> &foundFormsMap); 370 371 /** 372 * @brief delete forms by userId. 373 * 374 * @param userId user ID. 375 * @param removedFormIds removed userId. 376 */ 377 void DeleteFormsByUserId(const int32_t userId, std::vector<int64_t> &removedFormIds); 378 /** 379 * @brief Clear form records for st limit value test. 380 */ 381 void ClearFormRecords(); 382 383 /** 384 * @brief handle get no host invalid temp forms. 385 * @param userId User ID. 386 * @param callingUid The UID of the proxy. 387 * @param matchedFormIds The set of the valid forms. 388 * @param noHostTempFormsMap The map of the no host forms. 389 * @param foundFormsMap The map of the found forms. 390 */ 391 void GetNoHostInvalidTempForms(int32_t userId, int32_t callingUid, std::set<int64_t> &matchedFormIds, 392 std::map<FormIdKey, std::set<int64_t>> &noHostTempFormsMap, 393 std::map<int64_t, bool> &foundFormsMap); 394 395 /** 396 * @brief handle delete no host temp forms. 397 * @param callingUid The UID of the proxy. 398 * @param noHostTempFormsMap The map of the no host forms. 399 * @param foundFormsMap The map of the found forms. 400 */ 401 void BatchDeleteNoHostTempForms(int32_t callingUid, std::map<FormIdKey, std::set<int64_t>> &noHostTempFormsMap, 402 std::map<int64_t, bool> &foundFormsMap); 403 404 /** 405 * @brief delete invalid temp forms. 406 * @param userId User ID. 407 * @param callingUid The UID of the proxy. 408 * @param matchedFormIds The set of the valid forms. 409 * @param removedFormsMap The map of the removed invalid forms. 410 * @return Returns ERR_OK on success, others on failure. 411 */ 412 int32_t DeleteInvalidTempForms(int32_t userId, int32_t callingUid, std::set<int64_t> &matchedFormIds, 413 std::map<int64_t, bool> &removedFormsMap); 414 415 /** 416 * @brief clear host data by invalid forms. 417 * @param callingUid The UID of the proxy. 418 * @param removedFormsMap The map of the removed invalid forms. 419 * @return Returns ERR_OK on success, others on failure. 420 */ 421 int32_t ClearHostDataByInvalidForms(int32_t callingUid, std::map<int64_t, bool> &removedFormsMap); 422 423 /** 424 * @brief delete publish forms temp data 425 * @param userId User ID. 426 * @param bundleName BundleName. 427 * @param validFormIds The set of the valid forms. 428 * @return Returns - 429 */ 430 void DeleteInvalidPublishForms(int32_t userId, std::string bundleName, std::set<int64_t> &validFormIds); 431 432 /** 433 * @brief Create form acquire data host record. 434 * @param requestCode The request code of this acquire form. 435 * @param info The form item info. 436 * @param callerToken Caller ability token. 437 * @param callingUid The UID of the proxy. 438 * @return Returns true if this function is successfully called; returns false otherwise. 439 */ 440 bool CreateFormAcquireDataRecord(int64_t requestCode, const FormItemInfo &info, 441 const sptr<IRemoteObject> &callerToken, int callingUid); 442 443 /** 444 * @brief Create form state host record. 445 * @param provider The provider of the form state 446 * @param info The form item info. 447 * @param callerToken The UID of the proxy. 448 * @param callingUid The UID of the proxy. 449 * @return Returns true if this function is successfully called; returns false otherwise. 450 */ 451 bool CreateFormStateRecord(std::string &provider, const FormItemInfo &info, const sptr<IRemoteObject> &callerToken, 452 int callingUid); 453 454 /** 455 * @brief acquire form state callback. 456 * @param state form state. 457 * @param provider provider info. 458 * @param want The want of onAcquireFormState. 459 * @return Returns true if this function is successfully called; returns false otherwise. 460 */ 461 ErrCode AcquireFormStateBack(AppExecFwk::FormState state, const std::string &provider, const Want &want); 462 463 /** 464 * @brief acquire form data callback. 465 * @param wantParams Indicates the data information acquired by the form. 466 * @param requestCode Indicates the requested id. 467 * @return Returns true if this function is successfully called; returns false otherwise. 468 */ 469 ErrCode AcquireFormDataBack(const AAFwk::WantParams &wantParams, int64_t requestCode); 470 471 /** 472 * @brief Notify the form is visible or not. 473 * @param formIds Indicates the ID of the forms. 474 * @param isVisible Visible or not. 475 * @param callerToken Host client. 476 * @return Returns ERR_OK on success, others on failure. 477 */ 478 ErrCode NotifyFormsVisible(const std::vector<int64_t> &formIds, bool isVisible, 479 const sptr<IRemoteObject> &callerToken); 480 481 /** 482 * @brief set form record visible. 483 * @param matchedFormId form id. 484 * @param isVisible is visible. 485 * @return Returns true if this function is successfully called; returns false otherwise. 486 */ 487 ErrCode SetRecordVisible(int64_t matchedFormId, bool isVisible); 488 489 /** 490 * @brief add request publish form info. 491 * @param formId The form id of the form to publish. 492 * @param want The want of the form to publish. 493 * @param formProviderData The form data. 494 * @return Returns ERR_OK on success, others on failure. 495 */ 496 ErrCode AddRequestPublishFormInfo(int64_t formId, const Want &want, 497 std::unique_ptr<FormProviderData> &formProviderData); 498 499 /** 500 * @brief remove request publish form info. 501 * @param formId The form id of the form to publish. 502 * @return Returns true if this function is successfully called; returns false otherwise. 503 */ 504 ErrCode RemoveRequestPublishFormInfo(int64_t formId); 505 506 /** 507 * @brief check whether request publish form info. 508 * @param formId The form id of the form to publish. 509 * @return Returns true if this function is successfully called; returns false otherwise. 510 */ 511 bool IsRequestPublishForm(int64_t formId); 512 513 /** 514 * @brief get request publish form info. 515 * @param formId The form id of the form to publish. 516 * @param want The want of the form to publish. 517 * @param formProviderData The form data. 518 * @return Returns true if this function is successfully called; returns false otherwise. 519 */ 520 ErrCode GetRequestPublishFormInfo(int64_t formId, Want &want, 521 std::unique_ptr<FormProviderData> &formProviderData); 522 /** 523 * @brief Get updated form info. 524 * @param record Indicates the form record. 525 * @param bundlePackInfo Indicates the BundlePackInfo object. 526 * @param abilityFormInfo Indicates the obtained abilityFormInfo object. 527 * @return Returns true on success, false on failure. 528 */ 529 bool GetPackageForm(const FormRecord &record, const BundlePackInfo &bundlePackInfo, 530 AbilityFormInfo &abilityFormInfo); 531 532 /** 533 * @brief Set form free install flag. 534 * @param formId Indicates the form ID. 535 * @param isNeedFreeInstall Indicates the free install flag is true or false. 536 * @return Returns true on success, false on failure. 537 */ 538 bool SetRecordNeedFreeInstall(int64_t formId, bool isNeedFreeInstall); 539 540 /** 541 * @brief StopRenderingForm. 542 * @param formId The form id. 543 */ 544 void StopRenderingForm(int32_t formId); 545 546 /** 547 * @brief update host forms 548 * @param updateFormIds 549 */ 550 void UpdateHostForms(const std::vector<int64_t> &updateFormIds); 551 552 /** 553 * @brief Checks that the form is valid. 554 * @param formId Indicates the form ID. 555 * @return Returns ERR_OK on success, others on failure. 556 */ 557 ErrCode CheckInvalidForm(const int64_t formId); 558 559 /** 560 * @brief get cast forms count. 561 * @param formCount Returns the number of the cast form. 562 * @return Return the cast forms number. 563 */ 564 int32_t GetCastFormsCount(int32_t &formCount); 565 566 /** 567 * @brief get temp forms count. 568 * @param formCount Returns the number of the temp form. 569 * @return Return the temp forms number. 570 */ 571 int32_t GetTempFormsCount(int32_t &formCount); 572 573 /** 574 * @brief get host forms count. 575 * @param bundleName Indicates form host bundleName. 576 * @param formCount Returns the number of the host form. 577 * @return Return the host forms number. 578 */ 579 int32_t GetHostFormsCount(const std::string &bundleName, int32_t &formCount); 580 581 /** 582 * @brief handle form add observer. 583 * @param hostBundleName the bundle name of form host. 584 * @param formId Indicates the form ID. 585 * @return Returns ERR_OK on success, others on failure. 586 */ 587 ErrCode HandleFormAddObserver(const std::string hostBundleName, const int64_t formId); 588 589 /** 590 * @brief handle form add observer. 591 * @param hostBundleName the bundle name of form host. 592 * @param runningFormInfo the running forms' infos of the specify application name. 593 * @return Returns ERR_OK on success, others on failure. 594 */ 595 ErrCode HandleFormRemoveObserver(const std::string hostBundleName, const RunningFormInfo runningFormInfo); 596 597 /** 598 * @brief Get the running form infos by form id. 599 * @param formId Indicates the form ID. 600 * @param runningFormInfos Return the running forms' infos of the specify application name. 601 * @return Returns ERR_OK on success, others on failure. 602 */ 603 ErrCode GetRunningFormInfosByFormId(const int64_t formId, RunningFormInfo &runningFormInfo); 604 605 /** 606 * @brief Get all running form infos. 607 * @param isUnusedIncluded Indicates whether to include unused forms. 608 * @param runningFormInfos Return the running forms' infos currently. 609 * @return Returns ERR_OK on success, others on failure. 610 */ 611 ErrCode GetRunningFormInfos(bool isUnusedIncluded, std::vector<RunningFormInfo> &runningFormInfos); 612 613 /** 614 * @brief Get the running form infos by bundle name. 615 * @param bundleName Application name. 616 * @param isUnusedIncluded Indicates whether to include unused forms. 617 * @param runningFormInfos Return the running forms' infos of the specify application name. 618 * @return Returns ERR_OK on success, others on failure. 619 */ 620 ErrCode GetRunningFormInfosByBundleName( 621 const std::string &bundleName, bool isUnusedIncluded, std::vector<RunningFormInfo> &runningFormInfos); 622 623 /** 624 * @brief Get form instances by filter info. 625 * @param formInstancesFilter includes bundleName, moduleName, formName, abilityName to get formInstances. 626 * @param formInstances return formInstances 627 * @return return ERR_OK on get info success,other on failure. 628 */ 629 ErrCode GetFormInstancesByFilter(const FormInstancesFilter &formInstancesFilter, 630 std::vector<FormInstance> &formInstances); 631 632 /** 633 * @brief Get form instance by formId. 634 * @param formId formId Indicates the unique id of form. 635 * @param formInstance return formInstance 636 * @return return ERR_OK on get info success, others on failure. 637 */ 638 ErrCode GetFormInstanceById(const int64_t formId, FormInstance &formInstances); 639 640 /** 641 * @brief Get form instance by formId, include form store in DB. 642 * @param formId formId Indicates the unique id of form. 643 * @param isUnusedIncluded Indicates whether to include unused forms. 644 * @param formInstance return formInstance 645 * @return return ERR_OK on get info success, others on failure. 646 */ 647 ErrCode GetFormInstanceById(const int64_t formId, bool isUnusedIncluded, FormInstance &formInstances); 648 649 /** 650 * @brief Set form config map. 651 * @param configMap form config map. 652 */ 653 void SetConfigMap(const std::map<std::string, int32_t> &configMap); 654 655 /** 656 * @brief Get form config param form map. 657 * @param key the param's name. 658 * @param value the return value. 659 */ 660 void GetConfigParamFormMap(const std::string &key, int32_t &value) const; 661 662 /** 663 * @brief Recycle all recyclable forms. 664 */ 665 void RecycleAllRecyclableForms() const; 666 667 /** 668 * @brief Recycle forms. 669 * @param formIds Indicates the ID of the forms. 670 * @param callingUid The uid of caller. 671 * @param want The want of forms to be recycled. 672 */ 673 void RecycleForms(const std::vector<int64_t> &formIds, const int &callingUid, const Want &want) const; 674 675 /** 676 * @brief Update the form cloud update duration by bundleName. 677 * @param bundleName The specified bundleName. 678 * @param duration The form cloud update duration. 679 */ 680 void UpdateFormCloudUpdateDuration(const std::string &bundleName, int duration); 681 682 /** 683 * @brief Remove the form cloud update duration by bundleName. 684 * @param bundleName The specified bundleName. 685 */ 686 void RemoveFormCloudUpdateDuration(const std::string &bundleName); 687 688 /** 689 * @brief Get the form cloud update duration by bundleName. 690 * @param bundleName The specified bundleName. 691 */ 692 int GetFormCloudUpdateDuration(const std::string &bundleName) const; 693 694 /** 695 * @brief Determine if the form cloud update duration exists by bundleName. 696 * @param bundleName The specified bundleName. 697 */ 698 bool HasFormCloudUpdateDuration(const std::string &bundleName) const; 699 700 /** 701 * @brief Update form location. 702 * @param formId The Id of the form. 703 * @param formLocation The form location. 704 * @param hostBundleName the bundle name of form host. 705 * @return Returns ERR_OK on success, others on failure. 706 */ 707 ErrCode UpdateFormLocation(const int64_t &formId, const int32_t &formLocation); 708 709 /** 710 * @brief Get the formRecords by refreshType. 711 * @param formRefreshType form refresh type. 712 * @param visibleFormRecords Return the visible forms' infos need to refresh. 713 * @param invisibleFormRecords Return the invisible forms' infos need to refresh. 714 * @return Returns ERR_OK on success, others on failure. 715 */ 716 ErrCode GetRecordsByFormType(const int32_t formRefreshType, 717 std::vector<FormRecord> &visibleFormRecords, std::vector<FormRecord> &invisibleFormRecords); 718 719 /** 720 * @brief Set form enable or disable. 721 * @param formId The Id of the form. 722 * @param enable Ture or false. 723 */ 724 ErrCode SetFormEnable(const int64_t formId, const bool enable); 725 726 /** 727 * @brief Set form refresh flag or in disable during. 728 * @param formId The Id of the form. 729 * @param enable Ture or false. 730 */ 731 ErrCode SetRefreshDuringDisableForm(const int64_t formId, const bool enable); 732 733 /** 734 * @brief Set form update flag or in disable during. 735 * @param formId The Id of the form. 736 * @param enable Ture or false. 737 */ 738 ErrCode SetUpdateDuringDisableForm(const int64_t formId, const bool enable); 739 740 /** 741 * @brief Enable forms style. 742 * @param formRecords The Id list of the formRecord. 743 * @param enable True is enable form, false is disable form. 744 */ 745 void EnableForms(const std::vector<FormRecord> &&formRecords, const bool enable); 746 747 /** 748 * @brief Get all formIds by userId. 749 * @param userId User ID. 750 * @param formIds The list of formId. 751 */ 752 void GetFormIdsByUserId(int32_t userId, std::vector<int64_t> &formIds); 753 754 private: 755 /** 756 * @brief Create form record. 757 * @param formInfo The form item info. 758 * @param callingUid The UID of the proxy. 759 * @param userId User ID. 760 * @return Form record. 761 */ 762 FormRecord CreateFormRecord(const FormItemInfo &formInfo, const int callingUid, 763 const int32_t userId = Constants::DEFAULT_USER_ID) const; 764 765 /** 766 * @brief Create host record. 767 * @param info The form item info. 768 * @param callerToken The UID of the proxy. 769 * @param callingUid The UID of the proxy. 770 * @param record The form host record. 771 * @return Returns true if this function is successfully called; returns false otherwise. 772 */ 773 bool CreateHostRecord(const FormItemInfo &info, const sptr<IRemoteObject> &callerToken, 774 const int callingUid, FormHostRecord &record); 775 776 /** 777 * @brief Parse update config. 778 * @param record The form record. 779 * @param info The form item info. 780 * @return None. 781 */ 782 void ParseUpdateConfig(FormRecord &record, const FormItemInfo &info) const; 783 784 /** 785 * @brief Parse update interval config. 786 * @param record The form record. 787 * @param configDuration interval duration. 788 */ 789 void ParseIntervalConfig(FormRecord &record, const int configDuration) const; 790 791 /** 792 * @brief Parse at time config. 793 * @param record The form record. 794 * @param info form item info. 795 */ 796 void ParseAtTimerConfig(FormRecord &record, const FormItemInfo &info) const; 797 798 /** 799 * @brief Get the temp forms from host and delete temp form in cache. 800 * @param record The form record. 801 * @param recordTempForms the temp forms. 802 */ 803 void HandleHostDiedForTempForms(const FormHostRecord &record, std::vector<int64_t> &recordTempForms); 804 805 /** 806 * @brief Check if two forms is same or not. 807 * @param record FormRecord. 808 * @param formInfo FormInfo. 809 * @return Returns true on success, false on failure. 810 */ 811 bool IsSameForm(const FormRecord &record, const FormInfo &formInfo); 812 813 /** 814 * @brief Check if two forms is same or not. 815 * @param record Indicates the form record. 816 * @param abilityFormInfo Indicates the AbilityFormInfo. 817 * @return Returns true on success, false on failure. 818 */ 819 bool IsSameForm(const FormRecord &record, const AbilityFormInfo &abilityFormInfo); 820 821 /** 822 * @brief check if form cached. 823 * @param record The form record. 824 * @return Returns ERR_OK on cached, others on not cached. 825 */ 826 bool IsFormCached(const FormRecord record); 827 828 /** 829 * @brief handle update form flag. 830 * @param formIDs The id of the forms. 831 * @param flag form flag. 832 * @param isOnlyEnableUpdate form enable update form flag. 833 * @param formHostRecord form host record. 834 * @param refreshForms Refresh forms 835 * @return Returns ERR_OK on success, others on failure. 836 */ 837 ErrCode HandleUpdateHostFormFlag(const std::vector<int64_t> &formIds, bool flag, bool isOnlyEnableUpdate, 838 FormHostRecord &formHostRecord, std::vector<int64_t> &refreshForms); 839 840 /** 841 * @brief Fill the basic running form info by form record. 842 * @param formRecord The form record. 843 * @param runningFormInfo Return the running forms' info. 844 */ 845 void FillBasicRunningFormInfoByFormRecord(const FormRecord &formRecord, RunningFormInfo &runningFormInfo); 846 847 /** 848 * @brief Get ability form info. 849 * @param record Indicates form record. 850 * @param abilities Indicates the ModuleAbilityInfo in FA model or ExtensionAbilities in stage model. 851 * @param abilityFormInfo Indicates the obtained abilityFormInfo object. 852 * @return Returns ERR_OK on success, others on failure. 853 */ 854 template<typename T> 855 bool GetAbilityFormInfo(const FormRecord &record, const std::vector<T> &abilities, 856 AbilityFormInfo &abilityFormInfo); 857 858 private: 859 void GetUnusedFormInstancesByFilter( 860 const FormInstancesFilter &formInstancesFilter, std::vector<FormInstance> &formInstances); 861 ErrCode GetUnusedFormInstanceById(const int64_t formId, FormInstance &formInstance); 862 void GetUnusedFormInfos(std::vector<RunningFormInfo> &runningFormInfos); 863 void GetUnusedFormInfos(const std::string &bundleName, std::vector<RunningFormInfo> &runningFormInfos); 864 mutable std::mutex formRecordMutex_; 865 mutable std::mutex formHostRecordMutex_; 866 mutable std::mutex formTempMutex_; 867 mutable std::mutex formStateRecordMutex_; 868 mutable std::mutex formRequestPublishFormsMutex_; 869 mutable std::mutex formAcquireDataRecordMutex_; 870 mutable std::mutex formConfigMapMutex_; 871 mutable std::mutex formCloudUpdateDurationMapMutex_; 872 std::map<int64_t, FormRecord> formRecords_; 873 std::vector<FormHostRecord> clientRecords_; 874 std::vector<int64_t> tempForms_; 875 std::map<std::string, FormHostRecord> formStateRecord_; 876 std::map<std::string, std::vector<sptr<IRemoteObject>>> formAddObservers_; 877 std::map<int32_t, FormHostRecord> formAcquireDataRecord_; 878 using FormRequestPublishFormInfo = std::pair<Want, std::unique_ptr<FormProviderData>>; 879 std::map<int64_t, FormRequestPublishFormInfo> formRequestPublishForms_; 880 int64_t udidHash_ = 0; 881 std::vector<sptr<IRemoteObject>> formObservers_; 882 std::map<std::string, int32_t> formConfigMap_; 883 std::unordered_map<std::string, int> formCloudUpdateDurationMap_; 884 }; 885 } // namespace AppExecFwk 886 } // namespace OHOS 887 #endif // OHOS_FORM_FWK_FORM_FORM_DATA_MGR_H 888