diff --git a/datamgr_service/services/distributeddataservice/app/src/uninstaller/uninstaller_impl.cpp b/datamgr_service/services/distributeddataservice/app/src/uninstaller/uninstaller_impl.cpp index 77488f11d8d3448abcfaffbd18bd74862046b322..80f0686ab703bde6727192afc362e58c36c6af3a 100644 --- a/datamgr_service/services/distributeddataservice/app/src/uninstaller/uninstaller_impl.cpp +++ b/datamgr_service/services/distributeddataservice/app/src/uninstaller/uninstaller_impl.cpp @@ -93,42 +93,12 @@ Status UninstallerImpl::Init(KvStoreDataService *kvStoreDataService, std::shared auto subscriber = std::make_shared(info); auto removedCallback = [kvStoreDataService](const std::string &bundleName, int32_t userId, int32_t appIndex) { kvStoreDataService->OnUninstall(bundleName, userId, appIndex, IPCSkeleton::GetCallingTokenID()); - std::string prefix = StoreMetaData::GetPrefix({ DeviceManagerAdapter::GetInstance().GetLocalDevice().uuid, - std::to_string(userId), "default", bundleName }); - std::vector storeMetaData; - if (!MetaDataManager::GetInstance().LoadMeta(prefix, storeMetaData)) { - ZLOGE("load meta failed!"); - return; - } - for (auto &meta : storeMetaData) { - if (meta.instanceId == appIndex && !meta.appId.empty() && !meta.storeId.empty()) { - ZLOGI("uninstalled bundleName:%{public}s, stordId:%{public}s", bundleName.c_str(), meta.storeId.c_str()); - 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); - MetaDataManager::GetInstance().DelMeta(CloudInfo::GetSchemaKey(meta), true); - PermitDelegate::GetInstance().DelCache(meta.GetKey()); - } - } + OnUninstall(bundleName, userId, appIndex); }; auto updatedCallback = [kvStoreDataService](const std::string &bundleName, int32_t userId, int32_t appIndex) { kvStoreDataService->OnUpdate(bundleName, userId, appIndex, IPCSkeleton::GetCallingTokenID()); - std::string prefix = StoreMetaData::GetPrefix({ DeviceManagerAdapter::GetInstance().GetLocalDevice().uuid, - std::to_string(userId), "default", bundleName }); - std::vector storeMetaData; - if (!MetaDataManager::GetInstance().LoadMeta(prefix, storeMetaData)) { - ZLOGE("load meta failed!"); - return; - } - for (auto &meta : storeMetaData) { - if (meta.instanceId == appIndex && !meta.appId.empty() && !meta.storeId.empty()) { - ZLOGI("updated bundleName:%{public}s, stordId:%{public}s", bundleName.c_str(), meta.storeId.c_str()); - MetaDataManager::GetInstance().DelMeta(CloudInfo::GetSchemaKey(meta), true); - } - } + OnUpdate(bundleName, userId, appIndex); }; subscriber->RegisterCallback(CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED, removedCallback); @@ -140,6 +110,7 @@ Status UninstallerImpl::Init(KvStoreDataService *kvStoreDataService, std::shared executors_->Execute(GetTask()); return Status::SUCCESS; } + ExecutorPool::Task UninstallerImpl::GetTask() { return [this] { @@ -148,11 +119,51 @@ ExecutorPool::Task UninstallerImpl::GetTask() ZLOGI("subscribe uninstall event success"); return; } - ZLOGE("subscribe uninstall event fail, try times:%{public}d", retryTime_); + ZLOGE("subscribe common event fail, try times:%{public}d", retryTime_); if (retryTime_++ >= RETRY_TIME) { return; } executors_->Schedule(std::chrono::milliseconds(RETRY_INTERVAL), GetTask()); }; } + +void UninstallerImpl::OnUninstall(const std::string &bundleName, int32_t userId, int32_t appIndex) +{ + std::string prefix = StoreMetaData::GetPrefix( + { DeviceManagerAdapter::GetInstance().GetLocalDevice().uuid, std::to_string(userId), "default", bundleName }); + std::vector storeMetaData; + if (!MetaDataManager::GetInstance().LoadMeta(prefix, storeMetaData)) { + ZLOGE("load meta failed!"); + return; + } + for (auto &meta : storeMetaData) { + if (meta.instanceId == appIndex && !meta.appId.empty() && !meta.storeId.empty()) { + ZLOGI("uninstalled bundleName:%{public}s stordId:%{public}s", bundleName.c_str(), meta.storeId.c_str()); + 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); + MetaDataManager::GetInstance().DelMeta(CloudInfo::GetSchemaKey(meta), true); + PermitDelegate::GetInstance().DelCache(meta.GetKey()); + } + } +} + +void UninstallerImpl::OnUpdate(const std::string &bundleName, int32_t userId, int32_t appIndex) +{ + std::string prefix = StoreMetaData::GetPrefix( + { DeviceManagerAdapter::GetInstance().GetLocalDevice().uuid, std::to_string(userId), "default", bundleName }); + std::vector storeMetaData; + if (!MetaDataManager::GetInstance().LoadMeta(prefix, storeMetaData)) { + ZLOGE("load meta failed!"); + return; + } + for (auto &meta : storeMetaData) { + if (meta.instanceId == appIndex && !meta.appId.empty() && !meta.storeId.empty()) { + ZLOGI("updated bundleName:%{public}s, stordId:%{public}s", bundleName.c_str(), meta.storeId.c_str()); + MetaDataManager::GetInstance().DelMeta(CloudInfo::GetSchemaKey(meta), true); + } + } +} } // namespace OHOS::DistributedKv diff --git a/datamgr_service/services/distributeddataservice/app/src/uninstaller/uninstaller_impl.h b/datamgr_service/services/distributeddataservice/app/src/uninstaller/uninstaller_impl.h index 07a026c83b21bbb5bae48013ab0489217e708356..4de54f49d8f5fc169f05ce1f53d83fb2301717fb 100644 --- a/datamgr_service/services/distributeddataservice/app/src/uninstaller/uninstaller_impl.h +++ b/datamgr_service/services/distributeddataservice/app/src/uninstaller/uninstaller_impl.h @@ -25,7 +25,7 @@ using UninstallEventCallback = std::function callbacks_; - }; class UninstallerImpl : public Uninstaller { public: @@ -48,6 +47,8 @@ public: private: static constexpr int32_t RETRY_TIME = 300; static constexpr int32_t RETRY_INTERVAL = 100; + static void OnUninstall(const std::string &bundleName, int32_t userId, int32_t appIndex); + static void OnUpdate(const std::string &bundleName, int32_t userId, int32_t appIndex); int32_t retryTime_; ExecutorPool::Task GetTask(); std::shared_ptr subscriber_ {}; diff --git a/mock/innerkits/access_token/libaccesstoken_sdk/include/accesstoken_kit.h b/mock/innerkits/access_token/libaccesstoken_sdk/include/accesstoken_kit.h index 9064c4272ed33517cd6ed1f7cdf68fcbcb78c233..026f419927e386459cdb495b8a6fcbfe34362f6c 100644 --- a/mock/innerkits/access_token/libaccesstoken_sdk/include/accesstoken_kit.h +++ b/mock/innerkits/access_token/libaccesstoken_sdk/include/accesstoken_kit.h @@ -42,6 +42,7 @@ #include #include +#include #include "access_token.h" #include "hap_token_info.h" diff --git a/mock/src/mock_ipc.cpp b/mock/src/mock_ipc.cpp index 18d285ca057416948ed6bf20544a3b1bfd7862ee..7c179df7bce51d6d74e98bc9bd2c44f59bf70b23 100644 --- a/mock/src/mock_ipc.cpp +++ b/mock/src/mock_ipc.cpp @@ -121,6 +121,14 @@ uint32_t IPCSkeleton::GetCallingTokenID() return GetAccessTokenId(¶ms); } +uint64_t IPCSkeleton::GetCallingFullTokenID() +{ + NativeTokenInfoParams params{0}; + params.processName = "distributed_test"; + params.aplStr = "distributed_test"; + return GetAccessTokenId(¶ms); +} + uint64_t IPCSkeleton::GetSelfTokenID() { NativeTokenInfoParams params{0}; diff --git a/mock/src/mock_notification.cpp b/mock/src/mock_notification.cpp index d6f1beb87bb013e0baf20c763b56a18597b82d9e..e9ae436c826569f5ba3d43046a01e5cf68ffd2f6 100644 --- a/mock/src/mock_notification.cpp +++ b/mock/src/mock_notification.cpp @@ -194,6 +194,7 @@ const std::string CommonEventSupport::COMMON_EVENT_HWID_LOGOUT = "COMMON_EVENT_H const std::string CommonEventSupport::COMMON_EVENT_HWID_LOGIN = "COMMON_EVENT_HWID_LOGIN"; const std::string CommonEventSupport::COMMON_EVENT_PACKAGE_REPLACED = "COMMON_EVENT_PACKAGE_REPLACED"; const std::string CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED = "COMMON_EVENT_PACKAGE_REMOVED"; +const std::string CommonEventSupport::COMMON_EVENT_PACKAGE_CHANGED = "COMMON_EVENT_PACKAGE_CHANGED"; const std::string CommonEventSupport::COMMON_EVENT_USER_SWITCHED = "COMMON_EVENT_USER_SWITCHED"; const std::string CommonEventSupport::COMMON_EVENT_SANDBOX_PACKAGE_REMOVED = "COMMON_EVENT_SANDBOX_PACKAGE_REMOVED"; bool CommonEventSubscribeInfo::Marshalling(OHOS::Parcel &) const { return true; }