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