From c777a64227d10f987659d7552e9d3e04baa2e6fd Mon Sep 17 00:00:00 2001 From: ShortMessage Date: Tue, 15 Apr 2025 10:59:31 +0800 Subject: [PATCH] =?UTF-8?q?UDMF=E9=80=9A=E9=81=93=E6=9E=84=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: ShortMessage --- .../udmf/lifecycle/lifecycle_manager.cpp | 3 ++ .../udmf/lifecycle/lifecycle_policy.cpp | 6 +++ .../service/udmf/lifecycle/lifecycle_policy.h | 1 + .../service/udmf/store/store_cache.cpp | 3 ++ .../service/udmf/udmf_service_impl.cpp | 37 ++++++++++++------- 5 files changed, 37 insertions(+), 13 deletions(-) diff --git a/services/distributeddataservice/service/udmf/lifecycle/lifecycle_manager.cpp b/services/distributeddataservice/service/udmf/lifecycle/lifecycle_manager.cpp index cbfdca07a..ce6f6609d 100644 --- a/services/distributeddataservice/service/udmf/lifecycle/lifecycle_manager.cpp +++ b/services/distributeddataservice/service/udmf/lifecycle/lifecycle_manager.cpp @@ -23,6 +23,9 @@ namespace UDMF { using CleanAfterGet = LifeCyclePolicy; std::unordered_map> LifeCycleManager::intentionPolicy_ = { { UD_INTENTION_MAP.at(UD_INTENTION_DRAG), std::make_shared() }, + { UD_INTENTION_MAP.at(UD_INTENTION_PICKER), std::make_shared() }, + { UD_INTENTION_MAP.at(UD_INTENTION_RIGHT_CLICK), std::make_shared() }, + { UD_INTENTION_MAP.at(UD_INTENTION_SYSTEM_SHARE), std::make_shared() }, { UD_INTENTION_MAP.at(UD_INTENTION_DATA_HUB), std::make_shared() } }; diff --git a/services/distributeddataservice/service/udmf/lifecycle/lifecycle_policy.cpp b/services/distributeddataservice/service/udmf/lifecycle/lifecycle_policy.cpp index 095a95f65..1015aae5d 100644 --- a/services/distributeddataservice/service/udmf/lifecycle/lifecycle_policy.cpp +++ b/services/distributeddataservice/service/udmf/lifecycle/lifecycle_policy.cpp @@ -59,6 +59,12 @@ Status LifeCyclePolicy::OnTimeout(const std::string &intention) return E_DB_ERROR; } std::vector timeoutKeys; + Duration interval = INTERVAL; + if (intention == UD_INTENTION_MAP.at(UD_INTENTION_SYSTEM_SHARE) + ||intention == UD_INTENTION_MAP.at(UD_INTENTION_PICKER) + ||intention == UD_INTENTION_MAP.at(UD_INTENTION_RIGHT_CLICK)) { + interval = SYSTEM_SHARE_INTERVAL; + } auto status = GetTimeoutKeys(store, INTERVAL, timeoutKeys); if (status != E_OK) { ZLOGE("Timeout keys get failed"); diff --git a/services/distributeddataservice/service/udmf/lifecycle/lifecycle_policy.h b/services/distributeddataservice/service/udmf/lifecycle/lifecycle_policy.h index f7703e562..d058b4fd0 100644 --- a/services/distributeddataservice/service/udmf/lifecycle/lifecycle_policy.h +++ b/services/distributeddataservice/service/udmf/lifecycle/lifecycle_policy.h @@ -23,6 +23,7 @@ class LifeCyclePolicy { public: using Duration = std::chrono::steady_clock::duration; static constexpr Duration INTERVAL = std::chrono::milliseconds(60 * 60 * 1000); + static constexpr Duration SYSTEM_SHARE_INTERVAL = std::chrono::milliseconds(24 * 60 * 60 * 1000); virtual ~LifeCyclePolicy() = default; virtual Status OnGot(const UnifiedKey &key); virtual Status OnStart(const std::string &intention); diff --git a/services/distributeddataservice/service/udmf/store/store_cache.cpp b/services/distributeddataservice/service/udmf/store/store_cache.cpp index 9bd6ae679..e72125a10 100644 --- a/services/distributeddataservice/service/udmf/store/store_cache.cpp +++ b/services/distributeddataservice/service/udmf/store/store_cache.cpp @@ -46,6 +46,9 @@ std::shared_ptr StoreCache::GetStore(std::string intention) } if (intention == UD_INTENTION_MAP.at(UD_INTENTION_DRAG) + || intention == UD_INTENTION_MAP.at(UD_INTENTION_PICKER) + || intention == UD_INTENTION_MAP.at(UD_INTENTION_RIGHT_CLICK) + || intention == UD_INTENTION_MAP.at(UD_INTENTION_SYSTEM_SHARE) || intention == UD_INTENTION_MAP.at(UD_INTENTION_DATA_HUB)) { storePtr = std::make_shared(intention); if (!storePtr->Init()) { diff --git a/services/distributeddataservice/service/udmf/udmf_service_impl.cpp b/services/distributeddataservice/service/udmf/udmf_service_impl.cpp index 42ef97a5d..e88bdcf10 100644 --- a/services/distributeddataservice/service/udmf/udmf_service_impl.cpp +++ b/services/distributeddataservice/service/udmf/udmf_service_impl.cpp @@ -224,7 +224,6 @@ int32_t UdmfServiceImpl::RetrieveData(const QueryOption &query, UnifiedData &uni ZLOGE("Get data incomplete,key:%{public}s", query.key.c_str()); return E_NOT_FOUND; } - CheckerManager::CheckInfo info; info.tokenId = query.tokenId; std::shared_ptr runtime = unifiedData.GetRuntime(); @@ -236,7 +235,6 @@ int32_t UdmfServiceImpl::RetrieveData(const QueryOption &query, UnifiedData &uni BizScene::GET_DATA, GetDataStage::VERIFY_PRIVILEGE, StageRes::FAILED, E_NO_PERMISSION); return E_NO_PERMISSION; } - if (key.intention == UD_INTENTION_MAP.at(UD_INTENTION_DRAG)) { int32_t ret = ProcessUri(query, unifiedData); if (ret != E_OK) { @@ -246,15 +244,15 @@ int32_t UdmfServiceImpl::RetrieveData(const QueryOption &query, UnifiedData &uni return E_NO_PERMISSION; } } - if (!IsReadAndKeep(runtime->privileges, query)) { - if (LifeCycleManager::GetInstance().OnGot(key) != E_OK) { - ZLOGE("Remove data failed:%{public}s", key.intention.c_str()); - return E_DB_ERROR; + if (key.intention != UD_INTENTION_MAP.at(UD_INTENTION_DATA_HUB)) { + if (!IsReadAndKeep(runtime->privileges, query)) { + if (LifeCycleManager::GetInstance().OnGot(key) != E_OK) { + ZLOGE("Remove data failed:%{public}s", key.intention.c_str()); + return E_DB_ERROR; + } } + privilegeCache_.erase(query.key); } - - privilegeCache_.erase(query.key); - PreProcessUtils::SetRemoteData(unifiedData); return E_OK; } @@ -387,6 +385,10 @@ int32_t UdmfServiceImpl::UpdateData(const QueryOption &query, UnifiedData &unifi ZLOGE("data or key is invalid,key=%{public}s", query.key.c_str()); return E_INVALID_PARAMETERS; } + if (key.intention != UD_INTENTION_MAP.at(UD_INTENTION_DATA_HUB)) { + ZLOGE("intention:%{public}s no permission", key.intention.c_str()); + return E_NO_PERMISSION; + } std::string bundleName; PreProcessUtils::GetHapBundleNameByToken(query.tokenId, bundleName); if (key.bundleName != bundleName && !HasDatahubPriviledge(bundleName)) { @@ -429,6 +431,11 @@ int32_t UdmfServiceImpl::UpdateData(const QueryOption &query, UnifiedData &unifi int32_t UdmfServiceImpl::DeleteData(const QueryOption &query, std::vector &unifiedDataSet) { ZLOGD("start"); + UnifiedKey key(query.key); + if (!key.IsValid()) { + ZLOGE("key is invalid,key=%{public}s", query.key.c_str()); + return E_INVALID_PARAMETERS; + } std::vector dataSet; std::shared_ptr store; auto status = QueryDataCommon(query, dataSet, store); @@ -440,6 +447,10 @@ int32_t UdmfServiceImpl::DeleteData(const QueryOption &query, std::vector runtime; std::vector deleteKeys; for (const auto &data : dataSet) { @@ -499,16 +510,16 @@ int32_t UdmfServiceImpl::AddPrivilege(const QueryOption &query, Privilege &privi if (!PreProcessUtils::GetNativeProcessNameByToken(query.tokenId, processName)) { return E_ERROR; } - + if (key.intention == UD_INTENTION_MAP.at(UD_INTENTION_DATA_HUB)) { + ZLOGE("intention:%{public}s no permission", key.intention.c_str()); + return E_NO_PERMISSION; + } if (key.intention == UD_INTENTION_MAP.at(UD_INTENTION_DRAG)) { if (find(DRAG_AUTHORIZED_PROCESSES, std::end(DRAG_AUTHORIZED_PROCESSES), processName) == std::end(DRAG_AUTHORIZED_PROCESSES)) { ZLOGE("Process:%{public}s lacks permission for intention:drag", processName.c_str()); return E_NO_PERMISSION; } - } else { - ZLOGE("Intention: %{public}s has no authorized processes", key.intention.c_str()); - return E_NO_PERMISSION; } auto store = StoreCache::GetInstance().GetStore(key.intention); -- Gitee