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