From d8efdafa96109d0fe3bd325a80a02f091d9aa5e7 Mon Sep 17 00:00:00 2001 From: liweifeng Date: Sat, 1 Apr 2023 16:36:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8D=E6=94=AF=E6=8C=81=E5=90=8C=E4=B8=80?= =?UTF-8?q?=E4=B8=AAformid=E8=A2=AB=E5=A4=9A=E4=B8=AA=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E6=96=B9=E6=8C=81=E6=9C=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liweifeng Change-Id: Ib41456247bbfea7b5aebce116238a7e4b81dea04 --- services/include/form_data_mgr.h | 1 - services/include/form_db_cache.h | 2 ++ services/src/form_db_cache.cpp | 16 ++++++++++++++++ services/src/form_mgr_adapter.cpp | 9 +++++++++ 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/services/include/form_data_mgr.h b/services/include/form_data_mgr.h index 0faed95475..05c09c2448 100644 --- a/services/include/form_data_mgr.h +++ b/services/include/form_data_mgr.h @@ -614,7 +614,6 @@ private: template bool GetAbilityFormInfo(const FormRecord &record, const std::vector &abilities, AbilityFormInfo &abilityFormInfo); - private: mutable std::recursive_mutex formRecordMutex_; mutable std::recursive_mutex formHostRecordMutex_; diff --git a/services/include/form_db_cache.h b/services/include/form_db_cache.h index 8249727375..c745619d1a 100644 --- a/services/include/form_db_cache.h +++ b/services/include/form_db_cache.h @@ -146,6 +146,8 @@ public: */ ErrCode DeleteInvalidDBForms(int32_t userId, int32_t callingUid, std::set &matchedFormIds, std::map &removedFormsMap); + + bool IsHostOwner(int64_t formId, int32_t hostUid); private: /** * @brief Save or update form data to DbCache and DB. diff --git a/services/src/form_db_cache.cpp b/services/src/form_db_cache.cpp index 5ccac2203a..3d4a448b60 100644 --- a/services/src/form_db_cache.cpp +++ b/services/src/form_db_cache.cpp @@ -421,5 +421,21 @@ ErrCode FormDbCache::DeleteInvalidDBForms(int32_t userId, int32_t callingUid, st HILOG_INFO("DeleteInvalidDBForms done"); return ERR_OK; } + +bool FormDbCache::IsHostOwner(int64_t formId, int32_t hostUid) +{ + FormDBInfo dbInfo; + if (GetDBRecord(formId, dbInfo) != ERR_OK) { + HILOG_ERROR("get db record failed. formId: %{public}s", std::to_string(formId).c_str()); + return false; + } + + auto iter = std::find(dbInfo.formUserUids.begin(), dbInfo.formUserUids.end(), hostUid); + if (iter != dbInfo.formUserUids.end()) { + return true; + } + + return false; +} } // namespace AppExecFwk } // namespace OHOS diff --git a/services/src/form_mgr_adapter.cpp b/services/src/form_mgr_adapter.cpp index 08547cf47a..c4fe5d2912 100644 --- a/services/src/form_mgr_adapter.cpp +++ b/services/src/form_mgr_adapter.cpp @@ -838,6 +838,15 @@ ErrCode FormMgrAdapter::AllotFormById(const FormItemInfo &info, HILOG_ERROR("%{public}s, addForm can not acquire temp form when select form id", __func__); return ERR_APPEXECFWK_FORM_COMMON_CODE; } + + // ark ts form can only exist with one form host + if (info.GetUiSyntax() == FormType::ETS && + !FormDbCache::GetInstance().IsHostOwner(formId, IPCSkeleton::GetCallingUid())) { + HILOG_ERROR("the specified form id does not exist in caller. formId: %{public}s.", + std::to_string(formId).c_str()); + return ERR_APPEXECFWK_FORM_CFG_NOT_MATCH_ID; + } + int32_t currentUserId = FormUtil::GetCurrentAccountId(); if (hasRecord && (record.providerUserId == currentUserId)) { if (!info.IsMatch(record)) { -- Gitee