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 <shared_mutex> 22 #include <set> 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 /** 160 * @brief Get published form record by formId. 161 * @param bundleName Bundle name. 162 * @param formInfo The form record. 163 * @param formId The Id of the form. 164 * @param userId User ID. 165 * @return Returns ERR_OK on success, others on failure. 166 */ 167 ErrCode GetPublishedFormInfoById(const std::string &bundleName, RunningFormInfo &formInfo, 168 const int64_t &formId, int32_t userId = Constants::INVALID_USER_ID) const; 169 /** 170 * @brief Get published form records. 171 * @param bundleName Bundle name. 172 * @param formInfos The form record list. 173 * @param userId User ID. 174 * @return Returns ERR_OK on success, others on failure. 175 */ 176 ErrCode GetPublishedFormInfos(const std::string &bundleName, std::vector<RunningFormInfo> &formInfos, 177 int32_t userId = Constants::INVALID_USER_ID) const; 178 179 /** 180 * @param conditionType refresh type. 181 * @param formInfos The form record list. 182 * @return Returns true if this function is successfully called; returns false otherwise. 183 */ 184 bool GetFormRecordByCondition(int32_t conditionType, std::vector<FormRecord> &formInfos) const; 185 /** 186 * @brief Get temporary form record. 187 * @param formTempRecords The temp form record. 188 * @return Returns true if this function is successfully called; returns false otherwise. 189 */ 190 bool GetTempFormRecord(std::vector<FormRecord> &formTempRecords); 191 /** 192 * @brief Check form record is exist. 193 * @param formId The Id of the form. 194 * @return Returns true if the form record is exist; returns false is not exist. 195 */ 196 bool ExistFormRecord(const int64_t formId) const; 197 /** 198 * @brief Has form user uids in form record. 199 * @param formId The Id of the form. 200 * @return Returns true if this form has form user uids; returns false is not has. 201 */ 202 bool HasFormUserUids(const int64_t formId) const; 203 /** 204 * @brief Get form host record. 205 * @param formId The id of the form. 206 * @param formHostRecords The form host records. 207 */ 208 void GetFormHostRecord(const int64_t formId, std::vector<FormHostRecord> &formHostRecords) const; 209 /** 210 * @brief Get form host remote object. 211 * @param formId The id of the form. 212 * @param formHostObjs The form host remote object. 213 */ 214 void GetFormHostRemoteObj(const int64_t formId, std::vector<sptr<IRemoteObject>> &formHostObjs) const; 215 /** 216 * @brief Delete form host record. 217 * @param callerToken The client stub of the form host record. 218 * @param formId The id of the form. 219 * @return Returns true if this function is successfully called; returns false otherwise. 220 */ 221 bool DeleteHostRecord(const sptr<IRemoteObject> &callerToken, const int64_t formId); 222 /** 223 * @brief Handle form host died. 224 * @param remoteHost Form host proxy object. 225 */ 226 void HandleHostDied(const sptr<IRemoteObject> &remoteHost); 227 /** 228 * @brief Refresh enable or not. 229 * @param formId The Id of the form. 230 * @return true on enable, false on disable. 231 */ 232 bool IsEnableRefresh(int64_t formId); 233 /** 234 * @brief update enable or not. 235 * @param formId The Id of the form. 236 * @return true on enable, false on disable. 237 */ 238 bool IsEnableUpdate(int64_t formId); 239 /** 240 * @brief Check calling uid is valid. 241 * @param formUserUids The form user uids. 242 * @return Returns true if this user uid is valid; returns false otherwise. 243 */ 244 bool IsCallingUidValid(const std::vector<int> &formUserUids) const; 245 /** 246 * @brief Generate udid. 247 * @return Returns true if this function is successfully called; returns false otherwise. 248 */ 249 bool GenerateUdidHash(); 250 /** 251 * @brief Padding udid hash. 252 * @param formId The form id. 253 * @return Padded form id. 254 */ 255 int64_t PaddingUdidHash(int64_t formId); 256 /** 257 * @brief Generate form id. 258 * @return form id. 259 */ 260 int64_t GenerateFormId(); 261 /** 262 * @brief Get udid. 263 * @return udid. 264 */ 265 int64_t GetUdidHash() const; 266 /** 267 * @brief Set udid. 268 * @param udidHash udid. 269 */ 270 void SetUdidHash(const int64_t udidHash); 271 272 /** 273 * @brief Get the matched form host record by client stub. 274 * 275 * @param callerToken The client stub of the form host record. 276 * @param formHostRecord The form host record. 277 * @return Returns true if this function is successfully called, returns false otherwise. 278 */ 279 bool GetMatchedHostClient(const sptr<IRemoteObject> &callerToken, FormHostRecord &formHostRecord) const; 280 281 /** 282 * @brief Set needRefresh for FormRecord. 283 * @param formId The Id of the form. 284 * @param needRefresh true or false. 285 */ 286 void SetNeedRefresh(const int64_t formId, const bool needRefresh); 287 288 /** 289 * @brief Set refreshType for FormRecord. 290 * @param formId The Id of the form. 291 * @param needRefresh true or false. 292 */ 293 void SetRefreshType(const int64_t formId, const int refreshType); 294 295 /** 296 * @brief Get refreshType for FormRecord. 297 * @param formId The Id of the form. 298 * @param refreshType the form refresh type. 299 */ 300 void GetRefreshType(const int64_t formId, int &refreshType); 301 302 /** 303 * @brief Set needAddForm for FormRecord. 304 * @param formId The Id of the form. 305 * @param needAddForm true or false. 306 */ 307 void SetNeedAddForm(const int64_t formId, const bool needAddForm); 308 309 /** 310 * @brief Set isCountTimerRefresh for FormRecord. 311 * @param formId The Id of the form. 312 * @param countTimerRefresh true or false. 313 */ 314 void SetCountTimerRefresh(const int64_t formId, const bool countTimerRefresh); 315 316 /** 317 * @brief Set timerRefresh for FormRecord. 318 * @param formId The Id of the form. 319 * @param timerRefresh true or false. 320 */ 321 void SetTimerRefresh(const int64_t formId, const bool timerRefresh); 322 323 /** 324 * @brief Get updated form info. 325 * @param record FormRecord. 326 * @param targetForms Target forms. 327 * @param updatedForm Updated form info. 328 * @return Returns true on success, false on failure. 329 */ 330 bool GetUpdatedForm(const FormRecord &record, const std::vector<FormInfo> &targetForms, FormInfo &updatedForm); 331 /** 332 * @brief Set isEnableUpdate for FormRecord. 333 * @param formId The Id of the form. 334 * @param enableUpdate true or false. 335 */ 336 void SetEnableUpdate(const int64_t formId, const bool enableUpdate); 337 /** 338 * @brief Set update info for FormRecord. 339 * @param formId The Id of the form. 340 * @param enableUpdate true or false. 341 * @param updateDuration Update duration. 342 * @param updateAtHour Update at hour. 343 * @param updateAtMin Update at minute. 344 * @param updateAtTimes Update times. 345 */ 346 void SetUpdateInfo(const int64_t formId, const bool enableUpdate, const long updateDuration, 347 const int updateAtHour, const int updateAtMin, std::vector<std::vector<int>> updateAtTimes); 348 /** 349 * @brief Clean removed form records. 350 * @param bundleName BundleName. 351 * @param removedForms The id list of the forms. 352 */ 353 void CleanRemovedFormRecords(const std::string &bundleName, std::set<int64_t> &removedForms); 354 /** 355 * @brief Clean removed temp form records. 356 * @param bundleName BundleName. 357 * @param removedForms The id list of the forms. 358 */ 359 void CleanRemovedTempFormRecords(const std::string &bundleName, const int32_t userId, 360 std::set<int64_t> &removedForms); 361 /** 362 * @brief Get recreate form records. 363 * @param reCreateForms The id list of the forms. 364 */ 365 void GetReCreateFormRecordsByBundleName(const std::string &bundleName, std::set<int64_t> &reCreateForms); 366 /** 367 * @brief Set form isInited = true. 368 * @param formId The Id of the form. 369 * @param isInited isInited property 370 */ 371 void SetFormCacheInited(const int64_t formId, const bool isInited); 372 /** 373 * @brief Set versionUpgrade. 374 * @param formId The Id of the form. 375 * @param versionUpgrade true or false 376 */ 377 void SetVersionUpgrade(const int64_t formId, const bool versionUpgrade); 378 /** 379 * @brief Update form for host clients. 380 * @param formId The Id of the form. 381 * @param needRefresh true or false 382 */ 383 void UpdateHostNeedRefresh(const int64_t formId, const bool needRefresh); 384 /** 385 * @brief Update form for host clients. 386 * @param formId The Id of the form. 387 * @param formRecord The form info. 388 * @return Returns true if form update, false if other. 389 */ 390 bool UpdateHostForm(const int64_t formId, const FormRecord &formRecord); 391 /** 392 * @brief handle update form flag. 393 * @param formIDs The id of the forms. 394 * @param callerToken Caller ability token. 395 * @param flag form flag. 396 * @param isOnlyEnableUpdate form enable update form flag. 397 * @param refreshForms Refresh forms 398 * @return Returns ERR_OK on success, others on failure. 399 */ 400 ErrCode UpdateHostFormFlag(const std::vector<int64_t> &formIds, const sptr<IRemoteObject> &callerToken, 401 bool flag, bool isOnlyEnableUpdate, std::vector<int64_t> &refreshForms); 402 /** 403 * @brief Find matched form id. 404 * @param formId The form id. 405 * @return Matched form id. 406 */ 407 int64_t FindMatchedFormId(const int64_t formId); 408 /** 409 * @brief Clear host data by uId. 410 * @param uId The caller uId. 411 */ 412 void ClearHostDataByUId(const int uId); 413 /** 414 * @brief Get no host temp forms. 415 * @param uid The caller uid. 416 * @param noHostTempFormsMap no host temp forms. 417 * @param foundFormsMap Form Id list. 418 */ 419 void GetNoHostTempForms(const int uid, std::map<FormIdKey, std::set<int64_t>> &noHostTempFormsMap, 420 std::map<int64_t, bool> &foundFormsMap); 421 422 /** 423 * @brief delete forms by userId. 424 * 425 * @param userId user ID. 426 * @param removedFormIds removed userId. 427 */ 428 void DeleteFormsByUserId(const int32_t userId, std::vector<int64_t> &removedFormIds); 429 /** 430 * @brief Clear form records for st limit value test. 431 */ 432 void ClearFormRecords(); 433 434 /** 435 * @brief handle get no host invalid temp forms. 436 * @param userId User ID. 437 * @param callingUid The UID of the proxy. 438 * @param matchedFormIds The set of the valid forms. 439 * @param noHostTempFormsMap The map of the no host forms. 440 * @param foundFormsMap The map of the found forms. 441 */ 442 void GetNoHostInvalidTempForms(int32_t userId, int32_t callingUid, std::set<int64_t> &matchedFormIds, 443 std::map<FormIdKey, std::set<int64_t>> &noHostTempFormsMap, 444 std::map<int64_t, bool> &foundFormsMap); 445 446 /** 447 * @brief handle delete no host temp forms. 448 * @param callingUid The UID of the proxy. 449 * @param noHostTempFormsMap The map of the no host forms. 450 * @param foundFormsMap The map of the found forms. 451 */ 452 void BatchDeleteNoHostTempForms(int32_t callingUid, std::map<FormIdKey, std::set<int64_t>> &noHostTempFormsMap, 453 std::map<int64_t, bool> &foundFormsMap); 454 455 /** 456 * @brief delete invalid temp forms. 457 * @param userId User ID. 458 * @param callingUid The UID of the proxy. 459 * @param matchedFormIds The set of the valid forms. 460 * @param removedFormsMap The map of the removed invalid forms. 461 * @return Returns ERR_OK on success, others on failure. 462 */ 463 int32_t DeleteInvalidTempForms(int32_t userId, int32_t callingUid, std::set<int64_t> &matchedFormIds, 464 std::map<int64_t, bool> &removedFormsMap); 465 466 /** 467 * @brief clear host data by invalid forms. 468 * @param callingUid The UID of the proxy. 469 * @param removedFormsMap The map of the removed invalid forms. 470 * @return Returns ERR_OK on success, others on failure. 471 */ 472 int32_t ClearHostDataByInvalidForms(int32_t callingUid, std::map<int64_t, bool> &removedFormsMap); 473 474 /** 475 * @brief delete publish forms temp data 476 * @param userId User ID. 477 * @param bundleName BundleName. 478 * @param validFormIds The set of the valid forms. 479 * @return Returns - 480 */ 481 void DeleteInvalidPublishForms(int32_t userId, std::string bundleName, std::set<int64_t> &validFormIds); 482 483 /** 484 * @brief Create form acquire data host record. 485 * @param requestCode The request code of this acquire form. 486 * @param info The form item info. 487 * @param callerToken Caller ability token. 488 * @param callingUid The UID of the proxy. 489 * @return Returns true if this function is successfully called; returns false otherwise. 490 */ 491 bool CreateFormAcquireDataRecord(int64_t requestCode, const FormItemInfo &info, 492 const sptr<IRemoteObject> &callerToken, int callingUid); 493 494 /** 495 * @brief Create form state host record. 496 * @param provider The provider of the form state 497 * @param info The form item info. 498 * @param callerToken The UID of the proxy. 499 * @param callingUid The UID of the proxy. 500 * @return Returns true if this function is successfully called; returns false otherwise. 501 */ 502 bool CreateFormStateRecord(std::string &provider, const FormItemInfo &info, const sptr<IRemoteObject> &callerToken, 503 int callingUid); 504 505 /** 506 * @brief acquire form state callback. 507 * @param state form state. 508 * @param provider provider info. 509 * @param want The want of onAcquireFormState. 510 * @return Returns true if this function is successfully called; returns false otherwise. 511 */ 512 ErrCode AcquireFormStateBack(AppExecFwk::FormState state, const std::string &provider, const Want &want); 513 514 /** 515 * @brief acquire form data callback. 516 * @param wantParams Indicates the data information acquired by the form. 517 * @param requestCode Indicates the requested id. 518 * @return Returns true if this function is successfully called; returns false otherwise. 519 */ 520 ErrCode AcquireFormDataBack(const AAFwk::WantParams &wantParams, int64_t requestCode); 521 522 /** 523 * @brief Notify the form is visible or not. 524 * @param formIds Indicates the ID of the forms. 525 * @param isVisible Visible or not. 526 * @param callerToken Host client. 527 * @return Returns ERR_OK on success, others on failure. 528 */ 529 ErrCode NotifyFormsVisible(const std::vector<int64_t> &formIds, bool isVisible, 530 const sptr<IRemoteObject> &callerToken); 531 532 /** 533 * @brief set form record visible. 534 * @param matchedFormId form id. 535 * @param isVisible is visible. 536 * @return Returns true if this function is successfully called; returns false otherwise. 537 */ 538 ErrCode SetRecordVisible(int64_t matchedFormId, bool isVisible); 539 540 /** 541 * @brief add request publish form info. 542 * @param formId The form id of the form to publish. 543 * @param want The want of the form to publish. 544 * @param formProviderData The form data. 545 * @return Returns ERR_OK on success, others on failure. 546 */ 547 ErrCode AddRequestPublishFormInfo(int64_t formId, const Want &want, 548 std::unique_ptr<FormProviderData> &formProviderData); 549 550 /** 551 * @brief remove request publish form info. 552 * @param formId The form id of the form to publish. 553 * @return Returns true if this function is successfully called; returns false otherwise. 554 */ 555 ErrCode RemoveRequestPublishFormInfo(int64_t formId); 556 557 /** 558 * @brief check whether request publish form info. 559 * @param formId The form id of the form to publish. 560 * @return Returns true if this function is successfully called; returns false otherwise. 561 */ 562 bool IsRequestPublishForm(int64_t formId); 563 564 /** 565 * @brief get request publish form info. 566 * @param formId The form id of the form to publish. 567 * @param want The want of the form to publish. 568 * @param formProviderData The form data. 569 * @return Returns true if this function is successfully called; returns false otherwise. 570 */ 571 ErrCode GetRequestPublishFormInfo(int64_t formId, Want &want, 572 std::unique_ptr<FormProviderData> &formProviderData); 573 /** 574 * @brief Get updated form info. 575 * @param record Indicates the form record. 576 * @param bundlePackInfo Indicates the BundlePackInfo object. 577 * @param abilityFormInfo Indicates the obtained abilityFormInfo object. 578 * @return Returns true on success, false on failure. 579 */ 580 bool GetPackageForm(const FormRecord &record, const BundlePackInfo &bundlePackInfo, 581 AbilityFormInfo &abilityFormInfo); 582 583 /** 584 * @brief Set form free install flag. 585 * @param formId Indicates the form ID. 586 * @param isNeedFreeInstall Indicates the free install flag is true or false. 587 * @return Returns true on success, false on failure. 588 */ 589 bool SetRecordNeedFreeInstall(int64_t formId, bool isNeedFreeInstall); 590 591 /** 592 * @brief StopRenderingForm. 593 * @param formId The form id. 594 */ 595 void StopRenderingForm(int32_t formId); 596 597 /** 598 * @brief update host forms 599 * @param updateFormIds 600 */ 601 void UpdateHostForms(const std::vector<int64_t> &updateFormIds); 602 603 /** 604 * @brief Checks that the form is valid. 605 * @param formId Indicates the form ID. 606 * @return Returns ERR_OK on success, others on failure. 607 */ 608 ErrCode CheckInvalidForm(const int64_t formId); 609 610 /** 611 * @brief get cast forms count. 612 * @param formCount Returns the number of the cast form. 613 * @return Return the cast forms number. 614 */ 615 int32_t GetCastFormsCount(int32_t &formCount); 616 617 /** 618 * @brief get temp forms count. 619 * @param formCount Returns the number of the temp form. 620 * @return Return the temp forms number. 621 */ 622 int32_t GetTempFormsCount(int32_t &formCount); 623 624 /** 625 * @brief get host forms count. 626 * @param bundleName Indicates form host bundleName. 627 * @param formCount Returns the number of the host form. 628 * @return Return the host forms number. 629 */ 630 int32_t GetHostFormsCount(const std::string &bundleName, int32_t &formCount); 631 632 /** 633 * @brief handle form add observer. 634 * @param hostBundleName the bundle name of form host. 635 * @param formId Indicates the form ID. 636 * @return Returns ERR_OK on success, others on failure. 637 */ 638 ErrCode HandleFormAddObserver(const std::string hostBundleName, const int64_t formId); 639 640 /** 641 * @brief handle form add observer. 642 * @param hostBundleName the bundle name of form host. 643 * @param runningFormInfo the running forms' infos of the specify application name. 644 * @return Returns ERR_OK on success, others on failure. 645 */ 646 ErrCode HandleFormRemoveObserver(const std::string hostBundleName, const RunningFormInfo runningFormInfo); 647 648 /** 649 * @brief Get the running form infos by form id. 650 * @param formId Indicates the form ID. 651 * @param runningFormInfos Return the running forms' infos of the specify application name. 652 * @return Returns ERR_OK on success, others on failure. 653 */ 654 ErrCode GetRunningFormInfosByFormId(const int64_t formId, RunningFormInfo &runningFormInfo); 655 656 /** 657 * @brief Get all running form infos. 658 * @param isUnusedIncluded Indicates whether to include unused forms. 659 * @param runningFormInfos Return the running forms' infos currently. 660 * @return Returns ERR_OK on success, others on failure. 661 */ 662 ErrCode GetRunningFormInfos(bool isUnusedIncluded, std::vector<RunningFormInfo> &runningFormInfos); 663 664 /** 665 * @brief Get the running form infos by bundle name. 666 * @param bundleName Application name. 667 * @param isUnusedIncluded Indicates whether to include unused forms. 668 * @param runningFormInfos Return the running forms' infos of the specify application name. 669 * @return Returns ERR_OK on success, others on failure. 670 */ 671 ErrCode GetRunningFormInfosByBundleName( 672 const std::string &bundleName, bool isUnusedIncluded, std::vector<RunningFormInfo> &runningFormInfos); 673 674 /** 675 * @brief Get form instances by filter info. 676 * @param formInstancesFilter includes bundleName, moduleName, formName, abilityName to get formInstances. 677 * @param formInstances return formInstances 678 * @return return ERR_OK on get info success,other on failure. 679 */ 680 ErrCode GetFormInstancesByFilter(const FormInstancesFilter &formInstancesFilter, 681 std::vector<FormInstance> &formInstances); 682 683 /** 684 * @brief Get form instance by formId. 685 * @param formId formId Indicates the unique id of form. 686 * @param formInstance return formInstance 687 * @return return ERR_OK on get info success, others on failure. 688 */ 689 ErrCode GetFormInstanceById(const int64_t formId, FormInstance &formInstances); 690 691 /** 692 * @brief Get form instance by formId, include form store in DB. 693 * @param formId formId Indicates the unique id of form. 694 * @param isUnusedIncluded Indicates whether to include unused forms. 695 * @param formInstance return formInstance 696 * @return return ERR_OK on get info success, others on failure. 697 */ 698 ErrCode GetFormInstanceById(const int64_t formId, bool isUnusedIncluded, FormInstance &formInstances); 699 700 /** 701 * @brief Set form config map. 702 * @param configMap form config map. 703 */ 704 void SetConfigMap(const std::map<std::string, int32_t> &configMap); 705 706 /** 707 * @brief Get form config param form map. 708 * @param key the param's name. 709 * @param value the return value. 710 */ 711 void GetConfigParamFormMap(const std::string &key, int32_t &value) const; 712 713 /** 714 * @brief Recycle all recyclable forms. 715 */ 716 void RecycleAllRecyclableForms() const; 717 718 /** 719 * @brief Recycle forms. 720 * @param formIds Indicates the ID of the forms. 721 * @param callingUid The uid of caller. 722 * @param want The want of forms to be recycled. 723 */ 724 void RecycleForms(const std::vector<int64_t> &formIds, const int &callingUid, const Want &want) const; 725 726 /** 727 * @brief Update the form cloud update duration by bundleName. 728 * @param bundleName The specified bundleName. 729 * @param duration The form cloud update duration. 730 */ 731 void UpdateFormCloudUpdateDuration(const std::string &bundleName, int duration); 732 733 /** 734 * @brief Remove the form cloud update duration by bundleName. 735 * @param bundleName The specified bundleName. 736 */ 737 void RemoveFormCloudUpdateDuration(const std::string &bundleName); 738 739 /** 740 * @brief Get the form cloud update duration by bundleName. 741 * @param bundleName The specified bundleName. 742 */ 743 int GetFormCloudUpdateDuration(const std::string &bundleName) const; 744 745 /** 746 * @brief Determine if the form cloud update duration exists by bundleName. 747 * @param bundleName The specified bundleName. 748 */ 749 bool HasFormCloudUpdateDuration(const std::string &bundleName) const; 750 751 /** 752 * @brief Update form location. 753 * @param formId The Id of the form. 754 * @param formLocation The form location. 755 * @param hostBundleName the bundle name of form host. 756 * @return Returns ERR_OK on success, others on failure. 757 */ 758 ErrCode UpdateFormLocation(const int64_t &formId, const int32_t &formLocation); 759 760 /** 761 * @brief Get the formRecords by refreshType. 762 * @param formRefreshType form refresh type. 763 * @param visibleFormRecords Return the visible forms' infos need to refresh. 764 * @param invisibleFormRecords Return the invisible forms' infos need to refresh. 765 * @return Returns ERR_OK on success, others on failure. 766 */ 767 ErrCode GetRecordsByFormType(const int32_t formRefreshType, 768 std::vector<FormRecord> &visibleFormRecords, std::vector<FormRecord> &invisibleFormRecords); 769 770 /** 771 * @brief Set form lock or dislock. 772 * @param formId The Id of the form. 773 * @param lock Ture or false. 774 */ 775 ErrCode SetFormLock(const int64_t formId, const bool lock); 776 777 /** 778 * @brief Set form lock or dislock. 779 * @param formId The Id of the form. 780 * @param lock Ture or false. 781 */ 782 ErrCode GetFormLock(const int64_t formId, bool &lock); 783 784 /** 785 * @brief Set form protect or disprotect. 786 * @param formId The Id of the form. 787 * @param protect Ture or false. 788 */ 789 ErrCode SetFormProtect(const int64_t formId, const bool protect); 790 791 /** 792 * @brief Set form protect or disprotect. 793 * @param formId The Id of the form. 794 * @param protect Ture or false. 795 */ 796 ErrCode GetFormProtect(const int64_t formId, bool &protect); 797 798 /** 799 * @brief Set form enable or disable. 800 * @param formId The Id of the form. 801 * @param enable Ture or false. 802 */ 803 ErrCode SetFormEnable(const int64_t formId, const bool enable); 804 805 /** 806 * @brief Set form refresh flag or in disable during. 807 * @param formId The Id of the form. 808 * @param enable Ture or false. 809 */ 810 ErrCode SetRefreshDuringDisableForm(const int64_t formId, const bool enable); 811 812 /** 813 * @brief Set form update flag or in disable during. 814 * @param formId The Id of the form. 815 * @param enable Ture or false. 816 */ 817 ErrCode SetUpdateDuringDisableForm(const int64_t formId, const bool enable); 818 819 /** 820 * @brief protect forms style. 821 * @param formRecords The Id list of the formRecord. 822 * @param protect True is protect form, false is unprotect form. 823 */ 824 void LockForms(const std::vector<FormRecord> &&formRecords, const bool protect); 825 826 /** 827 * @brief Enable forms style. 828 * @param formRecords The Id list of the formRecord. 829 * @param enable True is enable form, false is disable form. 830 */ 831 void EnableForms(const std::vector<FormRecord> &&formRecords, const bool enable); 832 833 /** 834 * @brief Get all formIds by userId. 835 * @param userId User ID. 836 * @param formIds The list of formId. 837 */ 838 void GetFormIdsByUserId(int32_t userId, std::vector<int64_t> &formIds); 839 840 /** 841 * @brief Recheck whether need clean form host. 842 * @param callerToken The client stub of the form host record. 843 */ 844 bool RecheckWhetherNeedCleanFormHost(const sptr<IRemoteObject> &callerToken); 845 846 /** 847 * @brief Cache the visibility of the card. 848 * @param formId form id. 849 * @param isVisible is visible. 850 */ 851 void SetFormVisible(int64_t formId, bool isVisible); 852 853 /** 854 * @brief Delete Cache of card visibility. 855 * @param formId form id. 856 */ 857 void DeleteFormVisible(int64_t formId); 858 859 /** 860 * @brief Check if the card can be updated. 861 * @param formId form id. 862 */ 863 bool GetFormCanUpdate(int64_t formId); 864 865 private: 866 /** 867 * @brief Create form record. 868 * @param formInfo The form item info. 869 * @param callingUid The UID of the proxy. 870 * @param userId User ID. 871 * @return Form record. 872 */ 873 FormRecord CreateFormRecord(const FormItemInfo &formInfo, const int callingUid, 874 const int32_t userId = Constants::DEFAULT_USER_ID) const; 875 876 /** 877 * @brief Create host record. 878 * @param info The form item info. 879 * @param callerToken The UID of the proxy. 880 * @param callingUid The UID of the proxy. 881 * @param record The form host record. 882 * @return Returns true if this function is successfully called; returns false otherwise. 883 */ 884 bool CreateHostRecord(const FormItemInfo &info, const sptr<IRemoteObject> &callerToken, 885 const int callingUid, FormHostRecord &record); 886 887 /** 888 * @brief Parse update config. 889 * @param record The form record. 890 * @param info The form item info. 891 * @return None. 892 */ 893 void ParseUpdateConfig(FormRecord &record, const FormItemInfo &info) const; 894 895 /** 896 * @brief Parse update interval config. 897 * @param record The form record. 898 * @param configDuration interval duration. 899 */ 900 void ParseIntervalConfig(FormRecord &record, const int configDuration) const; 901 902 /** 903 * @brief Parse multi update time config. 904 * @param record The form record. 905 * @param info form item info. 906 */ 907 void ParseMultiUpdateTimeConfig(FormRecord &record, const FormItemInfo &info) const; 908 909 /** 910 * @brief Parse at time config. 911 * @param record The form record. 912 * @param info form item info. 913 */ 914 void ParseAtTimerConfig(FormRecord &record, const FormItemInfo &info) const; 915 916 /** 917 * @brief Get the temp forms from host and delete temp form in cache. 918 * @param record The form record. 919 * @param recordTempForms the temp forms. 920 */ 921 void HandleHostDiedForTempForms(const FormHostRecord &record, std::vector<int64_t> &recordTempForms); 922 923 /** 924 * @brief Check if two forms is same or not. 925 * @param record FormRecord. 926 * @param formInfo FormInfo. 927 * @return Returns true on success, false on failure. 928 */ 929 bool IsSameForm(const FormRecord &record, const FormInfo &formInfo); 930 931 /** 932 * @brief Check if two forms is same or not. 933 * @param record Indicates the form record. 934 * @param abilityFormInfo Indicates the AbilityFormInfo. 935 * @return Returns true on success, false on failure. 936 */ 937 bool IsSameForm(const FormRecord &record, const AbilityFormInfo &abilityFormInfo); 938 939 /** 940 * @brief check if form cached. 941 * @param record The form record. 942 * @return Returns ERR_OK on cached, others on not cached. 943 */ 944 bool IsFormCached(const FormRecord record); 945 946 /** 947 * @brief handle update form flag. 948 * @param formIDs The id of the forms. 949 * @param flag form flag. 950 * @param isOnlyEnableUpdate form enable update form flag. 951 * @param formHostRecord form host record. 952 * @param refreshForms Refresh forms 953 * @return Returns ERR_OK on success, others on failure. 954 */ 955 ErrCode HandleUpdateHostFormFlag(const std::vector<int64_t> &formIds, bool flag, bool isOnlyEnableUpdate, 956 FormHostRecord &formHostRecord, std::vector<int64_t> &refreshForms); 957 958 /** 959 * @brief Fill the basic running form info by form record. 960 * @param formRecord The form record. 961 * @param runningFormInfo Return the running forms' info. 962 */ 963 void FillBasicRunningFormInfoByFormRecord(const FormRecord &formRecord, 964 RunningFormInfo &runningFormInfo) const; 965 /** 966 * @brief Get ability form info. 967 * @param record Indicates form record. 968 * @param abilities Indicates the ModuleAbilityInfo in FA model or ExtensionAbilities in stage model. 969 * @param abilityFormInfo Indicates the obtained abilityFormInfo object. 970 * @return Returns ERR_OK on success, others on failure. 971 */ 972 template<typename T> 973 bool GetAbilityFormInfo(const FormRecord &record, const std::vector<T> &abilities, 974 AbilityFormInfo &abilityFormInfo); 975 976 private: 977 void GetUnusedFormInstancesByFilter( 978 const FormInstancesFilter &formInstancesFilter, std::vector<FormInstance> &formInstances); 979 ErrCode GetUnusedFormInstanceById(const int64_t formId, FormInstance &formInstance); 980 void GetUnusedFormInfos(std::vector<RunningFormInfo> &runningFormInfos); 981 void GetUnusedFormInfos(const std::string &bundleName, std::vector<RunningFormInfo> &runningFormInfos); 982 mutable std::mutex formRecordMutex_; 983 mutable std::mutex formHostRecordMutex_; 984 mutable std::mutex formTempMutex_; 985 mutable std::mutex formStateRecordMutex_; 986 mutable std::mutex formRequestPublishFormsMutex_; 987 mutable std::mutex formAcquireDataRecordMutex_; 988 mutable std::mutex formConfigMapMutex_; 989 mutable std::mutex formCloudUpdateDurationMapMutex_; 990 mutable std::shared_mutex formVisibleMapMutex_; 991 std::map<int64_t, FormRecord> formRecords_; 992 std::vector<FormHostRecord> clientRecords_; 993 std::vector<int64_t> tempForms_; 994 std::map<std::string, FormHostRecord> formStateRecord_; 995 std::map<std::string, std::vector<sptr<IRemoteObject>>> formAddObservers_; 996 std::map<int32_t, FormHostRecord> formAcquireDataRecord_; 997 using FormRequestPublishFormInfo = std::pair<Want, std::unique_ptr<FormProviderData>>; 998 std::map<int64_t, FormRequestPublishFormInfo> formRequestPublishForms_; 999 int64_t udidHash_ = 0; 1000 std::vector<sptr<IRemoteObject>> formObservers_; 1001 std::map<std::string, int32_t> formConfigMap_; 1002 std::unordered_map<std::string, int> formCloudUpdateDurationMap_; 1003 std::unordered_map<int64_t, bool> formVisibleMap_; 1004 }; 1005 } // namespace AppExecFwk 1006 } // namespace OHOS 1007 #endif // OHOS_FORM_FWK_FORM_FORM_DATA_MGR_H 1008