diff --git a/services/distributeddataservice/service/object/include/object_service_impl.h b/services/distributeddataservice/service/object/include/object_service_impl.h index 4dd5f1ca69e85670efaf8718cfdbf92255eb352b..79549a94d38c638fad172d4783c0f55884b504ce 100644 --- a/services/distributeddataservice/service/object/include/object_service_impl.h +++ b/services/distributeddataservice/service/object/include/object_service_impl.h @@ -76,6 +76,7 @@ private: static Factory factory_; std::shared_ptr executors_; + static constexpr int64_t WAIT_ACCOUNT_SERVICE = 5; }; } // namespace OHOS::DistributedObject #endif diff --git a/services/distributeddataservice/service/object/src/object_manager.cpp b/services/distributeddataservice/service/object/src/object_manager.cpp index 557b61de3a91759c4c61c2f58b582f3e594a8f46..cc7f041ae5bcac083b6142b73056753360e2848d 100644 --- a/services/distributeddataservice/service/object/src/object_manager.cpp +++ b/services/distributeddataservice/service/object/src/object_manager.cpp @@ -494,27 +494,6 @@ void ObjectStoreManager::NotifyChange(const ObjectRecord &changedData) } } auto data = GetObjectData(changedData, saveInfo, hasAsset); - auto isSameAccount = DeviceManagerAdapter::GetInstance().IsSameAccount(saveInfo.sourceDeviceId); - if (!isSameAccount) { - ZLOGE("IsSameAccount failed. bundleName:%{public}s, source device:%{public}s", saveInfo.bundleName.c_str(), - Anonymous::Change(saveInfo.sourceDeviceId).c_str()); - auto status = Open(); - if (status != OBJECT_SUCCESS) { - ZLOGE("Open failed, bundleName:%{public}s, source device::%{public}s, status: %{public}d", - saveInfo.bundleName.c_str(), Anonymous::Change(saveInfo.sourceDeviceId).c_str(), status); - return; - } - std::vector> keys; - for (const auto &[key, value] : changedData) { - keys.emplace_back(key.begin(), key.end()); - } - status = delegate_->DeleteBatch(keys); - if (status != DistributedDB::DBStatus::OK) { - ZLOGE("Delete entries failed, bundleName:%{public}s, source device::%{public}s, status: %{public}d", - saveInfo.bundleName.c_str(), Anonymous::Change(saveInfo.sourceDeviceId).c_str(), status); - } - return Close(); - } if (!hasAsset) { ObjectStore::RadarReporter::ReportStateStart(std::string(__FUNCTION__), ObjectStore::DATA_RESTORE, ObjectStore::DATA_RECV, ObjectStore::RADAR_SUCCESS, ObjectStore::START, saveInfo.bundleName); @@ -1023,10 +1002,6 @@ int32_t ObjectStoreManager::SyncOnStore( callback({{LOCAL_DEVICE, OBJECT_SUCCESS}}); return OBJECT_SUCCESS; } - if (!DeviceManagerAdapter::GetInstance().IsSameAccount(device)) { - ZLOGE("IsSameAccount failed. device:%{public}s", Anonymous::Change(device).c_str()); - continue; - } syncDevices.emplace_back(DmAdaper::GetInstance().GetUuidByNetworkId(device)); } if (syncDevices.empty()) { diff --git a/services/distributeddataservice/service/object/src/object_service_impl.cpp b/services/distributeddataservice/service/object/src/object_service_impl.cpp index d769fa8856ff12fde502734bd56ca936cf8c4eae..f8ce39d2e1c0c1dd541ec87c1a2e849afe910346 100644 --- a/services/distributeddataservice/service/object/src/object_service_impl.cpp +++ b/services/distributeddataservice/service/object/src/object_service_impl.cpp @@ -134,15 +134,22 @@ int32_t ObjectServiceImpl::OnInitialize() return OBJECT_INNER_ERROR; } auto token = IPCSkeleton::GetCallingTokenID(); - const std::string accountId = DistributedData::AccountDelegate::GetInstance()->GetCurrentAccountId(); const auto userId = DistributedData::AccountDelegate::GetInstance()->GetUserByToken(token); - StoreMetaData saveMeta; - SaveMetaData(saveMeta, std::to_string(userId), accountId); - ObjectStoreManager::GetInstance()->SetData(saveMeta.dataDir, std::to_string(userId)); - ObjectStoreManager::GetInstance()->InitUserMeta(); - RegisterObjectServiceInfo(); - RegisterHandler(); - ObjectDmsHandler::GetInstance().RegisterDmsEvent(); + + if (executors_ == nullptr) { + ZLOGE("executors_ is nullptr"); + return OBJECT_INNER_ERROR; + } + executors_->Schedule(std::chrono::seconds(WAIT_ACCOUNT_SERVICE), [userId, this]() { + StoreMetaData saveMeta; + SaveMetaData(saveMeta, std::to_string(userId), "accountId"); + ObjectStoreManager::GetInstance()->SetData(saveMeta.dataDir, saveMeta.user); + ObjectStoreManager::GetInstance()->InitUserMeta(); + RegisterObjectServiceInfo(); + RegisterHandler(); + ObjectDmsHandler::GetInstance().RegisterDmsEvent(); + }); + return OBJECT_SUCCESS; } @@ -162,14 +169,22 @@ int32_t ObjectServiceImpl::SaveMetaData(StoreMetaData &saveMeta, const std::stri saveMeta.bundleName = DistributedData::Bootstrap::GetInstance().GetProcessLabel(); saveMeta.appId = DistributedData::Bootstrap::GetInstance().GetProcessLabel(); saveMeta.user = user; - saveMeta.account = account; + saveMeta.account = DistributedData::AccountDelegate::GetInstance()->GetCurrentAccountId(); saveMeta.tokenId = IPCSkeleton::GetCallingTokenID(); saveMeta.securityLevel = DistributedKv::SecurityLevel::S1; saveMeta.area = DistributedKv::Area::EL1; saveMeta.uid = IPCSkeleton::GetCallingUid(); saveMeta.storeType = ObjectDistributedType::OBJECT_SINGLE_VERSION; saveMeta.dataType = DistributedKv::DataType::TYPE_DYNAMICAL; - saveMeta.dataDir = DistributedData::DirectoryManager::GetInstance().GetStorePath(saveMeta); + saveMeta.authType = DistributedKv::AuthType::IDENTICAL_ACCOUNT; + int foregroundUserId = 0; + DistributedData::AccountDelegate::GetInstance()->QueryForegroundUserId(foregroundUserId); + saveMeta.user = std::to_string(foregroundUserId); + saveMeta.dataDir = "/data/service/el1/public/database/distributeddata/kvdb"; + if (!DistributedData::DirectoryManager::GetInstance().CreateDirectory(saveMeta.dataDir)) { + ZLOGE("Create directory error, dataDir: %{public}s.", Anonymous::Change(saveMeta.dataDir).c_str()); + return false; + } bool isSaved = DistributedData::MetaDataManager::GetInstance().SaveMeta(saveMeta.GetKeyWithoutPath(), saveMeta) && DistributedData::MetaDataManager::GetInstance().SaveMeta(saveMeta.GetKey(), saveMeta, true); if (!isSaved) { @@ -195,6 +210,9 @@ int32_t ObjectServiceImpl::OnUserChange(uint32_t code, const std::string &user, if (status != OBJECT_SUCCESS) { ZLOGE("Clear fail user:%{public}s, status: %{public}d", user.c_str(), status); } + StoreMetaData saveMeta; + SaveMetaData(saveMeta, user, account); + ObjectStoreManager::GetInstance()->SetData(saveMeta.dataDir, saveMeta.user); } return Feature::OnUserChange(code, user, account); }