diff --git a/services/include/form_data_mgr.h b/services/include/form_data_mgr.h index 0faed95475015cc507f8aaa7ce80a0c2ff76fd6d..05c09c24485fe8d85ac12c4101167c359a45f360 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 8249727375db3c1e6c5f5aab5b7a927104fe0f28..c745619d1a96ee2c80fdf91dbe3a0864b12332f6 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 5ccac2203a78957f5de972748ef23b73a74a85bb..3d4a448b60f6356e04e4520a88a32b4e8063fca8 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 08547cf47ae8ccd47591b6012e9fcd1b321f96b6..c4fe5d2912055738b38e997809a55b9dd6aee26a 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)) {