diff --git a/services/include/common/util/form_trust_mgr.h b/services/include/common/util/form_trust_mgr.h index 6626c233f442f8279a41d9ed58fef108e726b19f..e37771732fd0f24666c69c54d04dd43fa739e8fe 100644 --- a/services/include/common/util/form_trust_mgr.h +++ b/services/include/common/util/form_trust_mgr.h @@ -57,7 +57,7 @@ public: void GetUntrustAppNameList(std::string &result); private: std::map unTrustList_; - mutable std::mutex rdbStoreMutex_; + mutable std::mutex unTrustListMutex_; }; } // namespace AppExecFwk } // namespace OHOS diff --git a/services/include/data_center/form_data_mgr.h b/services/include/data_center/form_data_mgr.h index a74740b80eb053c85d0aacd004e2f89fd56f6456..2ba6f27c0c46f55a2012109cbedd3aaa25b83568 100644 --- a/services/include/data_center/form_data_mgr.h +++ b/services/include/data_center/form_data_mgr.h @@ -211,6 +211,14 @@ public: * @param formId The id of the form. * @param formHostObjs The form host remote object. */ + + /** + * @brief update formRecord recycle status to recycled. + * @param formId form id. + * @return Returns true on success, false on failure. + */ + bool UpdateFormRecordRecycleStatus(const int64_t formId, const RecycleStatus status); + void GetFormHostRemoteObj(const int64_t formId, std::vector> &formHostObjs) const; /** * @brief Delete form host record. diff --git a/services/include/status_mgr_center/form_task_mgr.h b/services/include/status_mgr_center/form_task_mgr.h index 46af207a47ab98d175cb92e5d792be23e12aa22e..5907feba59aacf8eb3a30273e61be6329a211da1 100644 --- a/services/include/status_mgr_center/form_task_mgr.h +++ b/services/include/status_mgr_center/form_task_mgr.h @@ -629,6 +629,18 @@ private: void InnerPostRenderForm(const FormRecord &formRecord, const Want &want, const sptr &remoteObject); + + /** + * @brief remove form last revocer time + * @param formId The Id of the form. + */ + void RemoveLastRecoverTimesByFormId(const int64_t formId); + + /** + * @brief update form last revocer time + * @param formId The Id of the form. + */ + void UpdateFormLastRecoverTimes(const int64_t formId); private: std::mutex formRecoverTimesMutex_; std::unordered_map formLastRecoverTimes; diff --git a/services/src/common/util/form_trust_mgr.cpp b/services/src/common/util/form_trust_mgr.cpp index d63680fa8493c522f26575e3277086a8694629d2..663821dfb2d7a721725e712b14f927e8381b6c46 100644 --- a/services/src/common/util/form_trust_mgr.cpp +++ b/services/src/common/util/form_trust_mgr.cpp @@ -44,7 +44,7 @@ FormTrustMgr::~FormTrustMgr() bool FormTrustMgr::IsTrust(const std::string &bundleName) { - std::lock_guard lock(rdbStoreMutex_); + std::lock_guard lock(unTrustListMutex_); auto iter = unTrustList_.find(bundleName); if (iter == unTrustList_.end()) { return true; @@ -67,7 +67,7 @@ void FormTrustMgr::GetUntrustAppNameList(std::string &result) void FormTrustMgr::MarkTrustFlag(const std::string &bundleName, bool isTrust) { - std::lock_guard lock(rdbStoreMutex_); + std::lock_guard lock(unTrustListMutex_); auto iter = unTrustList_.find(bundleName); if (isTrust && iter != unTrustList_.end()) { auto ret = FormRdbDataMgr::GetInstance().DeleteData(UNTRUST_LIST, bundleName); diff --git a/services/src/data_center/form_cache_mgr.cpp b/services/src/data_center/form_cache_mgr.cpp index 472dcedde37e7b14e3b820654ed3d588976c99bb..021f32139a044ad493d1d0cd9282823cc5451898 100644 --- a/services/src/data_center/form_cache_mgr.cpp +++ b/services/src/data_center/form_cache_mgr.cpp @@ -456,6 +456,7 @@ bool FormCacheMgr::GetImgCacheFromDb( NativeRdb::AbsRdbPredicates absRdbPredicates(IMG_CACHE_TABLE); absRdbPredicates.EqualTo(IMAGE_ID, std::to_string(rowId)); auto absSharedResultSet = FormRdbDataMgr::GetInstance().QueryData(absRdbPredicates); + if (absSharedResultSet == nullptr) { HILOG_ERROR("GetImgCacheFromDb failed"); return false; @@ -510,7 +511,6 @@ bool FormCacheMgr::DeleteImgCacheInDb(const std::string &rowId) if (rowId.empty()) { return false; } - NativeRdb::AbsRdbPredicates absRdbPredicates(IMG_CACHE_TABLE); absRdbPredicates.EqualTo(IMAGE_ID, rowId); return FormRdbDataMgr::GetInstance().DeleteData(absRdbPredicates); diff --git a/services/src/data_center/form_data_mgr.cpp b/services/src/data_center/form_data_mgr.cpp index c307568869287fd20f48f51f23c1fdefbc2f720f..0a87e0411263be1f9b521397a09183fdc682bb24 100644 --- a/services/src/data_center/form_data_mgr.cpp +++ b/services/src/data_center/form_data_mgr.cpp @@ -2975,6 +2975,29 @@ void FormDataMgr::UpdateFormWant(const int64_t formId, const Want &want, FormRec record.wantCacheMap[formId] = want; } +/** + * @brief update formRecord recycle status. + * @param formId form id. + * @return Returns true on success, false on failure. + */ +bool FormDataMgr::UpdateFormRecordRecycleStatus(const int64_t formId, const RecycleStatus status) +{ + HILOG_DEBUG("get form record by formId"); + std::lock_guard lock(formRecordMutex_); + auto info = formRecords_.find(formId); + if (info == formRecords_.end()) { + HILOG_WARN("form %{public}" PRId64 " not exist", formId); + return false; + } + if (info->second.recycleStatus != RecycleStatus::RECYCLABLE) { + HILOG_WARN("form %{public}" PRId64 " not RECYCLABLE", formId); + return false; + } + info->second.recycleStatus = status; + HILOG_DEBUG("get form record successfully"); + return true; +} + void FormDataMgr::GetFormRecordsByUserId(const int32_t userId, std::vector &formRecords) { std::lock_guard lock(formRecordMutex_); diff --git a/services/src/form_provider/form_supply_callback.cpp b/services/src/form_provider/form_supply_callback.cpp index a789ed8f73601b9c3e5500f11bb5ce247c02cc59..a0e9d88d276f42ec09685ef00231a1c191a50d0e 100644 --- a/services/src/form_provider/form_supply_callback.cpp +++ b/services/src/form_provider/form_supply_callback.cpp @@ -360,17 +360,10 @@ int32_t FormSupplyCallback::OnRecycleForm(const int64_t &formId, const Want &wan return ERR_APPEXECFWK_FORM_COMMON_CODE; } - FormRecord formRecord; - if (!FormDataMgr::GetInstance().GetFormRecord(formId, formRecord)) { - HILOG_WARN("form %{public}" PRId64 " not exist", formId); + if (!FormDataMgr::GetInstance().UpdateFormRecordRecycleStatus(formId, RecycleStatus::RECYCLED)) { + HILOG_ERROR("update recycle status data of %{public}" PRId64 " failed", formId); return ERR_APPEXECFWK_FORM_COMMON_CODE; } - if (formRecord.recycleStatus != RecycleStatus::RECYCLABLE) { - HILOG_WARN("form %{public}" PRId64 " not RECYCLABLE", formId); - return ERR_APPEXECFWK_FORM_COMMON_CODE; - } - formRecord.recycleStatus = RecycleStatus::RECYCLED; - FormDataMgr::GetInstance().UpdateFormRecord(formId, formRecord); sptr remoteObjectOfHost = want.GetRemoteObject(Constants::PARAM_FORM_HOST_TOKEN); if (remoteObjectOfHost == nullptr) { diff --git a/services/src/status_mgr_center/form_task_mgr.cpp b/services/src/status_mgr_center/form_task_mgr.cpp index 9bfe98bdeeb4ed558d9cecef80e7892999c2689a..006d40f4356c7d2f3e8dedb1c24e75e785f3a3c5 100644 --- a/services/src/status_mgr_center/form_task_mgr.cpp +++ b/services/src/status_mgr_center/form_task_mgr.cpp @@ -947,10 +947,7 @@ void FormTaskMgr::PostStopRenderingForm( auto deleterenderForm = [formRecord, want, remoteObject]() { FormTaskMgr::GetInstance().StopRenderingForm(formRecord, want, remoteObject); }; - { - std::lock_guard lock(formRecoverTimesMutex_); - formLastRecoverTimes.erase(formId); - } + RemoveLastRecoverTimesByFormId(formId); FormCommand deleteCommand{ formId, std::make_pair(TaskCommandType::DELETE_FORM, formId), @@ -995,10 +992,7 @@ void FormTaskMgr::PostReleaseRenderer(int64_t formId, const std::string &compId, auto deleterenderForm = [formId, compId, uid, remoteObject]() { FormTaskMgr::GetInstance().ReleaseRenderer(formId, compId, uid, remoteObject); }; - { - std::lock_guard lock(formRecoverTimesMutex_); - formLastRecoverTimes.erase(formId); - } + RemoveLastRecoverTimesByFormId(formId); if (!isDynamic) { FormCommand deleteCommand{ formId, @@ -1260,10 +1254,7 @@ void FormTaskMgr::PostRecycleForms(const std::vector &formIds, const Wa auto recycleForm = [formId, remoteObjectOfHost, remoteObjectOfRender]() { FormTaskMgr::GetInstance().RecycleForm(formId, remoteObjectOfHost, remoteObjectOfRender); }; - { - std::lock_guard lock(formRecoverTimesMutex_); - formLastRecoverTimes.erase(formId); - } + RemoveLastRecoverTimesByFormId(formId); serialQueue_->ScheduleDelayTask( std::make_pair((int64_t)TaskType::RECYCLE_FORM, formId), delayTime, recycleForm); } @@ -1325,10 +1316,7 @@ void FormTaskMgr::PostRecoverForm(const FormRecord &record, const Want &want, co auto recoverForm = [record, want, remoteObject]() { FormTaskMgr::GetInstance().RecoverForm(record, want, remoteObject); }; - { - std::lock_guard lock(formRecoverTimesMutex_); - formLastRecoverTimes[formId] = FormUtil::GetCurrentMillisecond(); - } + UpdateFormLastRecoverTimes(formId); auto hostToken = want.GetRemoteObject(Constants::PARAM_FORM_HOST_TOKEN); FormCommand recoverCommand{ formId, @@ -1643,5 +1631,17 @@ void FormTaskMgr::PostDelayRefreshForms(const std::vector updatedFor serialQueue_->ScheduleTask(PROVIDER_UPDATE_REFRESH_FORMS_TASK_DELAY_TIME, delayRefreshForms); HILOG_INFO("end"); } + +void FormTaskMgr::RemoveLastRecoverTimesByFormId(const int64_t formId) +{ + std::lock_guard lock(formRecoverTimesMutex_); + formLastRecoverTimes.erase(formId); +} + +void FormTaskMgr::UpdateFormLastRecoverTimes(const int64_t formId) +{ + std::lock_guard lock(formRecoverTimesMutex_); + formLastRecoverTimes[formId] = FormUtil::GetCurrentMillisecond(); +} } // namespace AppExecFwk } // namespace OHOS