diff --git a/services/distributeddataservice/app/BUILD.gn b/services/distributeddataservice/app/BUILD.gn index ccb08f5ba8a18fdee8911907f2e1bc0b100453a0..b703e19e948906e544b8340dc18cfff967d14c7e 100644 --- a/services/distributeddataservice/app/BUILD.gn +++ b/services/distributeddataservice/app/BUILD.gn @@ -39,6 +39,7 @@ config("module_private_config") { visibility = [ ":*" ] include_dirs = [ "${kv_store_common_path}", + "${kv_store_path}/frameworks/innerkitsimpl/distributeddatasvc/include", "${kv_store_path}/frameworks/innerkitsimpl/distributeddatafwk/include", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/service/bootstrap/include", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/service/config/include", @@ -79,6 +80,7 @@ ohos_shared_library("distributeddataservice") { "src/feature_stub_impl.cpp", "src/kvstore_account_observer.cpp", "src/kvstore_data_service.cpp", + "src/kvstore_data_service_stub.cpp", "src/kvstore_device_listener.cpp", "src/kvstore_meta_manager.cpp", "src/security/security.cpp", @@ -123,6 +125,7 @@ ohos_shared_library("distributeddataservice") { "hitrace:libhitracechain", "ipc:ipc_core", "kv_store:distributeddata_inner", + "kv_store:distributeddata_mgr", "kv_store:distributeddb", "safwk:system_ability_fwk", "samgr:samgr_proxy", diff --git a/services/distributeddataservice/app/src/flowctrl_manager/BUILD.gn b/services/distributeddataservice/app/src/flowctrl_manager/BUILD.gn index eae2ee8337b39abf79546c3d5a6a07180de53fa7..274d88471d859820e5355ca10b82062bba76538c 100755 --- a/services/distributeddataservice/app/src/flowctrl_manager/BUILD.gn +++ b/services/distributeddataservice/app/src/flowctrl_manager/BUILD.gn @@ -20,6 +20,7 @@ ohos_static_library("distributeddata_flowctrl_static") { include_dirs = [ "../../../adapter/include/account", "../../src", + "${kv_store_path}/frameworks/innerkitsimpl/distributeddatasvc/include", "${kv_store_path}/frameworks/innerkitsimpl/distributeddatafwk/include", "${kv_store_path}/interfaces/innerkits/distributeddata/include", "//third_party/json/single_include", diff --git a/services/distributeddataservice/app/src/kvstore_data_service.cpp b/services/distributeddataservice/app/src/kvstore_data_service.cpp index 9eb32d479bc5999269e2c3346771ae5a426dc7f3..6c0c41d23f8a001f31365c5467f5bb38214297ca 100644 --- a/services/distributeddataservice/app/src/kvstore_data_service.cpp +++ b/services/distributeddataservice/app/src/kvstore_data_service.cpp @@ -19,6 +19,7 @@ #include #include +#include "accesstoken_kit.h" #include "auth_delegate.h" #include "auto_launch_export.h" #include "bootstrap.h" @@ -58,6 +59,7 @@ namespace OHOS::DistributedKv { using namespace std::chrono; using namespace OHOS::DistributedData; using namespace OHOS::DistributedDataDfx; +using namespace Security::AccessToken; using KvStoreDelegateManager = DistributedDB::KvStoreDelegateManager; using SecretKeyMeta = DistributedData::SecretKeyMetaData; using DmAdapter = DistributedData::DeviceManagerAdapter; @@ -685,21 +687,60 @@ void KvStoreDataService::OnDeviceOnReady(const AppDistributedKv::DeviceInfo &inf int32_t KvStoreDataService::OnUninstall(const std::string &bundleName, int32_t user, int32_t index) { - features_.ForEachCopies( - [bundleName, user, index](const auto &, sptr &value) { - value->OnAppUninstall(bundleName, user, index); - return false; - }); - return 0; + auto staticActs = FeatureSystem::GetInstance().GetStaticActs(); + staticActs.ForEachCopies([bundleName, user, index](const auto &, const std::shared_ptr& acts) { + acts->OnAppUninstall(bundleName, user, index); + return false; + }); + return SUCCESS; } int32_t KvStoreDataService::OnUpdate(const std::string &bundleName, int32_t user, int32_t index) { - features_.ForEachCopies( - [bundleName, user, index](const auto &, sptr &value) { - value->OnAppUpdate(bundleName, user, index); + auto staticActs = FeatureSystem::GetInstance().GetStaticActs(); + staticActs.ForEachCopies([bundleName, user, index](const auto &, const std::shared_ptr& acts) { + acts->OnAppUpdate(bundleName, user, index); + return false; + }); + return SUCCESS; +} + +int32_t KvStoreDataService::ClearAppStorage(const std::string &bundleName, int32_t userId, int32_t appIndex, + int32_t tokenId) +{ + HapTokenInfo hapTokenInfo; + if (AccessTokenKit::GetHapTokenInfo(tokenId, hapTokenInfo) != RET_SUCCESS || hapTokenInfo.tokenID != tokenId) { + ZLOGE("passed wrong tokenId: %{public}d", tokenId); + return ERROR; + } + auto staticActs = FeatureSystem::GetInstance().GetStaticActs(); + staticActs.ForEachCopies( + [bundleName, userId, appIndex, tokenId](const auto &, const std::shared_ptr &acts) { + acts->OnClearAppStorage(bundleName, userId, appIndex, tokenId); return false; }); - return 0; + + std::vector metaData; + std::string prefix = StoreMetaData::GetPrefix( + { DeviceManagerAdapter::GetInstance().GetLocalDevice().uuid, std::to_string(userId), "default", bundleName }); + if (!MetaDataManager::GetInstance().LoadMeta(prefix, metaData)) { + ZLOGE("Clear data load meta failed, bundleName:%{public}s, user:%{public}d, appIndex:%{public}d", + bundleName.c_str(), userId, appIndex); + return ERROR; + } + + for (auto &meta : metaData) { + if (meta.instanceId == appIndex && !meta.appId.empty() && !meta.storeId.empty()) { + ZLOGI("data cleared bundleName:%{public}s, stordId:%{public}s, appIndex:%{public}d", bundleName.c_str(), + Anonymous::Change(meta.storeId).c_str(), appIndex); + MetaDataManager::GetInstance().DelMeta(meta.GetKey()); + MetaDataManager::GetInstance().DelMeta(meta.GetSecretKey(), true); + MetaDataManager::GetInstance().DelMeta(meta.GetStrategyKey()); + MetaDataManager::GetInstance().DelMeta(meta.appId, true); + MetaDataManager::GetInstance().DelMeta(meta.GetKeyLocal(), true); + PermitDelegate::GetInstance().DelCache(meta.GetKey()); + } + } + return SUCCESS; } } // namespace OHOS::DistributedKv diff --git a/services/distributeddataservice/app/src/kvstore_data_service.h b/services/distributeddataservice/app/src/kvstore_data_service.h index a264d67b4c22ee8877af1f2272041192ffe5ea87..b67fbd9790ffe37149050d4ea08155cc2566f8d6 100644 --- a/services/distributeddataservice/app/src/kvstore_data_service.h +++ b/services/distributeddataservice/app/src/kvstore_data_service.h @@ -27,6 +27,7 @@ #include "ithread_pool.h" #include "kvstore_device_listener.h" #include "kvstore_meta_manager.h" +#include "kvstore_data_service_stub.h" #include "metadata/store_meta_data.h" #include "reporter.h" #include "runtime_config.h" @@ -53,6 +54,8 @@ public: sptr GetFeatureInterface(const std::string &name) override; + int32_t ClearAppStorage(const std::string &bundleName, int32_t userId, int32_t appIndex, int32_t tokenId) override; + void OnDump() override; int Dump(int fd, const std::vector &args) override; diff --git a/services/distributeddataservice/app/src/kvstore_data_service_stub.cpp b/services/distributeddataservice/app/src/kvstore_data_service_stub.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f8a13daab904bcad0b5293ae62e87cad62697d8e --- /dev/null +++ b/services/distributeddataservice/app/src/kvstore_data_service_stub.cpp @@ -0,0 +1,91 @@ +/* +* 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. +*/ + +#define LOG_TAG "KvStoreDataServiceStub" + +#include "kvstore_data_service_stub.h" +#include +#include "itypes_util.h" +#include "message_parcel.h" +#include "types.h" +#include "log_print.h" + +namespace OHOS { +namespace DistributedKv { +constexpr KvStoreDataServiceStub::RequestHandler + KvStoreDataServiceStub::HANDLERS[static_cast(KvStoreDataServiceInterfaceCode::SERVICE_CMD_LAST)]; + +int32_t KvStoreDataServiceStub::RegisterClientDeathObserverOnRemote(MessageParcel &data, MessageParcel &reply) +{ + AppId appId = { data.ReadString() }; + sptr kvStoreClientDeathObserverProxy = data.ReadRemoteObject(); + if (kvStoreClientDeathObserverProxy == nullptr) { + return -1; + } + Status status = RegisterClientDeathObserver(appId, std::move(kvStoreClientDeathObserverProxy)); + if (!reply.WriteInt32(static_cast(status))) { + return -1; + } + return 0; +} + +int32_t KvStoreDataServiceStub::GetFeatureInterfaceOnRemote(MessageParcel &data, MessageParcel &reply) +{ + std::string name; + if (!ITypesUtil::Unmarshal(data, name)) { + return -1; + } + auto remoteObject = GetFeatureInterface(name); + if (!ITypesUtil::Marshal(reply, remoteObject)) { + return -1; + } + return 0; +} + +int32_t KvStoreDataServiceStub::ClearAppStorageOnRemote(MessageParcel &data, MessageParcel &reply) +{ + std::string bundleName; + int32_t userId; + int32_t appIndex; + int32_t tokenId; + if (!ITypesUtil::Unmarshal(data, bundleName, userId, appIndex, tokenId)) { + return -1; + } + auto remoteObject = ClearAppStorage(bundleName, userId, appIndex, tokenId); + if (!ITypesUtil::Marshal(reply, remoteObject)) { + return -1; + } + return 0; +} + +int32_t KvStoreDataServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, + MessageOption &option) +{ + ZLOGD("code:%{public}u, callingPid:%{public}d", code, IPCSkeleton::GetCallingPid()); + std::u16string descriptor = KvStoreDataServiceStub::GetDescriptor(); + std::u16string remoteDescriptor = data.ReadInterfaceToken(); + if (descriptor != remoteDescriptor) { + ZLOGE("local descriptor is not equal to remote"); + return -1; + } + if (code >= 0 && code < static_cast(KvStoreDataServiceInterfaceCode::SERVICE_CMD_LAST)) { + return (this->*HANDLERS[code])(data, reply); + } else { + MessageOption mo{ MessageOption::TF_SYNC }; + return IPCObjectStub::OnRemoteRequest(code, data, reply, mo); + } +} +} // namespace DistributedKv +} // namespace OHOS diff --git a/services/distributeddataservice/app/src/kvstore_data_service_stub.h b/services/distributeddataservice/app/src/kvstore_data_service_stub.h new file mode 100644 index 0000000000000000000000000000000000000000..08767f6d565dc6e45c6f8d0f74207fd4cd6c13bb --- /dev/null +++ b/services/distributeddataservice/app/src/kvstore_data_service_stub.h @@ -0,0 +1,39 @@ +/* +* 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 KVSTORE_DATA_SERVICE_STUB_H +#define KVSTORE_DATA_SERVICE_STUB_H +#include "ikvstore_data_service.h" +#include "distributeddata_ipc_interface_code.h" +namespace OHOS::DistributedKv { +class API_EXPORT KvStoreDataServiceStub : public IRemoteStub { +public: + int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, + MessageOption &option) override; + +private: + int32_t GetFeatureInterfaceOnRemote(MessageParcel &data, MessageParcel &reply); + int32_t RegisterClientDeathObserverOnRemote(MessageParcel &data, MessageParcel &reply); + int32_t ClearAppStorageOnRemote(MessageParcel &data, MessageParcel &reply); + + using RequestHandler = int32_t (KvStoreDataServiceStub::*)(MessageParcel &, MessageParcel &); + using code = KvStoreDataServiceInterfaceCode; + static constexpr RequestHandler HANDLERS[static_cast(code::SERVICE_CMD_LAST)] = { + &KvStoreDataServiceStub::GetFeatureInterfaceOnRemote, + &KvStoreDataServiceStub::RegisterClientDeathObserverOnRemote, + &KvStoreDataServiceStub::ClearAppStorageOnRemote, + }; +}; +} // namespace OHOS::DistributedKv +#endif // KVSTORE_DATA_SERVICE_STUB_H diff --git a/services/distributeddataservice/app/src/uninstaller/BUILD.gn b/services/distributeddataservice/app/src/uninstaller/BUILD.gn index aa9913b8040cc16e551861e024e75b73636ff7e1..87cf3b89482b9b087860fe31f11732974c68e575 100755 --- a/services/distributeddataservice/app/src/uninstaller/BUILD.gn +++ b/services/distributeddataservice/app/src/uninstaller/BUILD.gn @@ -23,6 +23,7 @@ ohos_static_library("distributeddata_uninstaller_static") { include_dirs = [ "../../../adapter/include/account", "../../src", + "${kv_store_path}/frameworks/innerkitsimpl/distributeddatasvc/include", "${kv_store_path}/frameworks/innerkitsimpl/distributeddatafwk/include", "${kv_store_path}/interfaces/innerkits/distributeddata/include", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/framework/include", diff --git a/services/distributeddataservice/app/test/BUILD.gn b/services/distributeddataservice/app/test/BUILD.gn index 0b51ae59ad2bc4827b40ed612f5bd74abad0d935..42bdfd5c77cdcfcc942d581f50fa06f65fddf8d0 100644 --- a/services/distributeddataservice/app/test/BUILD.gn +++ b/services/distributeddataservice/app/test/BUILD.gn @@ -19,6 +19,7 @@ module_output_path = "datamgr_service/distributeddataservice" config("module_private_config") { visibility = [ ":*" ] include_dirs = [ + "${kv_store_path}/frameworks/innerkitsimpl/distributeddatasvc/include", "//foundation/distributeddatamgr/kv_store/frameworks/common", "//foundation/distributeddatamgr/kv_store/frameworks/innerkitsimpl/distributeddatafwk/include", "//foundation/distributeddatamgr/kv_store/frameworks/innerkitsimpl/distributeddatafwk/src", @@ -69,6 +70,7 @@ ohos_unittest("KvStoreDataServiceTest") { "../src/feature_stub_impl.cpp", "../src/kvstore_account_observer.cpp", "../src/kvstore_data_service.cpp", + "../src/kvstore_data_service_stub.cpp", "../src/kvstore_device_listener.cpp", "../src/kvstore_meta_manager.cpp", "../src/security/security.cpp", @@ -104,6 +106,7 @@ ohos_unittest("KvStoreDataServiceTest") { } deps = [ + "${kv_store_path}/interfaces/innerkits/distributeddatamgr:distributeddata_mgr", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter:distributeddata_adapter", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter/broadcaster:distributeddata_broadcaster_static", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter/utils:distributeddata_utils_static", @@ -154,6 +157,7 @@ ohos_unittest("SessionManagerTest") { } deps = [ + "${kv_store_path}/interfaces/innerkits/distributeddatamgr:distributeddata_mgr", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter:distributeddata_adapter", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter/broadcaster:distributeddata_broadcaster_static", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter/utils:distributeddata_utils_static", @@ -193,6 +197,7 @@ ohos_unittest("KvStoreFlowCtrlManagerTest") { } deps = [ + "${kv_store_path}/interfaces/innerkits/distributeddatamgr:distributeddata_mgr", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter:distributeddata_adapter", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/app/src/flowctrl_manager:distributeddata_flowctrl_static", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/framework:distributeddatasvcfwk", diff --git a/services/distributeddataservice/app/test/fuzztest/dataservicestub_fuzzer/BUILD.gn b/services/distributeddataservice/app/test/fuzztest/dataservicestub_fuzzer/BUILD.gn index 3e594bee1c03cdb18fbefca2eedb3b5338bb6e4e..822c306cfd6ea72329f10a54fbaea00482cbedb6 100644 --- a/services/distributeddataservice/app/test/fuzztest/dataservicestub_fuzzer/BUILD.gn +++ b/services/distributeddataservice/app/test/fuzztest/dataservicestub_fuzzer/BUILD.gn @@ -22,6 +22,7 @@ ohos_fuzztest("DataServiceStubFuzzTest") { include_dirs = [ "${kv_store_common_path}", "${kv_store_path}/frameworks/innerkitsimpl/distributeddatafwk/include", + "${kv_store_path}/frameworks/innerkitsimpl/distributeddatasvc/include", "${data_service_path}/service/bootstrap/include", "${data_service_path}/service/config/include", "${data_service_path}/service/crypto/include", @@ -65,6 +66,7 @@ ohos_fuzztest("DataServiceStubFuzzTest") { "${data_service_path}/app/src/feature_stub_impl.cpp", "${data_service_path}/app/src/kvstore_account_observer.cpp", "${data_service_path}/app/src/kvstore_data_service.cpp", + "${data_service_path}/app/src/kvstore_data_service_stub.cpp", "${data_service_path}/app/src/kvstore_device_listener.cpp", "${data_service_path}/app/src/kvstore_meta_manager.cpp", "${data_service_path}/app/src/security/security.cpp", @@ -102,6 +104,7 @@ ohos_fuzztest("DataServiceStubFuzzTest") { "hitrace:libhitracechain", "ipc:ipc_core", "kv_store:distributeddata_inner", + "kv_store:distributeddata_mgr", "safwk:system_ability_fwk", "samgr:samgr_proxy", ] diff --git a/services/distributeddataservice/framework/BUILD.gn b/services/distributeddataservice/framework/BUILD.gn index b13f8c456b23fccb3439cd14ae27e3c2a7adbed9..692ed9a8028356e45c317ad3a9ecbb8ba6c1beff 100644 --- a/services/distributeddataservice/framework/BUILD.gn +++ b/services/distributeddataservice/framework/BUILD.gn @@ -56,6 +56,7 @@ ohos_shared_library("distributeddatasvcfwk") { "eventcenter/event.cpp", "eventcenter/event_center.cpp", "feature/feature_system.cpp", + "feature/static_acts.cpp", "metadata/appid_meta_data.cpp", "metadata/capability_meta_data.cpp", "metadata/capability_range.cpp", diff --git a/services/distributeddataservice/framework/feature/feature_system.cpp b/services/distributeddataservice/framework/feature/feature_system.cpp index 98f67a1014076fdc01c70d2c8a435d40810a1010..b94ef987f3b47793dd9779ec8be40c54718031c3 100644 --- a/services/distributeddataservice/framework/feature/feature_system.cpp +++ b/services/distributeddataservice/framework/feature/feature_system.cpp @@ -38,6 +38,17 @@ FeatureSystem::Creator FeatureSystem::GetCreator(const std::string &name) return creator; } +int32_t FeatureSystem::RegisterStaticActs(const std::string &name, std::shared_ptr staticActs) +{ + staticActs_.InsertOrAssign(name, std::move(staticActs)); + return E_OK; +} + +const ConcurrentMap> &FeatureSystem::GetStaticActs() +{ + return staticActs_; +} + std::vector FeatureSystem::GetFeatureName(int32_t flag) { std::vector features; diff --git a/services/distributeddataservice/framework/feature/static_acts.cpp b/services/distributeddataservice/framework/feature/static_acts.cpp new file mode 100644 index 0000000000000000000000000000000000000000..817441af9ed83be5b95de4792b6a34b147511288 --- /dev/null +++ b/services/distributeddataservice/framework/feature/static_acts.cpp @@ -0,0 +1,35 @@ +/* + * 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 "feature/static_acts.h" +namespace OHOS::DistributedData { +StaticActs::~StaticActs() +{ +} + +int32_t StaticActs::OnAppUninstall(const std::string &bundleName, int32_t user, int32_t index) +{ + return E_OK; +} + +int32_t StaticActs::OnAppUpdate(const std::string &bundleName, int32_t user, int32_t index) +{ + return E_OK; +} + +int32_t StaticActs::OnClearAppStorage(const std::string &bundleName, int32_t user, int32_t index, int32_t tokenId) +{ + return E_OK; +} +} diff --git a/services/distributeddataservice/framework/include/feature/feature_system.h b/services/distributeddataservice/framework/include/feature/feature_system.h index a94f015738468ff8b619d0e130b344e239e141df..cc80359601642cc9c195432752cb963a44fadd2e 100644 --- a/services/distributeddataservice/framework/include/feature/feature_system.h +++ b/services/distributeddataservice/framework/include/feature/feature_system.h @@ -19,6 +19,7 @@ #include "concurrent_map.h" #include "error/general_error.h" #include "executor_pool.h" +#include "static_acts.h" #include "visibility.h" namespace DistributedDB { struct AutoLaunchParam; @@ -58,6 +59,8 @@ public: static FeatureSystem &GetInstance(); int32_t RegisterCreator(const std::string &name, Creator creator, int32_t flag = BIND_LAZY); Creator GetCreator(const std::string &name); + int32_t RegisterStaticActs(const std::string &name, std::shared_ptr staticActs); + const ConcurrentMap> &GetStaticActs(); std::vector GetFeatureName(int32_t flag); private: @@ -68,6 +71,7 @@ private: FeatureSystem &operator=(FeatureSystem &&) = delete; ConcurrentMap> creators_; + ConcurrentMap> staticActs_; }; } // namespace DistributedData } diff --git a/services/distributeddataservice/framework/include/feature/static_acts.h b/services/distributeddataservice/framework/include/feature/static_acts.h new file mode 100644 index 0000000000000000000000000000000000000000..d989f0a5d861234684dd715beed104d867368a5f --- /dev/null +++ b/services/distributeddataservice/framework/include/feature/static_acts.h @@ -0,0 +1,31 @@ +/* + * 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_DISTRIBUTED_DATA_FRAMEWORK_STATIC_ACTS_H +#define OHOS_DISTRIBUTED_DATA_FRAMEWORK_STATIC_ACTS_H +#include +#include +#include "error/general_error.h" +#include "visibility.h" +namespace OHOS::DistributedData { +class API_EXPORT StaticActs { +public: + virtual ~StaticActs(); + virtual int32_t OnAppUninstall(const std::string &bundleName, int32_t user, int32_t index); + virtual int32_t OnAppUpdate(const std::string &bundleName, int32_t user, int32_t index); + virtual int32_t OnClearAppStorage(const std::string &bundleName, int32_t user, int32_t index, int32_t tokenId); +}; +} // namespace OHOS::DistributedData +#endif // OHOS_DISTRIBUTED_DATA_FRAMEWORK_STATIC_ACTS_H diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index 972cc2124c123aff922512f2d4888160094bc501..fa4ebd56261f4ebad44ba9e53fa3460a7a68a4a6 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -50,6 +50,9 @@ CloudServiceImpl::Factory::Factory() noexcept return product_; }, FeatureSystem::BIND_NOW); + staticActs_ = std::make_shared(); + FeatureSystem::GetInstance().RegisterStaticActs(CloudServiceImpl::SERVICE_NAME, + staticActs_); } CloudServiceImpl::Factory::~Factory() {} @@ -467,7 +470,7 @@ std::pair CloudServiceImpl::GetCloudInfo(int32_t userId) return { SUCCESS, cloudInfo }; } -int32_t CloudServiceImpl::OnAppUninstall( +int32_t CloudServiceImpl::CloudStatic::OnAppUninstall( const std::string &bundleName, int32_t user, int32_t index) { MetaDataManager::GetInstance().DelMeta(Subscription::GetRelationKey(user, bundleName), true); diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.h b/services/distributeddataservice/service/cloud/cloud_service_impl.h index 866e48357f41fb2c1df318dbb314984be7151cc2..f1ef2e072d1c2236943d8db658d8a20a1af5351c 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.h +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.h @@ -23,6 +23,7 @@ #include "cloud/schema_meta.h" #include "cloud/subscription.h" #include "cloud_service_stub.h" +#include "feature/static_acts.h" #include "sync_manager.h" namespace OHOS::CloudData { class CloudServiceImpl : public CloudServiceStub { @@ -38,17 +39,23 @@ public: int32_t OnInitialize() override; int32_t OnBind(const BindInfo &info) override; int32_t OnUserChange(uint32_t code, const std::string &user, const std::string &account) override; - int32_t OnAppUninstall(const std::string &bundleName, int32_t user, int32_t index) override; int32_t Online(const std::string &device) override; int32_t Offline(const std::string &device) override; private: + using StaticActs = DistributedData::StaticActs; + class CloudStatic : public StaticActs { + public: + ~CloudStatic() override {}; + int32_t OnAppUninstall(const std::string &bundleName, int32_t user, int32_t index) override; + }; class Factory { public: Factory() noexcept; ~Factory(); private: std::shared_ptr product_; + std::shared_ptr staticActs_; }; static Factory factory_; diff --git a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp index ca9b7216d3a1c154676ec1fd20ade15c4bcd5123..973ed64e07ca2694965a371c0e2f34445984c2f0 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp @@ -43,6 +43,8 @@ DataShareServiceImpl::Factory::Factory() FeatureSystem::GetInstance().RegisterCreator("data_share", []() { return std::make_shared(); }); + staticActs_ = std::make_shared(); + FeatureSystem::GetInstance().RegisterStaticActs("data_share", staticActs_); } DataShareServiceImpl::Factory::~Factory() {} @@ -444,8 +446,8 @@ void DataShareServiceImpl::OnConnectDone() AppConnectManager::Notify(callerBundleName); } -int32_t DataShareServiceImpl::OnAppUninstall( - const std::string &bundleName, int32_t user, int32_t index) +int32_t DataShareServiceImpl::DataShareStatic::OnAppUninstall(const std::string &bundleName, int32_t user, + int32_t index) { ZLOGI("%{public}s uninstalled", bundleName.c_str()); PublishedData::Delete(bundleName, user); diff --git a/services/distributeddataservice/service/data_share/data_share_service_impl.h b/services/distributeddataservice/service/data_share/data_share_service_impl.h index a71cc0d48a3496f478a5d7054afd96f075909ffb..a505f915877b496d6a6fc246f62db6c4daf52a45 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.h +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.h @@ -25,6 +25,7 @@ #include "datashare_template.h" #include "db_delegate.h" #include "delete_strategy.h" +#include "feature/static_acts.h" #include "get_data_strategy.h" #include "insert_strategy.h" #include "publish_strategy.h" @@ -68,15 +69,22 @@ public: const int64_t subscriberId) override; void OnConnectDone() override; int32_t OnBind(const BindInfo &binderInfo) override; - int32_t OnAppUninstall(const std::string &bundleName, int32_t user, int32_t index) override; int32_t OnAppExit(pid_t uid, pid_t pid, uint32_t tokenId, const std::string &bundleName) override; void NotifyObserver(const std::string &uri) override; private: + using StaticActs = DistributedData::StaticActs; + class DataShareStatic : public StaticActs { + public: + ~DataShareStatic() override {}; + int32_t OnAppUninstall(const std::string &bundleName, int32_t user, int32_t index) override; + }; class Factory { public: Factory(); ~Factory(); + private: + std::shared_ptr staticActs_; }; class TimerReceiver : public EventFwk::CommonEventSubscriber { public: diff --git a/services/distributeddataservice/service/object/object_service_impl.cpp b/services/distributeddataservice/service/object/object_service_impl.cpp index c38e77dd9683d9a65aac56615300aabf0823b029..132faa2bb60c0386209fea0f7cb55dff0a20f559 100644 --- a/services/distributeddataservice/service/object/object_service_impl.cpp +++ b/services/distributeddataservice/service/object/object_service_impl.cpp @@ -44,6 +44,8 @@ ObjectServiceImpl::Factory::Factory() return std::make_shared(); }, FeatureSystem::BIND_NOW); + staticActs_ = std::make_shared(); + FeatureSystem::GetInstance().RegisterStaticActs("data_object", staticActs_); } ObjectServiceImpl::Factory::~Factory() @@ -219,7 +221,7 @@ void ObjectServiceImpl::Clear() return; } -int32_t ObjectServiceImpl::OnAppUninstall(const std::string &bundleName, int32_t user, int32_t index) +int32_t ObjectServiceImpl::ObjectStatic::OnAppUninstall(const std::string &bundleName, int32_t user, int32_t index) { ZLOGI("begin. %{public}s", bundleName.c_str()); int32_t result = ObjectStoreManager::GetInstance()->DeleteByAppId(bundleName); diff --git a/services/distributeddataservice/service/object/object_service_impl.h b/services/distributeddataservice/service/object/object_service_impl.h index f9e038a12936321ee12967e01f7f1fa6b023cb9a..caa1c34043f0123158a9d37f083972f69169afda 100644 --- a/services/distributeddataservice/service/object/object_service_impl.h +++ b/services/distributeddataservice/service/object/object_service_impl.h @@ -16,6 +16,7 @@ #ifndef DISTRIBUTEDDATASERVICE_OBJECT_SERVICE_H #define DISTRIBUTEDDATASERVICE_OBJECT_SERVICE_H +#include "feature/static_acts.h" #include "object_manager.h" #include "object_service_stub.h" #include "visibility.h" @@ -43,14 +44,21 @@ public: int32_t OnAppExit(pid_t uid, pid_t pid, uint32_t tokenId, const std::string &appId) override; int32_t OnInitialize() override; int32_t OnUserChange(uint32_t code, const std::string &user, const std::string &account) override; - int32_t OnAppUninstall(const std::string &bundleName, int32_t user, int32_t index) override; int32_t OnBind(const BindInfo &bindInfo) override; private: + using StaticActs = DistributedData::StaticActs; + class ObjectStatic : public StaticActs { + public: + ~ObjectStatic() override {}; + int32_t OnAppUninstall(const std::string &bundleName, int32_t user, int32_t index) override; + }; class Factory { public: Factory(); ~Factory(); + private: + std::shared_ptr staticActs_; }; static Factory factory_; std::shared_ptr executors_; diff --git a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp index 9a2ec41bed1809824682517afdf2ca1a95a80c55..cd78e9f2e09f7128741696221988f6fdb760216b 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp +++ b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp @@ -64,6 +64,9 @@ RdbServiceImpl::Factory::Factory() AutoCache::GetInstance().RegCreator(RDB_DEVICE_COLLABORATION, [](const StoreMetaData &metaData) -> GeneralStore* { return new (std::nothrow) RdbGeneralStore(metaData); }); + staticActs_ = std::make_shared(); + FeatureSystem::GetInstance().RegisterStaticActs(RdbServiceImpl::SERVICE_NAME, + staticActs_); } RdbServiceImpl::Factory::~Factory() @@ -633,18 +636,42 @@ int32_t RdbServiceImpl::OnBind(const BindInfo &bindInfo) return 0; } -int32_t RdbServiceImpl::OnAppUninstall(const std::string &bundleName, int32_t user, int32_t index) +void RdbServiceImpl::SyncAgent::ReInit(pid_t pid, const std::string &bundleName) { - return CloseStore(bundleName, user, index); + pid_ = pid; + count_ = 0; + bundleName_ = bundleName; + notifier_ = nullptr; + if (watcher_ != nullptr) { + watcher_->SetNotifier(nullptr); + } } -int32_t RdbServiceImpl::OnAppUpdate(const std::string &bundleName, int32_t user, int32_t index) +void RdbServiceImpl::SyncAgent::SetNotifier(sptr notifier) { - return CloseStore(bundleName, user, index); + notifier_ = notifier; + if (watcher_ != nullptr) { + watcher_->SetNotifier(notifier); + } +} + +void RdbServiceImpl::SyncAgent::SetWatcher(std::shared_ptr watcher) +{ + if (watcher_ != watcher) { + watcher_ = watcher; + if (watcher_ != nullptr) { + watcher_->SetNotifier(notifier_); + } + } } -int32_t RdbServiceImpl::CloseStore(const std::string &bundleName, int32_t user, int32_t index) const +int32_t RdbServiceImpl::RdbStatic::CloseStore(const std::string &bundleName, int32_t user, int32_t index, + int32_t tokenId) const { + if (tokenId != RdbServiceImpl::RdbStatic::INVALID_TOKENID) { + AutoCache::GetInstance().CloseStore(tokenId); + return E_OK; + } std::string prefix = StoreMetaData::GetPrefix( { DeviceManagerAdapter::GetInstance().GetLocalDevice().uuid, std::to_string(user), "default", bundleName }); std::vector storeMetaData; @@ -666,32 +693,19 @@ int32_t RdbServiceImpl::CloseStore(const std::string &bundleName, int32_t user, return E_OK; } -void RdbServiceImpl::SyncAgent::ReInit(pid_t pid, const std::string &bundleName) +int32_t RdbServiceImpl::RdbStatic::OnAppUninstall(const std::string &bundleName, int32_t user, int32_t index) { - pid_ = pid; - count_ = 0; - bundleName_ = bundleName; - notifier_ = nullptr; - if (watcher_ != nullptr) { - watcher_->SetNotifier(nullptr); - } + return CloseStore(bundleName, user, index); } -void RdbServiceImpl::SyncAgent::SetNotifier(sptr notifier) +int32_t RdbServiceImpl::RdbStatic::OnAppUpdate(const std::string &bundleName, int32_t user, int32_t index) { - notifier_ = notifier; - if (watcher_ != nullptr) { - watcher_->SetNotifier(notifier); - } + return CloseStore(bundleName, user, index); } -void RdbServiceImpl::SyncAgent::SetWatcher(std::shared_ptr watcher) +int32_t RdbServiceImpl::RdbStatic::OnClearAppStorage(const std::string &bundleName, int32_t user, int32_t index, + int32_t tokenId) { - if (watcher_ != watcher) { - watcher_ = watcher; - if (watcher_ != nullptr) { - watcher_->SetNotifier(notifier_); - } - } + return CloseStore(bundleName, user, index, tokenId); } } // namespace OHOS::DistributedRdb diff --git a/services/distributeddataservice/service/rdb/rdb_service_impl.h b/services/distributeddataservice/service/rdb/rdb_service_impl.h index 8a8a738ab71bceef3eab949521914a167a1a7a10..c8999344b5fe44257d3d267953c718e4b91b4a47 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_impl.h +++ b/services/distributeddataservice/service/rdb/rdb_service_impl.h @@ -22,6 +22,7 @@ #include #include #include "concurrent_map.h" +#include "feature/static_acts.h" #include "metadata/secret_key_meta_data.h" #include "metadata/store_meta_data.h" #include "rdb_notifier_proxy.h" @@ -31,6 +32,7 @@ #include "store_observer.h" #include "visibility.h" #include "store/general_value.h" + namespace OHOS::DistributedRdb { class API_EXPORT RdbServiceImpl : public RdbServiceStub { public: @@ -61,22 +63,19 @@ public: int32_t ResolveAutoLaunch(const std::string &identifier, DistributedDB::AutoLaunchParam ¶m) override; - int32_t OnInitialize() override; - int32_t OnAppExit(pid_t uid, pid_t pid, uint32_t tokenId, const std::string &bundleName) override; - int32_t OnAppUninstall(const std::string &bundleName, int32_t user, int32_t index) override; - - int32_t OnAppUpdate(const std::string &bundleName, int32_t user, int32_t index) override; - int32_t GetSchema(const RdbSyncerParam ¶m) override; int32_t Delete(const RdbSyncerParam ¶m) override; int32_t OnBind(const BindInfo &bindInfo) override; + int32_t OnInitialize() override; + private: using Watchers = DistributedData::AutoCache::Watchers; + using StaticActs = DistributedData::StaticActs; struct SyncAgent { pid_t pid_ = 0; int32_t count_ = 0; @@ -88,19 +87,32 @@ private: void SetWatcher(std::shared_ptr watcher); }; + class RdbStatic : public StaticActs { + public: + ~RdbStatic() override {}; + int32_t OnAppUninstall(const std::string &bundleName, int32_t user, int32_t index) override; + int32_t OnAppUpdate(const std::string &bundleName, int32_t user, int32_t index) override; + int32_t OnClearAppStorage(const std::string &bundleName, int32_t user, int32_t index, int32_t tokenId) override; + private: + static constexpr inline int32_t INVALID_TOKENID = 0; + int32_t CloseStore(const std::string &bundleName, int32_t user, int32_t index, + int32_t tokenId = INVALID_TOKENID) const; + }; + class Factory { public: Factory(); ~Factory(); private: std::shared_ptr product_; + std::shared_ptr staticActs_; }; static constexpr inline uint32_t WAIT_TIME = 30 * 1000; void DoCloudSync(const RdbSyncerParam ¶m, const Option &option, const PredicatesMemo &predicates, const AsyncDetail &async); - + int DoSync(const RdbSyncerParam ¶m, const Option &option, const PredicatesMemo &predicates, const AsyncDetail &async); @@ -130,8 +142,6 @@ private: static bool GetPassword(const StoreMetaData &metaData, DistributedDB::CipherPassword &password); - int32_t CloseStore(const std::string &bundleName, int32_t user, int32_t index) const; - static Factory factory_; ConcurrentMap syncAgents_; std::shared_ptr executors_; diff --git a/services/distributeddataservice/service/test/fuzztest/cloudservicestub_fuzzer/BUILD.gn b/services/distributeddataservice/service/test/fuzztest/cloudservicestub_fuzzer/BUILD.gn index 45818b8290b4f8d191adfdbbfacf222ca1fcee08..7683a031a0423cfbc23bb8cc4c2f3f6b544ebf79 100644 --- a/services/distributeddataservice/service/test/fuzztest/cloudservicestub_fuzzer/BUILD.gn +++ b/services/distributeddataservice/service/test/fuzztest/cloudservicestub_fuzzer/BUILD.gn @@ -35,6 +35,7 @@ ohos_fuzztest("CloudServiceStubFuzzTest") { "${data_service_path}/service/rdb", "${kv_store_common_path}", "${kv_store_path}/frameworks/innerkitsimpl/distributeddatafwk/include", + "${kv_store_path}/frameworks/innerkitsimpl/distributeddatasvc/include", "${kv_store_path}/frameworks/innerkitsimpl/kvdb/include", "${kv_store_distributeddb_path}", "${kv_store_distributeddb_path}/include/", @@ -99,6 +100,7 @@ ohos_fuzztest("CloudServiceStubFuzzTest") { "huks:libhukssdk", "ipc:ipc_core", "kv_store:distributeddata_inner", + "kv_store:distributeddata_mgr", "relational_store:native_rdb", ] } diff --git a/services/distributeddataservice/service/test/fuzztest/kvdbservicestub_fuzzer/BUILD.gn b/services/distributeddataservice/service/test/fuzztest/kvdbservicestub_fuzzer/BUILD.gn index 01f380c64eed2350fce6d1b22803608fbdfd35b5..58e977061d0d1927751e513ae63b59877976e701 100644 --- a/services/distributeddataservice/service/test/fuzztest/kvdbservicestub_fuzzer/BUILD.gn +++ b/services/distributeddataservice/service/test/fuzztest/kvdbservicestub_fuzzer/BUILD.gn @@ -33,6 +33,7 @@ ohos_fuzztest("KvdbServiceStubFuzzTest") { "${data_service_path}/service/permission/include", "${kv_store_common_path}", "${kv_store_path}/frameworks/innerkitsimpl/distributeddatafwk/include", + "${kv_store_path}/frameworks/innerkitsimpl/distributeddatasvc/include", "${kv_store_path}/frameworks/innerkitsimpl/kvdb/include", "${kv_store_distributeddb_path}", "${kv_store_distributeddb_path}/include/", @@ -101,6 +102,7 @@ ohos_fuzztest("KvdbServiceStubFuzzTest") { "huks:libhukssdk", "ipc:ipc_core", "kv_store:distributeddata_inner", + "kv_store:distributeddata_mgr", ] } diff --git a/services/distributeddataservice/service/test/fuzztest/objectservicestub_fuzzer/BUILD.gn b/services/distributeddataservice/service/test/fuzztest/objectservicestub_fuzzer/BUILD.gn index cd27ac04164ed5af25bc97a4454c60f494d3a01f..f71790cf984a9afde0cf3dd87fccc484d1ce39b4 100644 --- a/services/distributeddataservice/service/test/fuzztest/objectservicestub_fuzzer/BUILD.gn +++ b/services/distributeddataservice/service/test/fuzztest/objectservicestub_fuzzer/BUILD.gn @@ -30,6 +30,7 @@ ohos_fuzztest("ObjectServiceStubFuzzTest") { "${data_service_path}/service/object", "${kv_store_common_path}", "${kv_store_path}/frameworks/innerkitsimpl/distributeddatafwk/include", + "${kv_store_path}/frameworks/innerkitsimpl/distributeddatasvc/include", "${kv_store_path}/frameworks/innerkitsimpl/kvdb/include", "${kv_store_distributeddb_path}", "${kv_store_distributeddb_path}/include/", @@ -90,6 +91,7 @@ ohos_fuzztest("ObjectServiceStubFuzzTest") { "huks:libhukssdk", "ipc:ipc_core", "kv_store:distributeddata_inner", + "kv_store:distributeddata_mgr", ] } diff --git a/services/distributeddataservice/service/test/fuzztest/rdbresultsetstub_fuzzer/BUILD.gn b/services/distributeddataservice/service/test/fuzztest/rdbresultsetstub_fuzzer/BUILD.gn index c8736f9f67f97ae58b2783ad5160f0729873311f..68a76083fac4684cff6b0f90769f7b905d1bf2cc 100644 --- a/services/distributeddataservice/service/test/fuzztest/rdbresultsetstub_fuzzer/BUILD.gn +++ b/services/distributeddataservice/service/test/fuzztest/rdbresultsetstub_fuzzer/BUILD.gn @@ -26,6 +26,7 @@ ohos_fuzztest("RdbResultSetStubFuzzTest") { "${data_service_path}/service/rdb", "${kv_store_common_path}", "${kv_store_path}/frameworks/innerkitsimpl/distributeddatafwk/include", + "${kv_store_path}/frameworks/innerkitsimpl/distributeddatasvc/include", "${kv_store_path}/frameworks/innerkitsimpl/kvdb/include", "${kv_store_distributeddb_path}", "${kv_store_distributeddb_path}/include/", @@ -74,6 +75,7 @@ ohos_fuzztest("RdbResultSetStubFuzzTest") { "huks:libhukssdk", "ipc:ipc_core", "kv_store:distributeddata_inner", + "kv_store:distributeddata_mgr", "relational_store:native_rdb", ] } diff --git a/services/distributeddataservice/service/test/fuzztest/rdbservicestub_fuzzer/BUILD.gn b/services/distributeddataservice/service/test/fuzztest/rdbservicestub_fuzzer/BUILD.gn index b0c3923a0cdb2298b65c0613738eba347d65ca17..c3cc42bf7f426ed791ea428145137cf5b0e6bb78 100644 --- a/services/distributeddataservice/service/test/fuzztest/rdbservicestub_fuzzer/BUILD.gn +++ b/services/distributeddataservice/service/test/fuzztest/rdbservicestub_fuzzer/BUILD.gn @@ -36,6 +36,7 @@ ohos_fuzztest("RdbServiceStubFuzzTest") { "${data_service_path}/service/rdb", "${kv_store_common_path}", "${kv_store_path}/frameworks/innerkitsimpl/distributeddatafwk/include", + "${kv_store_path}/frameworks/innerkitsimpl/distributeddatasvc/include", "${kv_store_path}/frameworks/innerkitsimpl/kvdb/include", "${kv_store_distributeddb_path}", "${kv_store_distributeddb_path}/include/", @@ -96,6 +97,7 @@ ohos_fuzztest("RdbServiceStubFuzzTest") { "huks:libhukssdk", "ipc:ipc_core", "kv_store:distributeddata_inner", + "kv_store:distributeddata_mgr", "relational_store:native_rdb", ] } diff --git a/services/distributeddataservice/service/test/fuzztest/udmfservice_fuzzer/BUILD.gn b/services/distributeddataservice/service/test/fuzztest/udmfservice_fuzzer/BUILD.gn index 4656e9aa1061f4e7e75f2e9d794fa9c8a3666f52..4a878c22e56638c1d3addad1bb1c951a4ca8f5fb 100644 --- a/services/distributeddataservice/service/test/fuzztest/udmfservice_fuzzer/BUILD.gn +++ b/services/distributeddataservice/service/test/fuzztest/udmfservice_fuzzer/BUILD.gn @@ -58,6 +58,7 @@ ohos_fuzztest("UdmfServiceFuzzTest") { "hilog:libhilog", "ipc:ipc_core", "kv_store:distributeddata_inner", + "kv_store:distributeddata_mgr", "udmf:udmf_client", ] }