diff --git a/services/distributeddataservice/app/src/feature_stub_impl.cpp b/services/distributeddataservice/app/src/feature_stub_impl.cpp index bd206e4bf..a690ddbe9 100644 --- a/services/distributeddataservice/app/src/feature_stub_impl.cpp +++ b/services/distributeddataservice/app/src/feature_stub_impl.cpp @@ -124,4 +124,12 @@ int32_t FeatureStubImpl::OnSessionReady(const std::string &device) } return featureImpl_->OnSessionReady(device); } + +int32_t FeatureStubImpl::OnScreenUnlocked(int32_t user) +{ + if (featureImpl_ == nullptr) { + return -1; + } + return featureImpl_->OnScreenUnlocked(user); +} } diff --git a/services/distributeddataservice/app/src/feature_stub_impl.h b/services/distributeddataservice/app/src/feature_stub_impl.h index d4a2fb516..e9249a76b 100644 --- a/services/distributeddataservice/app/src/feature_stub_impl.h +++ b/services/distributeddataservice/app/src/feature_stub_impl.h @@ -41,6 +41,7 @@ public: int32_t Offline(const std::string &device); int32_t OnReady(const std::string &device); int32_t OnSessionReady(const std::string &device); + int32_t OnScreenUnlocked(int32_t user); private: std::shared_ptr featureImpl_; diff --git a/services/distributeddataservice/app/src/installer/installer_impl.cpp b/services/distributeddataservice/app/src/installer/installer_impl.cpp index 628329961..ed44f08b9 100644 --- a/services/distributeddataservice/app/src/installer/installer_impl.cpp +++ b/services/distributeddataservice/app/src/installer/installer_impl.cpp @@ -60,6 +60,10 @@ void InstallEventSubscriber::OnReceiveEvent(const CommonEventData &event) int32_t appIndex = want.GetIntParam(SANDBOX_APP_INDEX, 0); ZLOGI("bundleName:%{public}s, user:%{public}d, appIndex:%{public}d", bundleName.c_str(), userId, appIndex); (this->*(it->second))(bundleName, userId, appIndex); + } else if (action == CommonEventSupport::COMMON_EVENT_SCREEN_UNLOCKED) { + int32_t userId = want.GetIntParam(USER_ID, -1); + ZLOGI("user:%{public}d ScreenUnlocked", userId); + OnScreenUnlocked(userId); } } @@ -115,6 +119,11 @@ void InstallEventSubscriber::OnInstall(const std::string &bundleName, int32_t us kvStoreDataService_->OnInstall(bundleName, userId, appIndex); } +void InstallEventSubscriber::OnScreenUnlocked(int32_t userId) +{ + kvStoreDataService_->OnScreenUnlocked(userId); +} + InstallerImpl::~InstallerImpl() { ZLOGD("destruct"); diff --git a/services/distributeddataservice/app/src/installer/installer_impl.h b/services/distributeddataservice/app/src/installer/installer_impl.h index 683ae7299..aabcd933e 100644 --- a/services/distributeddataservice/app/src/installer/installer_impl.h +++ b/services/distributeddataservice/app/src/installer/installer_impl.h @@ -36,6 +36,7 @@ private: void OnUninstall(const std::string &bundleName, int32_t userId, int32_t appIndex); void OnUpdate(const std::string &bundleName, int32_t userId, int32_t appIndex); void OnInstall(const std::string &bundleName, int32_t userId, int32_t appIndex); + void OnScreenUnlocked(int32_t userId); std::map callbacks_; KvStoreDataService *kvStoreDataService_; }; diff --git a/services/distributeddataservice/app/src/kvstore_data_service.cpp b/services/distributeddataservice/app/src/kvstore_data_service.cpp index e745b7bcc..5ed825268 100644 --- a/services/distributeddataservice/app/src/kvstore_data_service.cpp +++ b/services/distributeddataservice/app/src/kvstore_data_service.cpp @@ -796,6 +796,15 @@ int32_t KvStoreDataService::OnInstall(const std::string &bundleName, int32_t use return SUCCESS; } +int32_t KvStoreDataService::OnScreenUnlocked(int32_t user) +{ + features_.ForEachCopies([user](const auto &key, sptr &value) { + value->OnScreenUnlocked(user); + return false; + }); + return SUCCESS; +} + int32_t KvStoreDataService::ClearAppStorage(const std::string &bundleName, int32_t userId, int32_t appIndex, int32_t tokenId) { diff --git a/services/distributeddataservice/app/src/kvstore_data_service.h b/services/distributeddataservice/app/src/kvstore_data_service.h index 308da088e..ae5b3b1c4 100644 --- a/services/distributeddataservice/app/src/kvstore_data_service.h +++ b/services/distributeddataservice/app/src/kvstore_data_service.h @@ -118,6 +118,8 @@ public: int32_t OnInstall(const std::string &bundleName, int32_t user, int32_t index); + int32_t OnScreenUnlocked(int32_t user); + private: void NotifyAccountEvent(const AccountEventInfo &eventInfo); class KvStoreClientDeathObserverImpl { diff --git a/services/distributeddataservice/framework/feature/feature_system.cpp b/services/distributeddataservice/framework/feature/feature_system.cpp index f0baaa321..593a7c63b 100644 --- a/services/distributeddataservice/framework/feature/feature_system.cpp +++ b/services/distributeddataservice/framework/feature/feature_system.cpp @@ -125,5 +125,10 @@ int32_t FeatureSystem::Feature::OnBind(const FeatureSystem::Feature::BindInfo &b { return E_OK; } + +int32_t FeatureSystem::Feature::OnScreenUnlocked(int32_t user) +{ + return E_OK; +} } // namespace DistributedData } // namespace OHOS \ No newline at end of file diff --git a/services/distributeddataservice/framework/include/feature/feature_system.h b/services/distributeddataservice/framework/include/feature/feature_system.h index a56aa0d34..ecadb34db 100644 --- a/services/distributeddataservice/framework/include/feature/feature_system.h +++ b/services/distributeddataservice/framework/include/feature/feature_system.h @@ -56,6 +56,7 @@ public: virtual int32_t Offline(const std::string &device); virtual int32_t OnReady(const std::string &device); virtual int32_t OnSessionReady(const std::string &device); + virtual int32_t OnScreenUnlocked(int32_t user); }; using Creator = std::function()>; static FeatureSystem &GetInstance(); diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index 37f5e9bf7..4e327057e 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -320,29 +320,19 @@ std::map> CloudServiceImpl::GetDbInfoFromE bool CloudServiceImpl::DoKvCloudSync(int32_t userId, const std::string &bundleName) { - auto dynamicStores = CheckerManager::GetInstance().GetDynamicStores(); + auto stores = CheckerManager::GetInstance().GetDynamicStores(); auto staticStores = CheckerManager::GetInstance().GetStaticStores(); + stores.insert(stores.end(), staticStores.begin(), staticStores.end()); bool found = false; - for (auto &dynamicStore : dynamicStores) { - if (dynamicStore.bundleName == bundleName) { + for (auto &store : stores) { + if (store.bundleName == bundleName || bundleName.empty()) { found = true; break; } } - if (!found) { - for (auto &staticStore : staticStores) { - if (staticStore.bundleName == bundleName) { - found = true; - break; - } - } - } if (found) { - for (auto &dynamicStore : dynamicStores) { - syncManager_.DoCloudSync(SyncManager::SyncInfo(userId, dynamicStore.bundleName)); - } - for (auto &staticStore : staticStores) { - syncManager_.DoCloudSync(SyncManager::SyncInfo(userId, staticStore.bundleName)); + for (auto &store : stores) { + syncManager_.DoCloudSync(SyncManager::SyncInfo(userId, store.bundleName, store.storeId)); } } return found; @@ -647,6 +637,12 @@ int32_t CloudServiceImpl::OnUserChange(uint32_t code, const std::string &user, c return E_OK; } +int32_t CloudServiceImpl::OnScreenUnlocked(int32_t user) +{ + DoKvCloudSync(user); + return E_OK; +} + int32_t CloudServiceImpl::OnReady(const std::string& device) { if (device != DeviceManagerAdapter::CLOUD_DEVICE_UUID) { diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.h b/services/distributeddataservice/service/cloud/cloud_service_impl.h index d194552a0..76476c253 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.h +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.h @@ -67,6 +67,7 @@ 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 OnScreenUnlocked(int32_t user) override; int32_t OnReady(const std::string &device) override; int32_t Offline(const std::string &device) override; @@ -157,7 +158,7 @@ private: const DistributedData::ExtraData &extraData, const SchemaMeta &schemaMeta); std::shared_ptr GetSharingHandle(const HapInfo& hapInfo); bool GetStoreMetaData(StoreMetaData &meta); - bool DoKvCloudSync(int32_t userId, const std::string &bundleName); + bool DoKvCloudSync(int32_t userId, const std::string &bundleName = ""); using SaveStrategy = int32_t (*)(const std::vector &values, const HapInfo &hapInfo); static const SaveStrategy STRATEGY_SAVERS[Strategy::STRATEGY_BUTT];