diff --git a/BUILD.gn b/BUILD.gn index 8b98ab7..8cc737b 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -19,7 +19,6 @@ group("udmf_packages") { "interfaces/innerkits:udmf_client", "interfaces/jskits:udmf_data_napi", "interfaces/jskits:udmf_napi", - "service:udmf_server", ] } } @@ -36,8 +35,5 @@ group("unittest") { group("fuzztest") { testonly = true - deps = [ - "framework/innerkitsimpl/test/fuzztest:fuzztest", - "service/test/fuzztest:fuzztest", - ] + deps = [ "framework/innerkitsimpl/test/fuzztest:fuzztest" ] } diff --git a/framework/common/anonymous.cpp b/framework/common/anonymous.cpp deleted file mode 100755 index 7f45677..0000000 --- a/framework/common/anonymous.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "anonymous.h" - -namespace OHOS { -namespace UDMF { -constexpr int32_t HEAD_SIZE = 3; -constexpr int32_t END_SIZE = 3; -constexpr int32_t MIN_SIZE = HEAD_SIZE + END_SIZE + 3; -constexpr const char *REPLACE_CHAIN = "***"; -constexpr const char *DEFAULT_ANONYMOUS = "******"; -std::string Anonymous::Change(const std::string &name) -{ - if (name.length() <= HEAD_SIZE) { - return DEFAULT_ANONYMOUS; - } - - if (name.length() < MIN_SIZE) { - return (name.substr(0, HEAD_SIZE) + REPLACE_CHAIN); - } - - return (name.substr(0, HEAD_SIZE) + REPLACE_CHAIN + name.substr(name.length() - END_SIZE, END_SIZE)); -} -} // namespace UDMF -} // namespace OHOS diff --git a/framework/common/anonymous.h b/framework/common/anonymous.h deleted file mode 100755 index 893e0a2..0000000 --- a/framework/common/anonymous.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_UDMF_FRAMEWORKS_COMMON_ANONYMOUS_H -#define OHOS_UDMF_FRAMEWORKS_COMMON_ANONYMOUS_H - -#include - -namespace OHOS { -namespace UDMF { -class Anonymous { -public: - static std::string Change(const std::string &name); -}; -} // namespace UDMF -} // namespace OHOS -#endif // OHOS_UDMF_FRAMEWORKS_COMMON_ANONYMOUS_H diff --git a/framework/common/concurrent_map.h b/framework/common/concurrent_map.h deleted file mode 100755 index b50bedd..0000000 --- a/framework/common/concurrent_map.h +++ /dev/null @@ -1,286 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_UDMF_FRAMEWORKS_COMMON_CONCURRENT_MAP_H -#define OHOS_UDMF_FRAMEWORKS_COMMON_CONCURRENT_MAP_H -#include -#include -#include -namespace OHOS { -template -class ConcurrentMap { - template - static _First First(); - -public: - using map_type = typename std::map<_Key, _Tp>; - using filter_type = typename std::function; - using key_type = typename std::map<_Key, _Tp>::key_type; - using mapped_type = typename std::map<_Key, _Tp>::mapped_type; - using value_type = typename std::map<_Key, _Tp>::value_type; - using size_type = typename std::map<_Key, _Tp>::size_type; - using reference = typename std::map<_Key, _Tp>::reference; - using const_reference = typename std::map<_Key, _Tp>::const_reference; - - ConcurrentMap() = default; - ~ConcurrentMap() - { - Clear(); - } - - ConcurrentMap(const ConcurrentMap &other) - { - operator=(std::move(other)); - } - - ConcurrentMap &operator=(const ConcurrentMap &other) noexcept - { - if (this == &other) { - return *this; - } - auto tmp = other.Clone(); - std::lock_guard lock(mutex_); - entries_ = std::move(tmp); - return *this; - } - - ConcurrentMap(ConcurrentMap &&other) noexcept - { - operator=(std::move(other)); - } - - ConcurrentMap &operator=(ConcurrentMap &&other) noexcept - { - if (this == &other) { - return *this; - } - auto tmp = other.Steal(); - std::lock_guard lock(mutex_); - entries_ = std::move(tmp); - return *this; - } - - bool Emplace() noexcept - { - std::lock_guard lock(mutex_); - auto it = entries_.emplace(); - return it.second; - } - - template - typename std::enable_if()), filter_type>, bool>::type - Emplace(_Args &&...__args) noexcept - { - std::lock_guard lock(mutex_); - auto it = entries_.emplace(std::forward<_Args>(__args)...); - return it.second; - } - - template - typename std::enable_if, bool>::type - Emplace(const _Filter &filter, _Args &&...__args) noexcept - { - std::lock_guard lock(mutex_); - if (!filter(entries_)) { - return false; - } - auto it = entries_.emplace(std::forward<_Args>(__args)...); - return it.second; - } - - std::pair Find(const key_type &key) const noexcept - { - std::lock_guard lock(mutex_); - auto it = entries_.find(key); - if (it == entries_.end()) { - return std::pair { false, mapped_type() }; - } - - return std::pair { true, it->second }; - } - - bool Contains(const key_type &key) const noexcept - { - std::lock_guard lock(mutex_); - return (entries_.find(key) != entries_.end()); - } - - template - bool InsertOrAssign(const key_type &key, _Obj &&obj) noexcept - { - std::lock_guard lock(mutex_); - auto it = entries_.insert_or_assign(key, std::forward<_Obj>(obj)); - return it.second; - } - - bool Insert(const key_type &key, const mapped_type &value) noexcept - { - std::lock_guard lock(mutex_); - auto it = entries_.insert(value_type { key, value }); - return it.second; - } - - size_type Erase(const key_type &key) noexcept - { - std::lock_guard lock(mutex_); - return entries_.erase(key); - } - - void Clear() noexcept - { - std::lock_guard lock(mutex_); - return entries_.clear(); - } - - bool Empty() const noexcept - { - std::lock_guard lock(mutex_); - return entries_.empty(); - } - - size_type Size() const noexcept - { - std::lock_guard lock(mutex_); - return entries_.size(); - } - - // The action`s return true means meeting the erase condition - // The action`s return false means not meeting the erase condition - size_type EraseIf(const std::function &action) noexcept - { - if (action == nullptr) { - return 0; - } - std::lock_guard lock(mutex_); -#if __cplusplus > 201703L - auto count = std::erase_if(entries_, - [&action](value_type &value) -> bool { return action(value.first, value.second); }); -#else - auto count = entries_.size(); - for (auto it = entries_.begin(); it != entries_.end();) { - if (action((*it).first, (*it).second)) { - it = entries_.erase(it); - } else { - ++it; - } - } - count -= entries_.size(); -#endif - return count; - } - - mapped_type &operator[](const key_type &key) noexcept - { - std::lock_guard lock(mutex_); - return entries_[key]; - } - - void ForEach(const std::function &action) - { - if (action == nullptr) { - return; - } - std::lock_guard lock(mutex_); - for (auto &[key, value] : entries_) { - if (action(key, value)) { - break; - } - } - } - - void ForEachCopies(const std::function &action) - { - if (action == nullptr) { - return; - } - auto entries = Clone(); - for (auto &[key, value] : entries) { - if (action(key, value)) { - break; - } - } - } - - // The action's return value means that the element is keep in map or not; true means keeping, false means removing. - bool Compute(const key_type &key, const std::function &action) - { - if (action == nullptr) { - return false; - } - std::lock_guard lock(mutex_); - auto it = entries_.find(key); - if (it == entries_.end()) { - auto result = entries_.emplace(key, mapped_type()); - it = result.second ? result.first : entries_.end(); - } - if (it == entries_.end()) { - return false; - } - if (!action(it->first, it->second)) { - entries_.erase(key); - } - return true; - } - - // The action's return value means that the element is keep in map or not; true means keeping, false means removing. - bool ComputeIfPresent(const key_type &key, const std::function &action) - { - if (action == nullptr) { - return false; - } - std::lock_guard lock(mutex_); - auto it = entries_.find(key); - if (it == entries_.end()) { - return false; - } - if (!action(key, it->second)) { - entries_.erase(key); - } - return true; - } - - bool ComputeIfAbsent(const key_type &key, const std::function &action) - { - if (action == nullptr) { - return false; - } - std::lock_guard lock(mutex_); - auto it = entries_.find(key); - if (it != entries_.end()) { - return false; - } - entries_.emplace(key, action(key)); - return true; - } - -private: - std::map<_Key, _Tp> Steal() noexcept - { - std::lock_guard lock(mutex_); - return std::move(entries_); - } - - std::map<_Key, _Tp> Clone() const noexcept - { - std::lock_guard lock(mutex_); - return entries_; - } - -private: - mutable std::recursive_mutex mutex_; - std::map<_Key, _Tp> entries_; -}; -} // namespace OHOS -#endif // OHOS_UDMF_FRAMEWORKS_COMMON_CONCURRENT_MAP_H diff --git a/framework/common/same_process_ipc_guard.h b/framework/common/same_process_ipc_guard.h deleted file mode 100644 index 02ecb47..0000000 --- a/framework/common/same_process_ipc_guard.h +++ /dev/null @@ -1,43 +0,0 @@ -/* -* Copyright (c) 2023 Huawei Device Co., Ltd. -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#ifndef UDMF_SAMEPROCESSIPCGUARD_H -#define UDMF_SAMEPROCESSIPCGUARD_H - -#include - -#include "ipc_skeleton.h" - -namespace OHOS { -namespace UDMF { -class SameProcessIpcGuard { -public: - SameProcessIpcGuard() - { - identity = IPCSkeleton::ResetCallingIdentity(); - } - - ~SameProcessIpcGuard() - { - IPCSkeleton::SetCallingIdentity(identity); - } - -private: - std::string identity; -}; -} // namespace UDMF -} // namespace OHOS - -#endif // UDMF_SAMEPROCESSIPCGUARD_H \ No newline at end of file diff --git a/framework/common/tlv_object.h b/framework/common/tlv_object.h index eecb9b3..7e638d3 100755 --- a/framework/common/tlv_object.h +++ b/framework/common/tlv_object.h @@ -16,7 +16,6 @@ #ifndef UDMF_TLV_OBJECT_H #define UDMF_TLV_OBJECT_H -#include "logger.h" #include "securec.h" #include "error_code.h" #include "unified_meta.h" diff --git a/framework/common/tlv_util.h b/framework/common/tlv_util.h index 5780c6b..2e8daf3 100755 --- a/framework/common/tlv_util.h +++ b/framework/common/tlv_util.h @@ -25,7 +25,6 @@ #include "html.h" #include "image.h" #include "link.h" -#include "logger.h" #include "plain_text.h" #include "system_defined_appitem.h" #include "system_defined_form.h" diff --git a/framework/innerkitsimpl/test/fuzztest/udmfclient_fuzzer/BUILD.gn b/framework/innerkitsimpl/test/fuzztest/udmfclient_fuzzer/BUILD.gn index a2b220f..e8eca9a 100644 --- a/framework/innerkitsimpl/test/fuzztest/udmfclient_fuzzer/BUILD.gn +++ b/framework/innerkitsimpl/test/fuzztest/udmfclient_fuzzer/BUILD.gn @@ -25,10 +25,6 @@ ohos_fuzztest("UdmfClientFuzzTest") { "${udmf_interfaces_path}/innerkits/common", "${udmf_interfaces_path}/innerkits/data", "${udmf_framework_path}/common", - "${udmf_framework_path}/manager", - "${udmf_framework_path}/manager/container", - "${udmf_framework_path}/manager/store", - "${udmf_framework_path}/manager/preprocess", "${udmf_framework_path}/service", ] @@ -44,10 +40,7 @@ ohos_fuzztest("UdmfClientFuzzTest") { sources = [ "udmf_client_fuzzer.cpp" ] - deps = [ - "../../../../../interfaces/innerkits:udmf_client", - "../../../../../service:udmf_server", - ] + deps = [ "${udmf_interfaces_path}/innerkits:udmf_client" ] external_deps = [ "access_token:libaccesstoken_sdk", diff --git a/framework/innerkitsimpl/test/unittest/BUILD.gn b/framework/innerkitsimpl/test/unittest/BUILD.gn index 958a03f..26d4f28 100755 --- a/framework/innerkitsimpl/test/unittest/BUILD.gn +++ b/framework/innerkitsimpl/test/unittest/BUILD.gn @@ -22,11 +22,6 @@ config("module_private_config") { "${udmf_interfaces_path}/innerkits/common", "${udmf_interfaces_path}/innerkits/data", "${udmf_framework_path}/common", - "${udmf_framework_path}/manager", - "${udmf_framework_path}/manager/container", - "${udmf_framework_path}/manager/store", - "${udmf_framework_path}/manager/preprocess", - "${udmf_framework_path}/manager/permission", "${udmf_framework_path}/service", ] } @@ -35,7 +30,6 @@ common_deps = [ "${aafwk_path}/interfaces/inner_api/uri_permission:uri_permission_mgr", "${third_party_path}/googletest:gtest_main", "../../../../interfaces/innerkits:udmf_client", - "../../../../service:udmf_server", ] common_external_deps = [ diff --git a/framework/manager/data_manager.cpp b/framework/manager/data_manager.cpp deleted file mode 100755 index 133d315..0000000 --- a/framework/manager/data_manager.cpp +++ /dev/null @@ -1,347 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "data_manager.h" - -#include "checker_manager.h" -#include "file.h" -#include "lifecycle/lifecycle_manager.h" -#include "logger.h" -#include "preprocess_utils.h" -#include "uri_permission_manager.h" - -namespace OHOS { -namespace UDMF { -const std::string MSDP_PROCESS_NAME = "msdp_sa"; -const std::string DATA_PREFIX = "udmf://"; -DataManager::DataManager() -{ - authorizationMap_[UD_INTENTION_MAP.at(UD_INTENTION_DRAG)] = MSDP_PROCESS_NAME; - CheckerManager::GetInstance().LoadCheckers(); -} - -DataManager::~DataManager() -{ -} - -DataManager &DataManager::GetInstance() -{ - static DataManager instance; - return instance; -} - -int32_t DataManager::SaveData(CustomOption &option, UnifiedData &unifiedData, std::string &key) -{ - if (unifiedData.IsEmpty()) { - LOG_ERROR(UDMF_FRAMEWORK, "Invalid parameters, have no record"); - return E_INVALID_PARAMETERS; - } - - if (!UnifiedDataUtils::IsValidIntention(option.intention)) { - LOG_ERROR(UDMF_FRAMEWORK, "Invalid parameters intention: %{public}d.", option.intention); - return E_INVALID_PARAMETERS; - } - - // imput runtime info before put it into store and save one privilege - PreProcessUtils utils = PreProcessUtils::GetInstance(); - if (!utils.RuntimeDataImputation(unifiedData, option)) { - LOG_ERROR(UDMF_FRAMEWORK, "Imputation failed, %{public}s", utils.errorStr.c_str()); - return E_UNKNOWN; - } - for (const auto &record : unifiedData.GetRecords()) { - record->SetUid(PreProcessUtils::GetInstance().IdGenerator()); - } - - std::string intention = unifiedData.GetRuntime()->key.intention; - auto store = storeCache_.GetStore(intention); - if (store == nullptr) { - LOG_ERROR(UDMF_FRAMEWORK, "Get store failed, intention: %{public}s.", intention.c_str()); - return E_DB_ERROR; - } - - if (!UnifiedDataUtils::IsPersist(intention) && store->Clear() != E_OK) { - LOG_ERROR(UDMF_FRAMEWORK, "Clear store failed, intention: %{public}s.", intention.c_str()); - return E_DB_ERROR; - } - - if (store->Put(unifiedData) != E_OK) { - LOG_ERROR(UDMF_FRAMEWORK, "Put unified data failed, intention: %{public}s.", intention.c_str()); - return E_DB_ERROR; - } - key = unifiedData.GetRuntime()->key.GetUnifiedKey(); - LOG_DEBUG(UDMF_FRAMEWORK, "Put unified data successful, key: %{public}s.", key.c_str()); - return E_OK; -} - -int32_t DataManager::RetrieveData(const QueryOption &query, UnifiedData &unifiedData) -{ - UnifiedKey key(query.key); - if (!key.IsValid()) { - LOG_ERROR(UDMF_FRAMEWORK, "Unified key: %{public}s is invalid.", query.key.c_str()); - return E_INVALID_PARAMETERS; - } - auto store = storeCache_.GetStore(key.intention); - if (store == nullptr) { - LOG_ERROR(UDMF_FRAMEWORK, "Get store failed, intention: %{public}s.", key.intention.c_str()); - return E_DB_ERROR; - } - int32_t res = store->Get(query.key, unifiedData); - if (res != E_OK) { - LOG_ERROR(UDMF_FRAMEWORK, "Get data from store failed, intention: %{public}s.", key.intention.c_str()); - return res; - } - if (unifiedData.IsEmpty()) { - return E_OK; - } - std::shared_ptr runtime = unifiedData.GetRuntime(); - CheckerManager::CheckInfo info; - info.tokenId = query.tokenId; - if (!CheckerManager::GetInstance().IsValid(runtime->privileges, info)) { - return E_NO_PERMISSION; - } - std::string bundleName; - if (!PreProcessUtils::GetInstance().GetHapBundleNameByToken(query.tokenId, bundleName)) { - return E_ERROR; - } - if (runtime->createPackage != bundleName) { - auto records = unifiedData.GetRecords(); - for (auto record : records) { - auto type = record->GetType(); - std::string uri = ""; - if (type == UDType::FILE || type == UDType::IMAGE || type == UDType::VIDEO || type == UDType::AUDIO - || type == UDType::FOLDER) { - auto file = static_cast(record.get()); - uri = file->GetUri(); - } - if (!uri.empty() && (UriPermissionManager::GetInstance().GrantUriPermission(uri, bundleName) != E_OK)) { - return E_NO_PERMISSION; - } - } - } - if (LifeCycleManager::GetInstance().DeleteOnGet(key) != E_OK) { - LOG_ERROR(UDMF_FRAMEWORK, "Remove data failed, intention: %{public}s.", key.intention.c_str()); - return E_DB_ERROR; - } - return E_OK; -} - -int32_t DataManager::RetrieveBatchData(const QueryOption &query, std::vector &unifiedDataSet) -{ - std::vector dataSet; - std::shared_ptr store; - auto status = QueryDataCommon(query, dataSet, store); - if (status != E_OK) { - LOG_ERROR(UDMF_FRAMEWORK, "QueryDataCommon failed."); - return status; - } - if (dataSet.empty()) { - LOG_WARN(UDMF_FRAMEWORK, "has no data, key: %{public}s, intention: %{public}d.", query.key.c_str(), - query.intention); - return E_OK; - } - for (const auto &data : dataSet) { - unifiedDataSet.push_back(data); - } - return E_OK; -} - -int32_t DataManager::UpdateData(const QueryOption &query, UnifiedData &unifiedData) -{ - UnifiedKey key(query.key); - if (!key.IsValid()) { - LOG_ERROR(UDMF_FRAMEWORK, "Unified key: %{public}s is invalid.", query.key.c_str()); - return E_INVALID_PARAMETERS; - } - if (unifiedData.IsEmpty()) { - LOG_ERROR(UDMF_FRAMEWORK, "Invalid parameters, unified data has no record."); - return E_INVALID_PARAMETERS; - } - auto store = storeCache_.GetStore(key.intention); - if (store == nullptr) { - LOG_ERROR(UDMF_FRAMEWORK, "Get store failed, intention: %{public}s.", key.intention.c_str()); - return E_DB_ERROR; - } - - UnifiedData data; - int32_t res = store->Get(query.key, data); - if (res != E_OK) { - LOG_ERROR(UDMF_FRAMEWORK, "Get data from store failed, intention: %{public}s.", key.intention.c_str()); - return res; - } - if (data.IsEmpty()) { - LOG_ERROR(UDMF_FRAMEWORK, "Invalid parameter, unified data has no record; intention: %{public}s.", - key.intention.c_str()); - return E_INVALID_PARAMETERS; - } - std::shared_ptr runtime = data.GetRuntime(); - runtime->lastModifiedTime = PreProcessUtils::GetInstance().GetTimeStamp(); - unifiedData.SetRuntime(*runtime); - for (const auto &record : unifiedData.GetRecords()) { - record->SetUid(PreProcessUtils::GetInstance().IdGenerator()); - } - if (store->Update(unifiedData) != E_OK) { - LOG_ERROR(UDMF_FRAMEWORK, "Update unified data failed, intention: %{public}s.", key.intention.c_str()); - return E_DB_ERROR; - } - return E_OK; -} -int32_t DataManager::DeleteData(const QueryOption &query, std::vector &unifiedDataSet) -{ - std::vector dataSet; - std::shared_ptr store; - auto status = QueryDataCommon(query, dataSet, store); - if (status != E_OK) { - LOG_ERROR(UDMF_FRAMEWORK, "QueryDataCommon failed."); - return status; - } - if (dataSet.empty()) { - LOG_WARN(UDMF_FRAMEWORK, "has no data, key: %{public}s, intention: %{public}d.", query.key.c_str(), - query.intention); - return E_OK; - } - std::shared_ptr runtime; - std::vector deleteKeys; - for (const auto &data : dataSet) { - runtime = data.GetRuntime(); - unifiedDataSet.push_back(data); - deleteKeys.push_back(runtime->key.key); - } - if (store->DeleteBatch(deleteKeys) != E_OK) { - LOG_ERROR(UDMF_FRAMEWORK, "Remove data failed."); - return E_DB_ERROR; - } - return E_OK; -} - -int32_t DataManager::GetSummary(const QueryOption &query, Summary &summary) -{ - UnifiedKey key(query.key); - if (!key.IsValid()) { - LOG_ERROR(UDMF_FRAMEWORK, "Unified key: %{public}s is invalid.", query.key.c_str()); - return E_INVALID_PARAMETERS; - } - - auto store = storeCache_.GetStore(key.intention); - if (store == nullptr) { - LOG_ERROR(UDMF_FRAMEWORK, "Get store failed, intention: %{public}s.", key.intention.c_str()); - return E_DB_ERROR; - } - - if (store->GetSummary(query.key, summary) != E_OK) { - LOG_ERROR(UDMF_FRAMEWORK, "Store get summary failed, intention: %{public}s.", key.intention.c_str()); - return E_DB_ERROR; - } - return E_OK; -} - -int32_t DataManager::AddPrivilege(const QueryOption &query, const Privilege &privilege) -{ - UnifiedKey key(query.key); - if (!key.IsValid()) { - LOG_ERROR(UDMF_FRAMEWORK, "Unified key: %{public}s is invalid.", query.key.c_str()); - return E_INVALID_PARAMETERS; - } - - std::string processName; - PreProcessUtils utils = PreProcessUtils::GetInstance(); - if (!utils.GetNativeProcessNameByToken(query.tokenId, processName)) { - LOG_ERROR(UDMF_FRAMEWORK, "%{public}s", utils.errorStr.c_str()); - return E_UNKNOWN; - } - - if (processName != authorizationMap_[key.intention]) { - LOG_ERROR(UDMF_FRAMEWORK, "Process: %{public}s have no permission", processName.c_str()); - return E_NO_PERMISSION; - } - - auto store = storeCache_.GetStore(key.intention); - if (store == nullptr) { - LOG_ERROR(UDMF_FRAMEWORK, "Get store failed, intention: %{public}s.", key.intention.c_str()); - return E_DB_ERROR; - } - - UnifiedData data; - int32_t res = store->Get(query.key, data); - if (res != E_OK) { - LOG_ERROR(UDMF_FRAMEWORK, "Get data from store failed, intention: %{public}s.", key.intention.c_str()); - return res; - } - - if (data.IsEmpty()) { - LOG_ERROR(UDMF_FRAMEWORK, "Invalid parameters, unified data has no record, intention: %{public}s.", - key.intention.c_str()); - return E_INVALID_PARAMETERS; - } - - data.GetRuntime()->privileges.emplace_back(privilege); - if (store->Update(data) != E_OK) { - LOG_ERROR(UDMF_FRAMEWORK, "Update unified data failed, intention: %{public}s.", key.intention.c_str()); - return E_DB_ERROR; - } - return E_OK; -} - -int32_t DataManager::Sync(const QueryOption &query, const std::vector &devices) -{ - UnifiedKey key(query.key); - if (!key.IsValid()) { - LOG_ERROR(UDMF_FRAMEWORK, "Unified key: %{public}s is invalid.", query.key.c_str()); - return E_INVALID_PARAMETERS; - } - - auto store = storeCache_.GetStore(key.intention); - if (store == nullptr) { - LOG_ERROR(UDMF_FRAMEWORK, "Get store failed, intention: %{public}s.", key.intention.c_str()); - return E_DB_ERROR; - } - - if (store->Sync(devices) != E_OK) { - LOG_ERROR(UDMF_FRAMEWORK, "Store sync failed, intention: %{public}s.", key.intention.c_str()); - return E_DB_ERROR; - } - return E_OK; -} - -int32_t DataManager::QueryDataCommon( - const QueryOption &query, std::vector &dataSet, std::shared_ptr &store) -{ - auto find = UD_INTENTION_MAP.find(query.intention); - std::string intention = find == UD_INTENTION_MAP.end() ? intention : find->second; - if (!UnifiedDataUtils::IsValidOptions(query.key, intention)) { - LOG_ERROR(UDMF_FRAMEWORK, "Unified key: %{public}s and intention: %{public}s is invalid.", query.key.c_str(), - intention.c_str()); - return E_INVALID_PARAMETERS; - } - std::string dataPrefix = DATA_PREFIX + intention; - UnifiedKey key(query.key); - key.IsValid(); - if (intention.empty()) { - dataPrefix = key.key; - intention = key.intention; - } - LOG_DEBUG(UDMF_FRAMEWORK, "dataPrefix = %{public}s, intention: %{public}s.", dataPrefix.c_str(), intention.c_str()); - store = storeCache_.GetStore(intention); - if (store == nullptr) { - LOG_ERROR(UDMF_FRAMEWORK, "Get store failed, intention: %{public}s.", intention.c_str()); - return E_DB_ERROR; - } - if (store->GetBatchData(dataPrefix, dataSet) != E_OK) { - LOG_ERROR(UDMF_FRAMEWORK, "Get dataSet failed, dataPrefix: %{public}s.", dataPrefix.c_str()); - return E_DB_ERROR; - } - return E_OK; -} -} // namespace UDMF -} // namespace OHOS \ No newline at end of file diff --git a/framework/manager/data_manager.h b/framework/manager/data_manager.h deleted file mode 100755 index 608d608..0000000 --- a/framework/manager/data_manager.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef UDMF_DATA_MANAGER_H -#define UDMF_DATA_MANAGER_H - -#include -#include -#include -#include - -#include "error_code.h" -#include "store_cache.h" -#include "unified_data.h" -#include "unified_types.h" - -namespace OHOS { -namespace UDMF { -class DataManager { -public: - virtual ~DataManager(); - - static DataManager &GetInstance(); - - int32_t SaveData(CustomOption &option, UnifiedData &unifiedData, std::string &key); - int32_t RetrieveData(const QueryOption &query, UnifiedData &unifiedData); - int32_t RetrieveBatchData(const QueryOption &query, std::vector &unifiedDataSet); - int32_t UpdateData(const QueryOption &query, UnifiedData &unifiedData); - int32_t DeleteData(const QueryOption &query, std::vector &unifiedDataSet); - int32_t GetSummary(const QueryOption &query, Summary &summary); - int32_t AddPrivilege(const QueryOption &query, const Privilege &privilege); - int32_t Sync(const QueryOption &query, const std::vector &devices); - -private: - DataManager(); - int32_t QueryDataCommon(const QueryOption &query, std::vector &dataSet, std::shared_ptr &store); - StoreCache storeCache_; - std::map authorizationMap_; -}; -} // namespace UDMF -} // namespace OHOS -#endif // UDMF_DATA_MANAGER_H diff --git a/framework/manager/lifecycle/clean_after_get.cpp b/framework/manager/lifecycle/clean_after_get.cpp deleted file mode 100644 index 54fc554..0000000 --- a/framework/manager/lifecycle/clean_after_get.cpp +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "clean_after_get.h" - -namespace OHOS { -namespace UDMF { -} // namespace UDMF -} // namespace OHOS \ No newline at end of file diff --git a/framework/manager/lifecycle/clean_after_get.h b/framework/manager/lifecycle/clean_after_get.h deleted file mode 100644 index 1e94b5f..0000000 --- a/framework/manager/lifecycle/clean_after_get.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef UDMF_CLEAN_AFTER_GET_H -#define UDMF_CLEAN_AFTER_GET_H -#include "lifecycle_policy.h" - -namespace OHOS { -namespace UDMF { -class CleanAfterGet : public LifeCyclePolicy { -public: -}; -} // namespace UDMF -} // namespace OHOS -#endif // UDMF_CLEAN_AFTER_GET_H diff --git a/framework/manager/lifecycle/clean_on_startup.cpp b/framework/manager/lifecycle/clean_on_startup.cpp deleted file mode 100644 index eef045f..0000000 --- a/framework/manager/lifecycle/clean_on_startup.cpp +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "clean_on_startup.h" - -namespace OHOS { -namespace UDMF { -Status CleanOnStartup::DeleteOnTimeout(const std::string &intention) -{ - return E_OK; -} - -Status CleanOnStartup::DeleteOnGet(const UnifiedKey &key) -{ - return E_OK; -} -} // namespace UDMF -} // namespace OHOS \ No newline at end of file diff --git a/framework/manager/lifecycle/clean_on_startup.h b/framework/manager/lifecycle/clean_on_startup.h deleted file mode 100644 index b269743..0000000 --- a/framework/manager/lifecycle/clean_on_startup.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef UDMF_CLEAN_ON_STARTUP_H -#define UDMF_CLEAN_ON_STARTUP_H -#include "lifecycle_policy.h" - -namespace OHOS { -namespace UDMF { -class CleanOnStartup : public LifeCyclePolicy { -public: - Status DeleteOnTimeout(const std::string &intention) override; - Status DeleteOnGet(const UnifiedKey &key) override; -}; -} // namespace UDMF -} // namespace OHOS -#endif // UDMF_CLEAN_ON_STARTUP_H diff --git a/framework/manager/lifecycle/clean_on_timeout.cpp b/framework/manager/lifecycle/clean_on_timeout.cpp deleted file mode 100644 index 6b36ead..0000000 --- a/framework/manager/lifecycle/clean_on_timeout.cpp +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "clean_on_timeout.h" - -namespace OHOS { -namespace UDMF { -Status CleanOnTimeout::DeleteOnStart(const std::string &intention) -{ - return LifeCyclePolicy::DeleteOnTimeout(intention); -} - -Status CleanOnTimeout::DeleteOnGet(const UnifiedKey &key) -{ - return E_OK; -} -} // namespace UDMF -} // namespace OHOS diff --git a/framework/manager/lifecycle/clean_on_timeout.h b/framework/manager/lifecycle/clean_on_timeout.h deleted file mode 100644 index d86be25..0000000 --- a/framework/manager/lifecycle/clean_on_timeout.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef UDMF_CLEAN_ON_TIMEOUT_H -#define UDMF_CLEAN_ON_TIMEOUT_H -#include "lifecycle_policy.h" - -namespace OHOS { -namespace UDMF { -class CleanOnTimeout : public LifeCyclePolicy { -public: - Status DeleteOnStart(const std::string &intention) override; - Status DeleteOnGet(const UnifiedKey &key) override; -}; -} // namespace UDMF -} // namespace OHOS -#endif // UDMF_CLEAN_ON_TIMEOUT_H diff --git a/framework/manager/lifecycle/lifecycle_manager.cpp b/framework/manager/lifecycle/lifecycle_manager.cpp deleted file mode 100644 index 19f662c..0000000 --- a/framework/manager/lifecycle/lifecycle_manager.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "lifecycle_manager.h" - -#include -#include - -namespace OHOS { -namespace UDMF { -std::shared_ptr LifeCycleManager::executorPool_ = std::make_shared(2, 1); - -std::unordered_map> LifeCycleManager::intentionPolicyMap_ = { - { UD_INTENTION_MAP.at(UD_INTENTION_DRAG), std::make_shared() }, -}; - -LifeCycleManager &LifeCycleManager::GetInstance() -{ - static LifeCycleManager instance; - return instance; -} - -Status LifeCycleManager::DeleteOnGet(const UnifiedKey &key) -{ - auto findPolicy = intentionPolicyMap_.find(key.intention); - if (findPolicy == intentionPolicyMap_.end()) { - LOG_ERROR(UDMF_SERVICE, "Invalid intention, intention: %{public}s.", key.intention.c_str()); - return E_INVALID_PARAMETERS; - } - auto policy = findPolicy->second; - return policy->DeleteOnGet(key); -} - -Status LifeCycleManager::DeleteOnStart() -{ - Status status = E_OK; - std::shared_ptr LifeCyclePolicy; - for (const auto &intentionPolicyPair : intentionPolicyMap_) { - LifeCyclePolicy = GetPolicy(intentionPolicyPair.first); - status = status == E_OK ? LifeCyclePolicy->DeleteOnStart(intentionPolicyPair.first) : status; - } - return status; -} - -Status LifeCycleManager::DeleteOnSchedule() -{ - ExecutorPool::TaskId taskId = - executorPool_->Schedule(&LifeCycleManager::DeleteOnTimeout, LifeCyclePolicy::INTERVAL); - if (taskId == ExecutorPool::INVALID_TASK_ID) { - LOG_ERROR(UDMF_SERVICE, "ExecutorPool Schedule failed."); - return E_ERROR; - } - LOG_INFO(UDMF_SERVICE, "ScheduleTask start, TaskId: %{public}" PRIu64 ".", taskId); - return E_OK; -} - -std::shared_ptr LifeCycleManager::GetPolicy(const std::string &intention) -{ - auto findPolicy = intentionPolicyMap_.find(intention); - if (findPolicy == intentionPolicyMap_.end()) { - return nullptr; - } - return findPolicy->second; -} - -Status LifeCycleManager::DeleteOnTimeout() -{ - Status status = E_OK; - std::shared_ptr LifeCyclePolicy; - for (const auto &intentionPolicyPair : intentionPolicyMap_) { - LifeCyclePolicy = LifeCycleManager::GetInstance().GetPolicy(intentionPolicyPair.first); - status = status == E_OK ? LifeCyclePolicy->DeleteOnTimeout(intentionPolicyPair.first) : status; - } - return status; -} -} // namespace UDMF -} // namespace OHOS \ No newline at end of file diff --git a/framework/manager/lifecycle/lifecycle_manager.h b/framework/manager/lifecycle/lifecycle_manager.h deleted file mode 100644 index e73032d..0000000 --- a/framework/manager/lifecycle/lifecycle_manager.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef UDMF_LIFECYCLE_MANAGER_H -#define UDMF_LIFECYCLE_MANAGER_H - -#include -#include -#include -#include -#include - -#include "clean_after_get.h" -#include "clean_on_startup.h" -#include "clean_on_timeout.h" -#include "executor_pool.h" -#include "lifecycle_policy.h" - -namespace OHOS { -namespace UDMF { -class LifeCycleManager { -public: - static LifeCycleManager &GetInstance(); - Status DeleteOnGet(const UnifiedKey &key); - Status DeleteOnStart(); - Status DeleteOnSchedule(); - -private: - static std::shared_ptr executorPool_; - static std::unordered_map> intentionPolicyMap_; - static std::shared_ptr GetPolicy(const std::string &intention); - static Status DeleteOnTimeout(); -}; -} // namespace UDMF -} // namespace OHOS -#endif // UDMF_LIFECYCLE_MANAGER_H diff --git a/framework/manager/lifecycle/lifecycle_policy.cpp b/framework/manager/lifecycle/lifecycle_policy.cpp deleted file mode 100644 index 5a4313a..0000000 --- a/framework/manager/lifecycle/lifecycle_policy.cpp +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "lifecycle_policy.h" - -#include - -namespace OHOS { -namespace UDMF { -using namespace std::chrono; -const LifeCyclePolicy::Duration LifeCyclePolicy::INTERVAL = milliseconds(60 * 60 * 1000); -const std::string LifeCyclePolicy::DATA_PREFIX = "udmf://"; - -Status LifeCyclePolicy::DeleteOnGet(const UnifiedKey &key) -{ - auto store = storeCache_.GetStore(key.intention); - if (store == nullptr) { - LOG_ERROR(UDMF_FRAMEWORK, "Get store failed, intention: %{public}s.", key.intention.c_str()); - return E_DB_ERROR; - } - if (store->Delete(key.key) != E_OK) { - LOG_ERROR(UDMF_FRAMEWORK, "Remove data failed, intention: %{public}s.", key.intention.c_str()); - return E_DB_ERROR; - } - return E_OK; -} - -Status LifeCyclePolicy::DeleteOnStart(const std::string &intention) -{ - auto store = storeCache_.GetStore(intention); - if (store == nullptr) { - LOG_ERROR(UDMF_FRAMEWORK, "Get store failed, intention: %{public}s.", intention.c_str()); - return E_DB_ERROR; - } - if (store->Clear() != E_OK) { - LOG_ERROR(UDMF_FRAMEWORK, "Remove data failed, intention: %{public}s.", intention.c_str()); - return E_DB_ERROR; - } - return E_OK; -} - -Status LifeCyclePolicy::DeleteOnTimeout(const std::string &intention) -{ - auto store = storeCache_.GetStore(intention); - if (store == nullptr) { - LOG_ERROR(UDMF_FRAMEWORK, "Get store failed, intention: %{public}s.", intention.c_str()); - return E_DB_ERROR; - } - std::vector timeoutKeys; - auto status = GetTimeoutKeys(store, INTERVAL, timeoutKeys); - if (status != E_OK) { - LOG_ERROR(UDMF_FRAMEWORK, "Get timeout keys failed."); - return E_DB_ERROR; - } - if (store->DeleteBatch(timeoutKeys) != E_OK) { - LOG_ERROR(UDMF_FRAMEWORK, "Remove data failed, intention: %{public}s.", intention.c_str()); - return E_DB_ERROR; - } - return E_OK; -} - -Status LifeCyclePolicy::GetTimeoutKeys( - const std::shared_ptr &store, Duration interval, std::vector &timeoutKeys) -{ - std::vector datas; - auto status = store->GetBatchData(DATA_PREFIX, datas); - if (status != E_OK) { - LOG_ERROR(UDMF_FRAMEWORK, "Get datas failed."); - return E_DB_ERROR; - } - if (datas.empty()) { - LOG_DEBUG(UDMF_FRAMEWORK, "entries is empty."); - return E_OK; - } - auto curTime = PreProcessUtils::GetInstance().GetTimeStamp(); - for (const auto &data : datas) { - if (curTime > data.GetRuntime()->createTime + duration_cast(interval).count() - || curTime < data.GetRuntime()->createTime) { - timeoutKeys.push_back(data.GetRuntime()->key.key); - } - } - return E_OK; -} -} // namespace UDMF -} // namespace OHOS \ No newline at end of file diff --git a/framework/manager/lifecycle/lifecycle_policy.h b/framework/manager/lifecycle/lifecycle_policy.h deleted file mode 100644 index c0168b1..0000000 --- a/framework/manager/lifecycle/lifecycle_policy.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef UDMF_LIFECYCLE_POLICY_H -#define UDMF_LIFECYCLE_POLICY_H - -#include -#include - -#include "logger.h" -#include "preprocess_utils.h" -#include "store_cache.h" -#include "unified_key.h" - -namespace OHOS { -namespace UDMF { -class LifeCyclePolicy { -public: - using Duration = std::chrono::steady_clock::duration; - static const Duration INTERVAL; - virtual ~LifeCyclePolicy() = default; - virtual Status DeleteOnGet(const UnifiedKey &key); - virtual Status DeleteOnStart(const std::string &intention); - virtual Status DeleteOnTimeout(const std::string &intention); - virtual Status GetTimeoutKeys( - const std::shared_ptr &store, Duration interval, std::vector &timeoutKeys); - -private: - static const std::string DATA_PREFIX; - StoreCache storeCache_; -}; -} // namespace UDMF -} // namespace OHOS - -#endif // UDMF_LIFECYCLE_POLICY_H diff --git a/framework/manager/permission/checker_manager.cpp b/framework/manager/permission/checker_manager.cpp deleted file mode 100755 index 1e92539..0000000 --- a/framework/manager/permission/checker_manager.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "checker_manager.h" - -namespace OHOS { -namespace UDMF { -const std::string DATA_CHECKER = "DataChecker"; -CheckerManager &CheckerManager::GetInstance() -{ - static CheckerManager instance; - return instance; -} - -void CheckerManager::RegisterChecker(const std::string &checker, std::function getter) -{ - getters_.ComputeIfAbsent(checker, [&getter](const auto &) { - return move(getter); - }); -} - -void CheckerManager::LoadCheckers() -{ - getters_.ForEach([this] (const auto &key, const auto &val) { - if (this->checkers_.find(key) != this->checkers_.end()) { - return false; - } - auto *checker = val(); - if (checker == nullptr) { - return false; - } - this->checkers_[key] = checker; - return false; - }); -} - -bool CheckerManager::IsValid(const std::vector &privileges, const CheckInfo &info) -{ - auto it = checkers_.find(DATA_CHECKER); - if (it == checkers_.end()) { - return true; - } - return it->second->IsValid(privileges, info); -} -} // namespace UDMF -} // namespace OHOS diff --git a/framework/manager/permission/checker_manager.h b/framework/manager/permission/checker_manager.h deleted file mode 100755 index 3145fd0..0000000 --- a/framework/manager/permission/checker_manager.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef UDMF_CHECKER_MANAGER_H -#define UDMF_CHECKER_MANAGER_H - -#include - -#include "concurrent_map.h" -#include "unified_types.h" - -namespace OHOS { -namespace UDMF { -class CheckerManager { -public: - struct CheckInfo { - uint32_t tokenId; - }; - - class Checker { - public: - virtual bool IsValid(const std::vector &privileges, const CheckInfo &info) = 0; - protected: - ~Checker() = default; - }; - - static CheckerManager &GetInstance(); - - void RegisterChecker(const std::string &checker, std::function getter); - void LoadCheckers(); - bool IsValid(const std::vector &privileges, const CheckInfo &info); - -private: - std::map checkers_; - ConcurrentMap> getters_; -}; -} // namespace UDMF -} // namespace OHOS -#endif // UDMF_CHECKER_MANAGER_H \ No newline at end of file diff --git a/framework/manager/permission/data_checker.cpp b/framework/manager/permission/data_checker.cpp deleted file mode 100755 index 389a852..0000000 --- a/framework/manager/permission/data_checker.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "data_checker.h" - -#include "logger.h" -#include "anonymous.h" - -namespace OHOS { -namespace UDMF { -__attribute__((used)) DataChecker DataChecker::instance_; -DataChecker::DataChecker() noexcept -{ - CheckerManager::GetInstance().RegisterChecker( - "DataChecker", [this]() -> auto { return this; }); -} - -DataChecker::~DataChecker() -{ -} - -bool DataChecker::IsValid(const std::vector &privileges, const CheckerManager::CheckInfo &info) -{ - for (const auto &privilege : privileges) { - if (privilege.tokenId == info.tokenId) { - return true; - } - } - LOG_ERROR(UDMF_FRAMEWORK, "Invalid parameters, %{public}s", - Anonymous::Change(std::to_string(info.tokenId)).c_str()); - return false; -} -} // namespace UDMF -} // namespace OHOS \ No newline at end of file diff --git a/framework/manager/permission/data_checker.h b/framework/manager/permission/data_checker.h deleted file mode 100755 index 5aec008..0000000 --- a/framework/manager/permission/data_checker.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef UDMF_DATA_CHECKER_H -#define UDMF_DATA_CHECKER_H - -#include "checker_manager.h" - -namespace OHOS { -namespace UDMF { -class DataChecker : public CheckerManager::Checker { -public: - DataChecker() noexcept; - ~DataChecker(); - - bool IsValid(const std::vector &privileges, const CheckerManager::CheckInfo &info) override; - -private: - static DataChecker instance_; -}; -} // namespace UDMF -} // namespace OHOS -#endif // UDMF_DATA_CHECKER_H \ No newline at end of file diff --git a/framework/manager/permission/uri_permission_manager.cpp b/framework/manager/permission/uri_permission_manager.cpp deleted file mode 100755 index 6c9c41b..0000000 --- a/framework/manager/permission/uri_permission_manager.cpp +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "uri_permission_manager.h" -#include "uri_permission_manager_client.h" - -#include "want.h" -#include "uri.h" - -#include "logger.h" - -namespace OHOS { -namespace UDMF { -UriPermissionManager &UriPermissionManager::GetInstance() -{ - static UriPermissionManager instance; - return instance; -} - -Status UriPermissionManager::GrantUriPermission(const std::string &path, const std::string &bundleName) -{ - Uri uri(path); - int autoRemove = 1; - auto status = AAFwk::UriPermissionManagerClient::GetInstance().GrantUriPermission( - uri, AAFwk::Want::FLAG_AUTH_READ_URI_PERMISSION, bundleName, autoRemove); - if (status != ERR_OK) { - LOG_ERROR(UDMF_FRAMEWORK, "GrantUriPermission failed, %{public}d", status); - return E_ERROR; - } - return E_OK; -} -} // namespace UDMF -} // namespace OHOS diff --git a/framework/manager/permission/uri_permission_manager.h b/framework/manager/permission/uri_permission_manager.h deleted file mode 100755 index db32e31..0000000 --- a/framework/manager/permission/uri_permission_manager.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef UDMF_URI_PERMISSION_MANAGER_H -#define UDMF_URI_PERMISSION_MANAGER_H - -#include -#include - -#include "error_code.h" - -namespace OHOS { -namespace UDMF { -class UriPermissionManager { -public: - static UriPermissionManager &GetInstance(); - Status GrantUriPermission(const std::string &path, const std::string &bundleName); -}; -} // namespace UDMF -} // namespace OHOS -#endif // UDMF_URI_PERMISSION_MANAGER_H \ No newline at end of file diff --git a/framework/manager/preprocess/preprocess_utils.cpp b/framework/manager/preprocess/preprocess_utils.cpp deleted file mode 100755 index 0e70375..0000000 --- a/framework/manager/preprocess/preprocess_utils.cpp +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "preprocess_utils.h" - -#include - -#include "accesstoken_kit.h" -#include "bundlemgr/bundle_mgr_client_impl.h" -#include "ipc_skeleton.h" - -namespace OHOS { -namespace UDMF { -static constexpr int ID_LEN = 32; -const char SPECIAL = '^'; -PreProcessUtils &PreProcessUtils::GetInstance() -{ - static auto instance = new PreProcessUtils(); - return *instance; -} - -bool PreProcessUtils::RuntimeDataImputation(UnifiedData &data, CustomOption &option) -{ - auto it = UD_INTENTION_MAP.find(option.intention); - if (it == UD_INTENTION_MAP.end()) { - errorStr = "invalid intention"; - return false; - } - std::string bundleName; - GetHapBundleNameByToken(option.tokenId, bundleName); - std::string intention = it->second; - UnifiedKey key(intention, bundleName, IdGenerator()); - Privilege privilege; - privilege.tokenId = option.tokenId; - Runtime runtime; - runtime.key = key; - runtime.privileges.emplace_back(privilege); - runtime.createTime = GetTimeStamp(); - runtime.sourcePackage = bundleName; - runtime.createPackage = bundleName; - data.SetRuntime(runtime); - return true; -} - -std::string PreProcessUtils::IdGenerator() -{ - std::random_device randomDevice; - int minimum = 48; - int maximum = 121; - std::uniform_int_distribution distribution(minimum, maximum); - std::stringstream idStr; - for (int32_t i = 0; i < ID_LEN; i++) { - auto asc = distribution(randomDevice); - asc = asc >= SPECIAL ? asc + 1 : asc; - idStr << static_cast(asc); - } - return idStr.str(); -} - -time_t PreProcessUtils::GetTimeStamp() -{ - std::chrono::time_point tp = - std::chrono::time_point_cast(std::chrono::system_clock::now()); - time_t timestamp = tp.time_since_epoch().count(); - return timestamp; -} - -bool PreProcessUtils::GetHapBundleNameByToken(uint32_t tokenId, std::string &bundleName) -{ - Security::AccessToken::HapTokenInfo hapInfo; - if (Security::AccessToken::AccessTokenKit::GetHapTokenInfo(tokenId, hapInfo) - != Security::AccessToken::AccessTokenKitRet::RET_SUCCESS) { - errorStr = "get bundle info error"; - return false; - } - bundleName = hapInfo.bundleName; - return true; -} - -bool PreProcessUtils::GetNativeProcessNameByToken(uint32_t tokenId, std::string &processName) -{ - Security::AccessToken::NativeTokenInfo nativeInfo; - if (Security::AccessToken::AccessTokenKit::GetNativeTokenInfo(tokenId, nativeInfo) - != Security::AccessToken::AccessTokenKitRet::RET_SUCCESS) { - errorStr = "get native info error"; - return false; - } - processName = nativeInfo.processName; - return true; -} -} // namespace UDMF -} // namespace OHOS \ No newline at end of file diff --git a/framework/manager/preprocess/preprocess_utils.h b/framework/manager/preprocess/preprocess_utils.h deleted file mode 100644 index 41e2b46..0000000 --- a/framework/manager/preprocess/preprocess_utils.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef UDMF_PREPROCESS_UTILS_H -#define UDMF_PREPROCESS_UTILS_H - -#include -#include -#include -#include - -#include "logger.h" -#include "unified_data.h" -#include "unified_meta.h" - -namespace OHOS { -namespace UDMF { -class PreProcessUtils { -public: - static PreProcessUtils &GetInstance(); - /* - * Data Imputation - */ - bool RuntimeDataImputation(UnifiedData &data, CustomOption &option); - std::string IdGenerator(); - time_t GetTimeStamp(); - bool GetHapBundleNameByToken(uint32_t tokenId, std::string &bundleName); - bool GetNativeProcessNameByToken(uint32_t tokenId, std::string &processName); - std::string errorStr; -}; -} // namespace UDMF -} // namespace OHOS -#endif // UDMF_PREPROCESS_UTILS_H diff --git a/framework/manager/store/runtime_store.cpp b/framework/manager/store/runtime_store.cpp deleted file mode 100755 index 1613922..0000000 --- a/framework/manager/store/runtime_store.cpp +++ /dev/null @@ -1,312 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "runtime_store.h" - -#include -#include - -#include "logger.h" -#include "same_process_ipc_guard.h" -#include "tlv_util.h" - -namespace OHOS { -namespace UDMF { -using namespace DistributedKv; -const AppId RuntimeStore::APP_ID = { "distributeddata" }; -const std::string RuntimeStore::DATA_PREFIX = "udmf://"; -const std::string RuntimeStore::BASE_DIR = "/data/service/el1/public/database/distributeddata"; - -RuntimeStore::RuntimeStore(const std::string &storeId) : storeId_({ storeId }) -{ - updateTime(); - LOG_INFO(UDMF_SERVICE, "Construct runtimeStore: %{public}s.", storeId_.storeId.c_str()); -} - -RuntimeStore::~RuntimeStore() -{ - LOG_INFO(UDMF_SERVICE, "Destruct runtimeStore: %{public}s.", storeId_.storeId.c_str()); - Close(); -} - -Status RuntimeStore::Put(const UnifiedData &unifiedData) -{ - updateTime(); - std::vector entries; - std::string unifiedKey = unifiedData.GetRuntime()->key.GetUnifiedKey(); - // add unified record - for (const auto &record : unifiedData.GetRecords()) { - if (record == nullptr) { - LOG_ERROR(UDMF_SERVICE, "record is nullptr."); - return E_INVALID_PARAMETERS; - } - - std::vector recordBytes; - auto recordTlv = TLVObject(recordBytes); - if (!TLVUtil::Writing(record, recordTlv)) { - LOG_ERROR(UDMF_SERVICE, "Marshall unified record failed."); - return E_WRITE_PARCEL_ERROR; - } - - Entry entry = { Key(unifiedKey + "/" + record->GetUid()), Value(recordBytes) }; - entries.push_back(entry); - } - // add runtime info - std::vector runtimeBytes; - auto runtimeTlv = TLVObject(runtimeBytes); - if (!TLVUtil::Writing(*unifiedData.GetRuntime(), runtimeTlv)) { - LOG_ERROR(UDMF_SERVICE, "Marshall runtime info failed."); - return E_WRITE_PARCEL_ERROR; - } - Entry entry = { Key(unifiedKey), Value(runtimeBytes) }; - entries.push_back(entry); - auto status = PutEntries(entries); - return status; -} - -Status RuntimeStore::Get(const std::string &key, UnifiedData &unifiedData) -{ - updateTime(); - std::vector entries; - if (GetEntries(key, entries) != E_OK) { - LOG_ERROR(UDMF_FRAMEWORK, "GetEntries failed, dataPrefix: %{public}s.", key.c_str()); - return E_DB_ERROR; - } - if (entries.empty()) { - LOG_DEBUG(UDMF_FRAMEWORK, "entries is empty."); - return E_OK; - } - return UnMarshalEntries(key, entries, unifiedData); -} - -Status RuntimeStore::GetSummary(const std::string &key, Summary &summary) -{ - updateTime(); - UnifiedData unifiedData; - if (Get(key, unifiedData) != E_OK) { - LOG_ERROR(UDMF_SERVICE, "Get unified data failed."); - return E_DB_ERROR; - } - - for (const auto &record : unifiedData.GetRecords()) { - int64_t recordSize = record->GetSize(); - auto it = summary.summary.find(UD_TYPE_MAP.at(record->GetType())); - if (it == summary.summary.end()) { - summary.summary[UD_TYPE_MAP.at(record->GetType())] = recordSize; - } else { - summary.summary[UD_TYPE_MAP.at(record->GetType())] += recordSize; - } - summary.totalSize += recordSize; - } - return E_OK; -} - -Status RuntimeStore::Update(const UnifiedData &unifiedData) -{ - updateTime(); - std::string key = unifiedData.GetRuntime()->key.key; - if (Delete(key) != E_OK) { - LOG_ERROR(UDMF_SERVICE, "Delete unified data failed."); - return E_DB_ERROR; - } - if (Put(unifiedData) != E_OK) { - LOG_ERROR(UDMF_SERVICE, "Put unified data failed."); - return E_DB_ERROR; - } - return E_OK; -} - -Status RuntimeStore::Delete(const std::string &key) -{ - updateTime(); - std::vector entries; - if (GetEntries(key, entries) != E_OK) { - LOG_ERROR(UDMF_FRAMEWORK, "GetEntries failed, dataPrefix: %{public}s.", key.c_str()); - return E_DB_ERROR; - } - if (entries.empty()) { - LOG_DEBUG(UDMF_FRAMEWORK, "entries is empty."); - return E_OK; - } - std::vector keys; - for (const auto &entry : entries) { - keys.push_back(entry.key); - } - return DeleteEntries(keys); -} - -Status RuntimeStore::DeleteBatch(const std::vector &unifiedKeys) -{ - updateTime(); - LOG_DEBUG(UDMF_SERVICE, "called!"); - if (unifiedKeys.empty()) { - LOG_DEBUG(UDMF_SERVICE, "No need to delete!"); - return E_OK; - } - for (const std::string &unifiedKey : unifiedKeys) { - if (Delete(unifiedKey) != E_OK) { - LOG_ERROR(UDMF_FRAMEWORK, "Delete failed, key: %{public}s.", unifiedKey.c_str()); - return E_DB_ERROR; - } - } - return E_OK; -} - -Status RuntimeStore::Sync(const std::vector &devices) -{ - updateTime(); - SameProcessIpcGuard ipcGuard; - DistributedKv::Status status = kvStore_->Sync(devices, SyncMode::PULL); - if (status != DistributedKv::Status::SUCCESS) { - LOG_ERROR(UDMF_SERVICE, "Sync kvStore failed, status: %{public}d.", status); - return E_DB_ERROR; - } - return E_OK; -} - -Status RuntimeStore::Clear() -{ - updateTime(); - return Delete(DATA_PREFIX); -} - -Status RuntimeStore::GetBatchData(const std::string &dataPrefix, std::vector &unifiedDataSet) -{ - updateTime(); - std::vector entries; - auto status = GetEntries(dataPrefix, entries); - if (status != E_OK) { - LOG_ERROR(UDMF_FRAMEWORK, "GetEntries failed, dataPrefix: %{public}s.", dataPrefix.c_str()); - return E_DB_ERROR; - } - if (entries.empty()) { - LOG_DEBUG(UDMF_FRAMEWORK, "entries is empty."); - return E_OK; - } - std::vector keySet; - for (const auto &entry : entries) { - std::string keyStr = entry.key.ToString(); - if (std::count(keyStr.begin(), keyStr.end(), '/') == SLASH_COUNT_IN_KEY) { - keySet.emplace_back(keyStr); - } - } - - for (const std::string &key : keySet) { - UnifiedData data; - if (UnMarshalEntries(key, entries, data) != E_OK) { - return E_READ_PARCEL_ERROR; - } - unifiedDataSet.emplace_back(data); - } - return E_OK; -} - -void RuntimeStore::Close() -{ - dataManager_.CloseKvStore(APP_ID, storeId_); -} - -bool RuntimeStore::Init() -{ - Options options; - options.autoSync = false; - options.createIfMissing = true; - options.rebuild = true; - options.backup = false; - options.securityLevel = SecurityLevel::S1; - options.baseDir = BASE_DIR; - options.area = Area::EL1; - options.kvStoreType = KvStoreType::SINGLE_VERSION; - SameProcessIpcGuard ipcGuard; - DistributedKv::Status status = dataManager_.GetSingleKvStore(options, APP_ID, storeId_, kvStore_); - if (status != DistributedKv::Status::SUCCESS) { - LOG_ERROR(UDMF_SERVICE, "GetKvStore: %{public}s failed, status: %{public}d.", storeId_.storeId.c_str(), status); - return false; - } - return true; -} - -Status RuntimeStore::GetEntries(const std::string &dataPrefix, std::vector &entries) -{ - DataQuery query; - query.KeyPrefix(dataPrefix); - query.OrderByWriteTime(true); - auto status = kvStore_->GetEntries(query, entries); - if (status != DistributedKv::Status::SUCCESS) { - LOG_ERROR(UDMF_SERVICE, "KvStore getEntries failed, status: %{public}d.", static_cast(status)); - return E_DB_ERROR; - } - return E_OK; -} - -Status RuntimeStore::PutEntries(const std::vector &entries) -{ - size_t size = entries.size(); - DistributedKv::Status status; - for (size_t index = 0; index < size; index += MAX_BATCH_SIZE) { - std::vector batchEntries( - entries.begin() + index, entries.begin() + std::min(index + MAX_BATCH_SIZE, size)); - status = kvStore_->PutBatch(batchEntries); - if (status != DistributedKv::Status::SUCCESS) { - LOG_ERROR(UDMF_SERVICE, "KvStore putBatch failed, status: %{public}d.", status); - return E_DB_ERROR; - } - } - return E_OK; -} - -Status RuntimeStore::DeleteEntries(const std::vector &keys) -{ - size_t size = keys.size(); - DistributedKv::Status status; - for (size_t index = 0; index < size; index += MAX_BATCH_SIZE) { - std::vector batchKeys(keys.begin() + index, keys.begin() + std::min(index + MAX_BATCH_SIZE, size)); - status = kvStore_->DeleteBatch(batchKeys); - if (status != DistributedKv::Status::SUCCESS) { - LOG_ERROR(UDMF_SERVICE, "KvStore deleteBatch failed, status: %{public}d.", status); - return E_DB_ERROR; - } - } - return E_OK; -} - -Status RuntimeStore::UnMarshalEntries(const std::string &key, std::vector &entries, UnifiedData &unifiedData) -{ - for (const auto &entry : entries) { - std::string keyStr = entry.key.ToString(); - if (keyStr == key) { - Runtime runtime; - auto runtimeTlv = TLVObject(const_cast &>(entry.value.Data())); - if (!TLVUtil::Reading(runtime, runtimeTlv)) { - LOG_ERROR(UDMF_SERVICE, "Unmarshall runtime info failed."); - return E_READ_PARCEL_ERROR; - } - unifiedData.SetRuntime(runtime); - break; - } - if (keyStr.find(key) == 0) { - std::shared_ptr record; - auto recordTlv = TLVObject(const_cast &>(entry.value.Data())); - if (!TLVUtil::Reading(record, recordTlv)) { - LOG_ERROR(UDMF_SERVICE, "Unmarshall unified record failed."); - return E_READ_PARCEL_ERROR; - } - unifiedData.AddRecord(record); - } - } - return E_OK; -} -} // namespace UDMF -} // namespace OHOS \ No newline at end of file diff --git a/framework/manager/store/runtime_store.h b/framework/manager/store/runtime_store.h deleted file mode 100755 index d819e64..0000000 --- a/framework/manager/store/runtime_store.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef UDMF_RUNTIMESTORE_H -#define UDMF_RUNTIMESTORE_H - -#include "distributed_kv_data_manager.h" -#include "single_kvstore.h" - -#include "store.h" - -namespace OHOS { -namespace UDMF { -class RuntimeStore final : public Store { -public: - explicit RuntimeStore(const std::string &storeId); - ~RuntimeStore(); - Status Put(const UnifiedData &unifiedData) override; - Status Get(const std::string &key, UnifiedData &unifiedData) override; - Status GetSummary(const std::string &key, Summary &summary) override; - Status Update(const UnifiedData &unifiedData) override; - Status Delete(const std::string &key) override; - Status DeleteBatch(const std::vector &unifiedKeys) override; - Status Sync(const std::vector &devices) override; - Status Clear() override; - Status GetBatchData(const std::string &dataPrefix, std::vector &unifiedDataSet) override; - void Close() override; - bool Init() override; - -private: - static const DistributedKv::AppId APP_ID; - static const std::string DATA_PREFIX; - static const std::string BASE_DIR; - static constexpr std::int32_t SLASH_COUNT_IN_KEY = 4; - static constexpr std::int32_t MAX_BATCH_SIZE = 128; - DistributedKv::DistributedKvDataManager dataManager_; - std::shared_ptr kvStore_; - DistributedKv::StoreId storeId_; - Status GetEntries(const std::string &dataPrefix, std::vector &entries); - Status PutEntries(const std::vector &entries); - Status DeleteEntries(const std::vector &keys); - Status UnMarshalEntries( - const std::string &key, std::vector &entries, UnifiedData &unifiedData); -}; -} // namespace UDMF -} // namespace OHOS -#endif // UDMF_RUNTIMESTORE_H diff --git a/framework/manager/store/store.h b/framework/manager/store/store.h deleted file mode 100755 index 70228f1..0000000 --- a/framework/manager/store/store.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef UDMF_STORE_H -#define UDMF_STORE_H - -#include -#include - -#include "error_code.h" -#include "unified_data.h" -#include "unified_key.h" -#include "unified_types.h" - - -namespace OHOS { -namespace UDMF { -class Store { -public: - using Time = std::chrono::steady_clock::time_point; - virtual Status Put(const UnifiedData &unifiedData) = 0; - virtual Status Get(const std::string &key, UnifiedData &unifiedData) = 0; - virtual Status GetSummary(const std::string &key, Summary &summary) = 0; - virtual Status Update(const UnifiedData &unifiedData) = 0; - virtual Status Delete(const std::string &key) = 0; - virtual Status DeleteBatch(const std::vector &unifiedKeys) = 0; - virtual Status Sync(const std::vector &devices) = 0; - virtual Status Clear() = 0; - virtual bool Init() = 0; - virtual void Close() = 0; - virtual Status GetBatchData(const std::string &dataPrefix, std::vector &unifiedDataSet) = 0; - - bool operator<(const Time &time) const - { - std::shared_lock lock(timeMutex_); - return time_ < time; - } - - void updateTime() - { - std::unique_lock lock(timeMutex_); - time_ = std::chrono::steady_clock::now() + std::chrono::minutes(INTERVAL); - } -private: - static constexpr int64_t INTERVAL = 1; // 1 min - mutable Time time_; - mutable std::shared_mutex timeMutex_; -}; -} // namespace UDMF -} // namespace OHOS -#endif // UDMF_STORE_H diff --git a/framework/manager/store/store_cache.cpp b/framework/manager/store/store_cache.cpp deleted file mode 100755 index 051b98a..0000000 --- a/framework/manager/store/store_cache.cpp +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "store_cache.h" -#include - -#include "logger.h" -#include "runtime_store.h" -#include "unified_meta.h" - -namespace OHOS { -namespace UDMF { -std::shared_ptr StoreCache::executorPool_ = std::make_shared(2, 1); - -std::shared_ptr StoreCache::GetStore(std::string intention) -{ - std::shared_ptr store; - stores_.Compute(intention, [&store](const auto &intention, std::shared_ptr &storePtr) -> bool { - if (storePtr != nullptr) { - store = storePtr; - return true; - } - - if (intention == UD_INTENTION_MAP.at(UD_INTENTION_DRAG) - || intention == UD_INTENTION_MAP.at(UD_INTENTION_DATA_HUB)) { - storePtr = std::make_shared(intention); - if (!storePtr->Init()) { - LOG_ERROR(UDMF_SERVICE, "Init runtime store failed."); - return false; - } - store = storePtr; - return true; - } - return false; - }); - - std::unique_lock lock(taskMutex_); - if (taskId_ == ExecutorPool::INVALID_TASK_ID) { - taskId_ = executorPool_->Schedule(std::chrono::minutes(INTERVAL), std::bind(&StoreCache::GarbageCollect, this)); - } - return store; -} - -void StoreCache::GarbageCollect() -{ - auto current = std::chrono::steady_clock::now(); - stores_.EraseIf([¤t](auto &key, std::shared_ptr &storePtr) { - if (*storePtr < current) { - LOG_DEBUG(UDMF_SERVICE, "GarbageCollect, stores:%{public}s time limit, will be close.", key.c_str()); - return true; - } - return false; - }); - std::unique_lock lock(taskMutex_); - if (!stores_.Empty()) { - LOG_DEBUG(UDMF_SERVICE, "GarbageCollect, stores size:%{public}zu", stores_.Size()); - taskId_ = executorPool_->Schedule(std::chrono::minutes(INTERVAL), std::bind(&StoreCache::GarbageCollect, this)); - } else { - taskId_ = ExecutorPool::INVALID_TASK_ID; - } -} -} // namespace UDMF -} // namespace OHOS diff --git a/framework/manager/store/store_cache.h b/framework/manager/store/store_cache.h deleted file mode 100755 index 59807f7..0000000 --- a/framework/manager/store/store_cache.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef UDMF_STORE_CACHE_H -#define UDMF_STORE_CACHE_H - -#include -#include - -#include "concurrent_map.h" -#include "executor_pool.h" -#include "store.h" -#include "unified_meta.h" - -namespace OHOS { -namespace UDMF { -class StoreCache { -public: - std::shared_ptr GetStore(std::string intention); - -private: - void GarbageCollect(); - - ConcurrentMap> stores_; - std::mutex taskMutex_; - ExecutorPool::TaskId taskId_ = ExecutorPool::INVALID_TASK_ID; - - static constexpr int64_t INTERVAL = 1; // 1 min - static std::shared_ptr executorPool_; -}; -} // namespace UDMF -} // namespace OHOS -#endif // UDMF_STORE_CACHE_H diff --git a/framework/service/udmf_service_proxy.cpp b/framework/service/udmf_service_proxy.cpp index 1768719..4c4be99 100755 --- a/framework/service/udmf_service_proxy.cpp +++ b/framework/service/udmf_service_proxy.cpp @@ -17,7 +17,7 @@ #include "ipc_types.h" -#include "preprocess_utils.h" +#include "logger.h" #include "tlv_util.h" #include "udmf_types_util.h" diff --git a/interfaces/innerkits/BUILD.gn b/interfaces/innerkits/BUILD.gn index acf7724..92de903 100755 --- a/interfaces/innerkits/BUILD.gn +++ b/interfaces/innerkits/BUILD.gn @@ -20,21 +20,18 @@ config("udmf_client_config") { "${udmf_interfaces_path}/innerkits/data", "${udmf_framework_path}/common", - "${udmf_framework_path}/manager", - "${udmf_framework_path}/manager/store", - "${udmf_framework_path}/manager/preprocess", - "${udmf_framework_path}/manager/permission", - "${udmf_framework_path}/manager/lifecycle", "${udmf_framework_path}/service", "${kv_store_path}/frameworks/common", "//third_party/libuv/include", "//third_party/node/src", + "${kv_store_path}/frameworks/innerkitsimpl/distributeddatafwk/include", + "${kv_store_path}/frameworks/innerkitsimpl/distributeddatafwk/src", + "${kv_store_path}/interfaces/innerkits/distributeddata/include", ] } ohos_shared_library("udmf_client") { sources = [ - "${udmf_framework_path}/common/anonymous.cpp", "${udmf_framework_path}/common/tlv_util.cpp", "${udmf_framework_path}/common/udmf_types_util.cpp", "${udmf_framework_path}/innerkitsimpl/client/udmf_client.cpp", @@ -56,18 +53,6 @@ ohos_shared_library("udmf_client") { "${udmf_framework_path}/innerkitsimpl/data/unified_data.cpp", "${udmf_framework_path}/innerkitsimpl/data/unified_record.cpp", "${udmf_framework_path}/innerkitsimpl/data/video.cpp", - "${udmf_framework_path}/manager/data_manager.cpp", - "${udmf_framework_path}/manager/lifecycle/clean_after_get.cpp", - "${udmf_framework_path}/manager/lifecycle/clean_on_startup.cpp", - "${udmf_framework_path}/manager/lifecycle/clean_on_timeout.cpp", - "${udmf_framework_path}/manager/lifecycle/lifecycle_manager.cpp", - "${udmf_framework_path}/manager/lifecycle/lifecycle_policy.cpp", - "${udmf_framework_path}/manager/permission/checker_manager.cpp", - "${udmf_framework_path}/manager/permission/data_checker.cpp", - "${udmf_framework_path}/manager/permission/uri_permission_manager.cpp", - "${udmf_framework_path}/manager/preprocess/preprocess_utils.cpp", - "${udmf_framework_path}/manager/store/runtime_store.cpp", - "${udmf_framework_path}/manager/store/store_cache.cpp", "${udmf_framework_path}/service/udmf_service_client.cpp", "${udmf_framework_path}/service/udmf_service_proxy.cpp", ] diff --git a/interfaces/jskits/BUILD.gn b/interfaces/jskits/BUILD.gn index 75f2aae..56c0a81 100755 --- a/interfaces/jskits/BUILD.gn +++ b/interfaces/jskits/BUILD.gn @@ -22,14 +22,8 @@ config("udmf_napi_config") { "${udmf_interfaces_path}/jskits/data", "${udmf_framework_path}/common", - "${udmf_framework_path}/manager", - "${udmf_framework_path}/manager/store", - "${udmf_framework_path}/manager/preprocess", - "${udmf_framework_path}/manager/permission", - "${udmf_framework_path}/manager/lifecycle", "${udmf_framework_path}/service", - "${udmf_service_path}/include", "//third_party/libuv/include", "//third_party/node/src", diff --git a/service/BUILD.gn b/service/BUILD.gn deleted file mode 100755 index 222c68c..0000000 --- a/service/BUILD.gn +++ /dev/null @@ -1,61 +0,0 @@ -# Copyright (c) 2022 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import("//build/ohos.gni") -import("//foundation/distributeddatamgr/udmf/udmf.gni") - -config("udmf_service_config") { - visibility = [ ":*" ] - include_dirs = [ "include" ] -} - -ohos_shared_library("udmf_server") { - include_dirs = [ - "${udmf_framework_path}/common", - "${udmf_framework_path}/manager", - "${udmf_framework_path}/manager/store", - "${udmf_framework_path}/manager/preprocess", - "${udmf_framework_path}/manager/permission", - "${udmf_framework_path}/manager/lifecycle", - "${udmf_framework_path}/service", - "${udmf_interfaces_path}/innerkits/client", - "${udmf_interfaces_path}/innerkits/common", - "${udmf_interfaces_path}/innerkits/data", - "${kv_store_path}/frameworks/common", - "${ddms_path}/services/distributeddataservice/framework/include", - "//third_party/libuv/include", - "//third_party/node/src", - ] - - sources = [ - "src/udmf_service_impl.cpp", - "src/udmf_service_stub.cpp", - ] - - configs = [ ":udmf_service_config" ] - - deps = [ - "${ddms_path}/services/distributeddataservice/framework:distributeddatasvcfwk", - "../interfaces/innerkits:udmf_client", - ] - - external_deps = [ - "access_token:libaccesstoken_sdk", - "c_utils:utils", - "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_core", - ] - - subsystem_name = "distributeddatamgr" - - part_name = "udmf" -} diff --git a/service/include/udmf_service_impl.h b/service/include/udmf_service_impl.h deleted file mode 100755 index 30b9daf..0000000 --- a/service/include/udmf_service_impl.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef UDMF_SERVICE_IMPL_H -#define UDMF_SERVICE_IMPL_H - -#include - -#include "udmf_service_stub.h" - -namespace OHOS { -namespace UDMF { -/* - * UDMF server implementation - */ -class UdmfServiceImpl final : public UdmfServiceStub { -public: - UdmfServiceImpl() = default; - ~UdmfServiceImpl() = default; - - int32_t SetData(CustomOption &option, UnifiedData &unifiedData, std::string &key) override; - int32_t GetData(const QueryOption &query, UnifiedData &unifiedData) override; - int32_t GetBatchData(const QueryOption &query, std::vector &unifiedDataSet) override; - int32_t UpdateData(const QueryOption &query, UnifiedData &unifiedData) override; - int32_t DeleteData(const QueryOption &query, std::vector &unifiedDataSet) override; - int32_t GetSummary(const QueryOption &query, Summary &summary) override; - int32_t AddPrivilege(const QueryOption &query, Privilege &privilege) override; - int32_t Sync(const QueryOption &query, const std::vector &devices) override; - int32_t OnInitialize() override; - -private: - class Factory { - public: - Factory(); - ~Factory(); - - private: - std::shared_ptr product_; - }; - static Factory factory_; -}; -} // namespace UDMF -} // namespace OHOS -#endif // UDMF_SERVICE_IMPL_H diff --git a/service/include/udmf_service_stub.h b/service/include/udmf_service_stub.h deleted file mode 100755 index 9684d2e..0000000 --- a/service/include/udmf_service_stub.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef UDMF_SERVICE_STUB_H -#define UDMF_SERVICE_STUB_H - -#include -#include - -#include "feature/feature_system.h" -#include "message_parcel.h" - -#include "error_code.h" -#include "udmf_service.h" - -namespace OHOS { -namespace UDMF { -/* - * UDMF server stub - */ -class UdmfServiceStub : public UdmfService, public DistributedData::FeatureSystem::Feature { -public: - UdmfServiceStub(); - virtual ~UdmfServiceStub() override; - int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply) override; - -private: - int32_t OnSetData(MessageParcel &data, MessageParcel &reply); - int32_t OnGetData(MessageParcel &data, MessageParcel &reply); - int32_t OnGetBatchData(MessageParcel &data, MessageParcel &reply); - int32_t OnUpdateData(MessageParcel &data, MessageParcel &reply); - int32_t OnDeleteData(MessageParcel &data, MessageParcel &reply); - int32_t OnGetSummary(MessageParcel &data, MessageParcel &reply); - int32_t OnAddPrivilege(MessageParcel &data, MessageParcel &reply); - int32_t OnSync(MessageParcel &data, MessageParcel &reply); - - bool VerifyPermission(const std::string &permission); - - const std::string READ_PERMISSION = "ohos.permission.READ_UDMF_DATA"; - const std::string WRITE_PERMISSION = "ohos.permission.WRITE_UDMF_DATA"; - const std::string SYNC_PERMISSION = "ohos.permission.SYNC_UDMF_DATA"; - - using UdmfServiceFunc = int32_t (UdmfServiceStub::*)(MessageParcel &data, MessageParcel &reply); - std::map memberFuncMap_; -}; -} // namespace UDMF -} // namespace OHOS -#endif // UDMF_SERVICE_STUB_H diff --git a/service/src/udmf_service_impl.cpp b/service/src/udmf_service_impl.cpp deleted file mode 100755 index d88b977..0000000 --- a/service/src/udmf_service_impl.cpp +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "udmf_service_impl.h" - -#include "iservice_registry.h" - -#include "data_manager.h" -#include "lifecycle/lifecycle_manager.h" -#include "logger.h" -#include "preprocess_utils.h" - -namespace OHOS { -namespace UDMF { -using FeatureSystem = DistributedData::FeatureSystem; -__attribute__((used)) UdmfServiceImpl::Factory UdmfServiceImpl::factory_; -UdmfServiceImpl::Factory::Factory() -{ - LOG_ERROR(UDMF_SERVICE, "Register udmf creator!"); - FeatureSystem::GetInstance().RegisterCreator("udmf", [this]() { - if (product_ == nullptr) { - product_ = std::make_shared(); - } - return product_; - }); -} - -UdmfServiceImpl::Factory::~Factory() -{ - product_ = nullptr; -} - -int32_t UdmfServiceImpl::SetData(CustomOption &option, UnifiedData &unifiedData, std::string &key) -{ - LOG_DEBUG(UDMF_SERVICE, "start"); - return DataManager::GetInstance().SaveData(option, unifiedData, key); -} - -int32_t UdmfServiceImpl::GetData(const QueryOption &query, UnifiedData &unifiedData) -{ - LOG_DEBUG(UDMF_SERVICE, "start"); - return DataManager::GetInstance().RetrieveData(query, unifiedData); -} - -int32_t UdmfServiceImpl::GetBatchData(const QueryOption &query, std::vector &unifiedDataSet) -{ - LOG_DEBUG(UDMF_SERVICE, "start"); - return DataManager::GetInstance().RetrieveBatchData(query, unifiedDataSet); -} - -int32_t UdmfServiceImpl::UpdateData(const QueryOption &query, UnifiedData &unifiedData) -{ - LOG_DEBUG(UDMF_SERVICE, "start"); - return DataManager::GetInstance().UpdateData(query, unifiedData); -} - -int32_t UdmfServiceImpl::DeleteData(const QueryOption &query, std::vector &unifiedDataSet) -{ - LOG_DEBUG(UDMF_SERVICE, "start"); - return DataManager::GetInstance().DeleteData(query, unifiedDataSet); -} - -int32_t UdmfServiceImpl::GetSummary(const QueryOption &query, Summary &summary) -{ - LOG_DEBUG(UDMF_SERVICE, "start"); - return DataManager::GetInstance().GetSummary(query, summary); -} - -int32_t UdmfServiceImpl::AddPrivilege(const QueryOption &query, Privilege &privilege) -{ - return DataManager::GetInstance().AddPrivilege(query, privilege); -} - -int32_t UdmfServiceImpl::Sync(const QueryOption &query, const std::vector &devices) -{ - return DataManager::GetInstance().Sync(query, devices); -} - -int32_t UdmfServiceImpl::OnInitialize() -{ - LOG_DEBUG(UDMF_SERVICE, "start"); - Status status = LifeCycleManager::GetInstance().DeleteOnStart(); - if (status != E_OK) { - LOG_ERROR(UDMF_SERVICE, "DeleteOnStart execute failed, status: %{public}d", status); - } - status = LifeCycleManager::GetInstance().DeleteOnSchedule(); - if (status != E_OK) { - LOG_ERROR(UDMF_SERVICE, "ScheduleTask start failed, status: %{public}d", status); - } - return DistributedData::FeatureSystem::STUB_SUCCESS; -} -} // namespace UDMF -} // namespace OHOS - diff --git a/service/src/udmf_service_stub.cpp b/service/src/udmf_service_stub.cpp deleted file mode 100755 index 9e1d21b..0000000 --- a/service/src/udmf_service_stub.cpp +++ /dev/null @@ -1,268 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "udmf_service_stub.h" - -#include - -#include "accesstoken_kit.h" -#include "ipc_skeleton.h" -#include "logger.h" -#include "udmf_types_util.h" -#include "unified_data.h" -#include "unified_meta.h" -namespace OHOS { -namespace UDMF { -UdmfServiceStub::UdmfServiceStub() -{ - memberFuncMap_[static_cast(SET_DATA)] = &UdmfServiceStub::OnSetData; - memberFuncMap_[static_cast(GET_DATA)] = &UdmfServiceStub::OnGetData; - memberFuncMap_[static_cast(GET_BATCH_DATA)] = &UdmfServiceStub::OnGetBatchData; - memberFuncMap_[static_cast(UPDATE_DATA)] = &UdmfServiceStub::OnUpdateData; - memberFuncMap_[static_cast(DELETE_DATA)] = &UdmfServiceStub::OnDeleteData; - memberFuncMap_[static_cast(GET_SUMMARY)] = &UdmfServiceStub::OnGetSummary; - memberFuncMap_[static_cast(ADD_PRIVILEGE)] = &UdmfServiceStub::OnAddPrivilege; - memberFuncMap_[static_cast(SYNC)] = &UdmfServiceStub::OnSync; -} - -UdmfServiceStub::~UdmfServiceStub() -{ - memberFuncMap_.clear(); -} - -int UdmfServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply) -{ - LOG_INFO(UDMF_SERVICE, "start##code = %{public}u", code); - std::u16string myDescripter = UdmfServiceStub::GetDescriptor(); - std::u16string remoteDescripter = data.ReadInterfaceToken(); - if (myDescripter != remoteDescripter) { - LOG_ERROR(UDMF_SERVICE, "end##descriptor checked fail"); - return -1; - } - if (CODE_HEAD > code || code >= CODE_BUTT) { - return -1; - } - auto itFunc = memberFuncMap_.find(code); - if (itFunc != memberFuncMap_.end()) { - auto memberFunc = itFunc->second; - if (memberFunc != nullptr) { - return (this->*memberFunc)(data, reply); - } - } - LOG_INFO(UDMF_SERVICE, "end##ret = -1"); - return -1; -} - -int32_t UdmfServiceStub::OnSetData(MessageParcel &data, MessageParcel &reply) -{ - LOG_INFO(UDMF_SERVICE, "start"); - CustomOption customOption; - UnifiedData unifiedData; - if (!ITypesUtil::Unmarshal(data, customOption, unifiedData)) { - LOG_ERROR(UDMF_SERVICE, "Unmarshal customOption or unifiedData failed!"); - return E_READ_PARCEL_ERROR; - } - if (unifiedData.IsEmpty()) { - LOG_ERROR(UDMF_SERVICE, "Empty data without any record!"); - return E_INVALID_PARAMETERS; - } - if (unifiedData.GetSize() > UdmfService::MAX_DATA_SIZE) { - LOG_ERROR(UDMF_SERVICE, "Exceeded data limit!"); - return E_INVALID_PARAMETERS; - } - for (const auto &record : unifiedData.GetRecords()) { - if (record == nullptr) { - LOG_ERROR(UDMF_SERVICE, "record is nullptr!"); - return E_INVALID_PARAMETERS; - } - if (record->GetSize() > UdmfService::MAX_RECORD_SIZE) { - LOG_ERROR(UDMF_SERVICE, "Exceeded record limit!"); - return E_INVALID_PARAMETERS; - } - } - uint32_t token = IPCSkeleton::GetCallingTokenID(); - customOption.tokenId = token; - std::string key; - int32_t status = SetData(customOption, unifiedData, key); - if (!ITypesUtil::Marshal(reply, status, key)) { - LOG_ERROR(UDMF_SERVICE, "Marshal status or key failed, status: %{public}d, key: %{public}s", status, - key.c_str()); - return E_WRITE_PARCEL_ERROR; - } - return E_OK; -} - -int32_t UdmfServiceStub::OnGetData(MessageParcel &data, MessageParcel &reply) -{ - LOG_INFO(UDMF_SERVICE, "start"); - QueryOption query; - if (!ITypesUtil::Unmarshal(data, query)) { - LOG_ERROR(UDMF_SERVICE, "Unmarshal queryOption failed!"); - return E_READ_PARCEL_ERROR; - } - uint32_t token = IPCSkeleton::GetCallingTokenID(); - query.tokenId = token; - UnifiedData unifiedData; - int32_t status = GetData(query, unifiedData); - if (!ITypesUtil::Marshal(reply, status, unifiedData)) { - LOG_ERROR(UDMF_SERVICE, "Marshal status or unifiedData failed, status: %{public}d", status); - return E_WRITE_PARCEL_ERROR; - } - return E_OK; -} - -int32_t UdmfServiceStub::OnGetBatchData(MessageParcel &data, MessageParcel &reply) -{ - LOG_INFO(UDMF_SERVICE, "start"); - QueryOption query; - if (!ITypesUtil::Unmarshal(data, query)) { - LOG_ERROR(UDMF_SERVICE, "Unmarshal queryOption failed!"); - return E_READ_PARCEL_ERROR; - } - uint32_t token = IPCSkeleton::GetCallingTokenID(); - query.tokenId = token; - std::vector unifiedDataSet; - int32_t status = GetBatchData(query, unifiedDataSet); - if (!ITypesUtil::Marshal(reply, status, unifiedDataSet)) { - LOG_ERROR(UDMF_SERVICE, "Marshal status or unifiedDataSet failed, status: %{public}d", status); - return E_WRITE_PARCEL_ERROR; - } - return E_OK; -} - -int32_t UdmfServiceStub::OnUpdateData(MessageParcel &data, MessageParcel &reply) -{ - LOG_INFO(UDMF_SERVICE, "start"); - QueryOption query; - UnifiedData unifiedData; - if (!ITypesUtil::Unmarshal(data, query, unifiedData)) { - LOG_ERROR(UDMF_SERVICE, "Unmarshal queryOption or unifiedData failed!"); - return E_READ_PARCEL_ERROR; - } - if (unifiedData.IsEmpty()) { - LOG_ERROR(UDMF_SERVICE, "Empty data without any record!"); - return E_INVALID_PARAMETERS; - } - if (unifiedData.GetSize() > UdmfService::MAX_DATA_SIZE) { - LOG_ERROR(UDMF_SERVICE, "Exceeded data limit!"); - return E_INVALID_PARAMETERS; - } - for (const auto &record : unifiedData.GetRecords()) { - if (record->GetSize() > UdmfService::MAX_RECORD_SIZE) { - LOG_ERROR(UDMF_SERVICE, "Exceeded record limit!"); - return E_INVALID_PARAMETERS; - } - } - uint32_t token = IPCSkeleton::GetCallingTokenID(); - query.tokenId = token; - int32_t status = UpdateData(query, unifiedData); - if (!ITypesUtil::Marshal(reply, status)) { - LOG_ERROR(UDMF_SERVICE, "Marshal status failed, status: %{public}d", status); - return E_WRITE_PARCEL_ERROR; - } - return E_OK; -} - -int32_t UdmfServiceStub::OnDeleteData(MessageParcel &data, MessageParcel &reply) -{ - LOG_INFO(UDMF_SERVICE, "start"); - QueryOption query; - if (!ITypesUtil::Unmarshal(data, query)) { - LOG_ERROR(UDMF_SERVICE, "Unmarshal queryOption failed!"); - return E_READ_PARCEL_ERROR; - } - uint32_t token = IPCSkeleton::GetCallingTokenID(); - query.tokenId = token; - std::vector unifiedDataSet; - int32_t status = DeleteData(query, unifiedDataSet); - if (!ITypesUtil::Marshal(reply, status, unifiedDataSet)) { - LOG_ERROR(UDMF_SERVICE, "Marshal status or unifiedDataSet failed, status: %{public}d", status); - return E_WRITE_PARCEL_ERROR; - } - return E_OK; -} - -int32_t UdmfServiceStub::OnGetSummary(MessageParcel &data, MessageParcel &reply) -{ - LOG_INFO(UDMF_SERVICE, "start"); - QueryOption query; - if (!ITypesUtil::Unmarshal(data, query)) { - LOG_ERROR(UDMF_SERVICE, "Unmarshal query"); - return E_READ_PARCEL_ERROR; - } - uint32_t token = IPCSkeleton::GetCallingTokenID(); - query.tokenId = token; - Summary summary; - int32_t status = GetSummary(query, summary); - if (!ITypesUtil::Marshal(reply, status, summary)) { - LOG_ERROR(UDMF_SERVICE, "Marshal summary, key: %{public}s", query.key.c_str()); - return E_WRITE_PARCEL_ERROR; - } - return E_OK; -} - -int32_t UdmfServiceStub::OnAddPrivilege(MessageParcel &data, MessageParcel &reply) -{ - LOG_INFO(UDMF_SERVICE, "start"); - QueryOption query; - Privilege privilege; - if (!ITypesUtil::Unmarshal(data, query, privilege)) { - LOG_ERROR(UDMF_SERVICE, "Unmarshal query and privilege"); - return E_READ_PARCEL_ERROR; - } - uint32_t token = IPCSkeleton::GetCallingTokenID(); - query.tokenId = token; - int32_t status = AddPrivilege(query, privilege); - if (!ITypesUtil::Marshal(reply, status)) { - LOG_ERROR(UDMF_SERVICE, "Marshal status, key: %{public}s", query.key.c_str()); - return E_WRITE_PARCEL_ERROR; - } - return E_OK; -} - -int32_t UdmfServiceStub::OnSync(MessageParcel &data, MessageParcel &reply) -{ - LOG_INFO(UDMF_SERVICE, "start"); - QueryOption query; - std::vector devices; - if (!ITypesUtil::Unmarshal(data, query, devices)) { - LOG_ERROR(UDMF_SERVICE, "Unmarshal query and devices"); - return E_READ_PARCEL_ERROR; - } - uint32_t token = IPCSkeleton::GetCallingTokenID(); - query.tokenId = token; - int32_t status = Sync(query, devices); - if (!ITypesUtil::Marshal(reply, status)) { - LOG_ERROR(UDMF_SERVICE, "Marshal status, key: %{public}s", query.key.c_str()); - return E_WRITE_PARCEL_ERROR; - } - return E_OK; -} - -/* - * Check whether the caller has the permission to access data. - */ -bool UdmfServiceStub::VerifyPermission(const std::string &permission) -{ -#ifdef UDMF_PERMISSION_ENABLED - uint32_t tokenId = IPCSkeleton::GetCallingTokenID(); - int32_t result = Security::AccessToken::AccessTokenKit::VerifyAccessToken(tokenId, permission); - return result == Security::AccessToken::TypePermissionState::PERMISSION_GRANTED; -#else - return true; -#endif // UDMF_PERMISSION_ENABLED -} -} // namespace UDMF -} // namespace OHOS \ No newline at end of file diff --git a/service/test/fuzztest/BUILD.gn b/service/test/fuzztest/BUILD.gn deleted file mode 100644 index 6152b95..0000000 --- a/service/test/fuzztest/BUILD.gn +++ /dev/null @@ -1,21 +0,0 @@ -# Copyright (c) 2023 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//build/ohos.gni") - -######################################################################################### -group("fuzztest") { - testonly = true - - deps = [ "udmfservice_fuzzer:fuzztest" ] -} diff --git a/service/test/fuzztest/udmfservice_fuzzer/BUILD.gn b/service/test/fuzztest/udmfservice_fuzzer/BUILD.gn deleted file mode 100644 index 42b4cb3..0000000 --- a/service/test/fuzztest/udmfservice_fuzzer/BUILD.gn +++ /dev/null @@ -1,73 +0,0 @@ -# Copyright (c) 2023 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -##############################hydra-fuzz######################################## -import("//build/config/features.gni") -import("//build/test.gni") -import("//foundation/distributeddatamgr/udmf/udmf.gni") - -##############################fuzztest########################################## -ohos_fuzztest("UdmfServiceFuzzTest") { - module_out_path = "udmf/service" - - include_dirs = [ - "${udmf_framework_path}/common", - "${udmf_framework_path}/manager", - "${udmf_framework_path}/manager/store", - "${udmf_framework_path}/manager/preprocess", - "${udmf_framework_path}/manager/permission", - "${udmf_framework_path}/manager/lifecycle", - "${udmf_framework_path}/service", - "${udmf_interfaces_path}/innerkits/client", - "${udmf_interfaces_path}/innerkits/common", - "${udmf_interfaces_path}/innerkits/data", - "${udmf_service_path}/include", - "${kv_store_path}/frameworks/common", - "${ddms_path}/services/distributeddataservice/framework/include", - "//third_party/libuv/include", - "//third_party/node/src", - ] - - fuzz_config_file = "${udmf_service_path}/test/fuzztest/udmfservice_fuzzer" - - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - ] - - sources = [ "udmfservice_fuzzer.cpp" ] - - deps = [ "${udmf_root_path}/service:udmf_server" ] - - external_deps = [ - "access_token:libaccesstoken_sdk", - "access_token:libnativetoken", - "access_token:libtoken_setproc", - "bundle_framework:appexecfwk_core", - "c_utils:utils", - "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_core", - "kv_store:distributeddata_inner", - "os_account:os_account_innerkits", - "samgr:samgr_proxy", - ] -} - -############################################################################### -group("fuzztest") { - testonly = true - - deps = [ ":UdmfServiceFuzzTest" ] -} -############################################################################### diff --git a/service/test/fuzztest/udmfservice_fuzzer/corpus/init b/service/test/fuzztest/udmfservice_fuzzer/corpus/init deleted file mode 100644 index 2b595da..0000000 --- a/service/test/fuzztest/udmfservice_fuzzer/corpus/init +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -FUZZ \ No newline at end of file diff --git a/service/test/fuzztest/udmfservice_fuzzer/project.xml b/service/test/fuzztest/udmfservice_fuzzer/project.xml deleted file mode 100644 index 3fdba3e..0000000 --- a/service/test/fuzztest/udmfservice_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 300 - - 4096 - - \ No newline at end of file diff --git a/service/test/fuzztest/udmfservice_fuzzer/udmfservice_fuzzer.cpp b/service/test/fuzztest/udmfservice_fuzzer/udmfservice_fuzzer.cpp deleted file mode 100644 index 010f5bd..0000000 --- a/service/test/fuzztest/udmfservice_fuzzer/udmfservice_fuzzer.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "udmfservice_fuzzer.h" - -#include -#include - -#include "udmf_service_impl.h" -#include "message_parcel.h" -#include "securec.h" - -using namespace OHOS::UDMF; - -namespace OHOS { -const std::u16string INTERFACE_TOKEN = u"OHOS.UDMF.UdmfService"; - -bool OnRemoteRequestFuzz(const uint8_t* data, size_t size) -{ - uint32_t code = static_cast(*data); - MessageParcel request; - request.WriteInterfaceToken(INTERFACE_TOKEN); - request.WriteBuffer(data, size); - request.RewindRead(0); - MessageParcel reply; - std::shared_ptr udmfServiceStub = std::make_shared(); - udmfServiceStub->OnRemoteRequest(code, request, reply); - return true; -} -} - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - if (data == nullptr) { - return 0; - } - - OHOS::OnRemoteRequestFuzz(data, size); - - return 0; -} \ No newline at end of file diff --git a/service/test/fuzztest/udmfservice_fuzzer/udmfservice_fuzzer.h b/service/test/fuzztest/udmfservice_fuzzer/udmfservice_fuzzer.h deleted file mode 100644 index d86d273..0000000 --- a/service/test/fuzztest/udmfservice_fuzzer/udmfservice_fuzzer.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef UDMF_SERVICE_FUZZER_H -#define UDMF_SERVICE_FUZZER_H - -#define FUZZ_PROJECT_NAME "udmfservice_fuzzer" - -#endif // UDMF_SERVICE_FUZZER_H \ No newline at end of file