1 /*
2 * Copyright (c) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 #define LOG_TAG "KvStoreMetaManager"
16
17 #include "kvstore_meta_manager.h"
18
19 #include <ipc_skeleton.h>
20 #include <thread>
21 #include <unistd.h>
22
23 #include "account_delegate.h"
24 #include "bootstrap.h"
25 #include "cloud/change_event.h"
26 #include "communication_provider.h"
27 #include "crypto_manager.h"
28 #include "device_manager_adapter.h"
29 #include "device_matrix.h"
30 #include "directory/directory_manager.h"
31 #include "eventcenter/event_center.h"
32 #include "kvstore_data_service.h"
33 #include "kv_radar_reporter.h"
34 #include "log_print.h"
35 #include "matrix_event.h"
36 #include "metadata/meta_data_manager.h"
37 #include "metadata/store_meta_data_local.h"
38 #include "metadata/version_meta_data.h"
39 #include "runtime_config.h"
40 #include "safe_block_queue.h"
41 #include "store/general_store.h"
42 #include "store/store_info.h"
43 #include "utils/anonymous.h"
44 #include "utils/block_integer.h"
45 #include "utils/crypto.h"
46 #include "utils/ref_count.h"
47 #include "utils/converter.h"
48 #include "water_version_manager.h"
49
50 namespace OHOS {
51 namespace DistributedKv {
52 using Commu = AppDistributedKv::CommunicationProvider;
53 using DmAdapter = DistributedData::DeviceManagerAdapter;
54 using namespace std::chrono;
55 using namespace OHOS::DistributedData;
56 using namespace DistributedDB;
57 using namespace OHOS::AppDistributedKv;
58
59 KvStoreMetaManager::MetaDeviceChangeListenerImpl KvStoreMetaManager::listener_;
60 KvStoreMetaManager::DBInfoDeviceChangeListenerImpl KvStoreMetaManager::dbInfoListener_;
61
KvStoreMetaManager()62 KvStoreMetaManager::KvStoreMetaManager()
63 : metaDelegate_(nullptr), metaDBDirectory_(DirectoryManager::GetInstance().GetMetaStorePath()),
64 label_(Bootstrap::GetInstance().GetProcessLabel()),
65 delegateManager_(Bootstrap::GetInstance().GetProcessLabel(), "default")
66 {
67 ZLOGI("begin.");
68 }
69
~KvStoreMetaManager()70 KvStoreMetaManager::~KvStoreMetaManager()
71 {
72 if (delaySyncTaskId_ != ExecutorPool::INVALID_TASK_ID) {
73 executors_->Remove(delaySyncTaskId_);
74 delaySyncTaskId_ = ExecutorPool::INVALID_TASK_ID;
75 }
76 }
77
GetInstance()78 KvStoreMetaManager &KvStoreMetaManager::GetInstance()
79 {
80 static KvStoreMetaManager instance;
81 return instance;
82 }
83
SubscribeMeta(const std::string & keyPrefix,const ChangeObserver & observer)84 void KvStoreMetaManager::SubscribeMeta(const std::string &keyPrefix, const ChangeObserver &observer)
85 {
86 metaObserver_.handlerMap_[keyPrefix] = observer;
87 }
88
InitMetaListener()89 void KvStoreMetaManager::InitMetaListener()
90 {
91 InitMetaData();
92 auto status = DmAdapter::GetInstance().StartWatchDeviceChange(&listener_, { "metaMgr" });
93 if (status != AppDistributedKv::Status::SUCCESS) {
94 ZLOGW("register metaMgr failed: %{public}d.", status);
95 return;
96 }
97 SubscribeMetaKvStore();
98 InitBroadcast();
99 NotifyAllAutoSyncDBInfo();
100 }
101
InitBroadcast()102 void KvStoreMetaManager::InitBroadcast()
103 {
104 auto pipe = Bootstrap::GetInstance().GetProcessLabel() + "-" + "default";
105 auto result = Commu::GetInstance().ListenBroadcastMsg({ pipe },
106 [](const std::string &device, const AppDistributedKv::LevelInfo &levelInfo) {
107 DistributedData::DeviceMatrix::DataLevel level;
108 level.dynamic = levelInfo.dynamic;
109 level.statics = levelInfo.statics;
110 level.switches = levelInfo.switches;
111 level.switchesLen = levelInfo.switchesLen;
112 DeviceMatrix::GetInstance().OnBroadcast(device, std::move(level));
113 });
114
115 EventCenter::GetInstance().Subscribe(DeviceMatrix::MATRIX_BROADCAST, [pipe](const Event &event) {
116 auto &matrixEvent = static_cast<const MatrixEvent &>(event);
117 auto matrixData = matrixEvent.GetMatrixData();
118 AppDistributedKv::LevelInfo level;
119 level.dynamic = matrixData.dynamic;
120 level.statics = matrixData.statics;
121 level.switches = matrixData.switches;
122 level.switchesLen = matrixData.switchesLen;
123 Commu::GetInstance().Broadcast({ pipe }, std::move(level));
124 });
125
126 ZLOGI("observer matrix broadcast %{public}d.", result);
127 }
128
InitMetaData()129 void KvStoreMetaManager::InitMetaData()
130 {
131 ZLOGI("start.");
132 auto metaDelegate = GetMetaKvStore();
133 if (metaDelegate == nullptr) {
134 ZLOGI("get meta failed.");
135 return;
136 }
137 auto uid = getuid();
138 auto tokenId = IPCSkeleton::GetCallingTokenID();
139 const std::string accountId = AccountDelegate::GetInstance()->GetCurrentAccountId();
140 auto userId = AccountDelegate::GetInstance()->GetUserByToken(tokenId);
141 StoreMetaData data;
142 data.appId = label_;
143 data.appType = "default";
144 data.bundleName = label_;
145 data.dataDir = metaDBDirectory_;
146 data.user = std::to_string(userId);
147 data.deviceId = DmAdapter::GetInstance().GetLocalDevice().uuid;
148 data.isAutoSync = false;
149 data.isBackup = false;
150 data.isEncrypt = false;
151 data.isNeedCompress = true;
152 data.storeType = KvStoreType::SINGLE_VERSION;
153 data.dataType = DataType::TYPE_DYNAMICAL;
154 data.schema = "";
155 data.storeId = Bootstrap::GetInstance().GetMetaDBName();
156 data.account = accountId;
157 data.uid = static_cast<int32_t>(uid);
158 data.version = META_STORE_VERSION;
159 data.securityLevel = SecurityLevel::S1;
160 data.area = EL1;
161 data.tokenId = tokenId;
162 StoreMetaDataLocal localData;
163 localData.isAutoSync = false;
164 localData.isBackup = false;
165 localData.isEncrypt = false;
166 localData.dataDir = metaDBDirectory_;
167 localData.schema = "";
168 localData.isPublic = true;
169 if (!(MetaDataManager::GetInstance().SaveMeta(data.GetKey(), data) &&
170 MetaDataManager::GetInstance().SaveMeta(data.GetKey(), data, true) &&
171 MetaDataManager::GetInstance().SaveMeta(data.GetKeyLocal(), localData, true))) {
172 ZLOGE("save meta fail");
173 }
174 UpdateMetaData();
175 SetCloudSyncer();
176 ZLOGI("end.");
177 }
178
UpdateMetaData()179 void KvStoreMetaManager::UpdateMetaData()
180 {
181 VersionMetaData versionMeta;
182 if (!MetaDataManager::GetInstance().LoadMeta(versionMeta.GetKey(), versionMeta, true)
183 || versionMeta.version < META_VERSION) {
184 std::vector<StoreMetaData> metaDataList;
185 std::string prefix = StoreMetaData::GetPrefix({ DmAdapter::GetInstance().GetLocalDevice().uuid });
186 MetaDataManager::GetInstance().LoadMeta(prefix, metaDataList);
187 for (auto metaData : metaDataList) {
188 MetaDataManager::GetInstance().SaveMeta(metaData.GetKey(), metaData, true);
189 if (CheckerManager::GetInstance().IsDistrust(Converter::ConvertToStoreInfo(metaData)) ||
190 (metaData.storeType >= StoreMetaData::StoreType::STORE_RELATIONAL_BEGIN
191 && metaData.storeType <= StoreMetaData::StoreType::STORE_RELATIONAL_END)) {
192 MetaDataManager::GetInstance().DelMeta(metaData.GetKey());
193 }
194 }
195 }
196 if (versionMeta.version != VersionMetaData::CURRENT_VERSION) {
197 versionMeta.version = VersionMetaData::CURRENT_VERSION;
198 MetaDataManager::GetInstance().SaveMeta(versionMeta.GetKey(), versionMeta, true);
199 }
200 }
201
InitMetaParameter()202 void KvStoreMetaManager::InitMetaParameter()
203 {
204 ZLOGI("start.");
205 executors_->Execute(GetTask(0));
206 DistributedDB::KvStoreConfig kvStoreConfig{ metaDBDirectory_ };
207 delegateManager_.SetKvStoreConfig(kvStoreConfig);
208 }
209
GetTask(uint32_t retry)210 ExecutorPool::Task KvStoreMetaManager::GetTask(uint32_t retry)
211 {
212 return [this, retry] {
213 auto status = CryptoManager::GetInstance().CheckRootKey();
214 if (status == CryptoManager::ErrCode::SUCCESS) {
215 ZLOGI("root key exist.");
216 return;
217 }
218 if (status == CryptoManager::ErrCode::NOT_EXIST &&
219 CryptoManager::GetInstance().GenerateRootKey() == CryptoManager::ErrCode::SUCCESS) {
220 ZLOGI("GenerateRootKey success.");
221 return;
222 }
223 ZLOGW("GenerateRootKey failed, retry times:%{public}d.", static_cast<int>(retry));
224 if (retry + 1 > RETRY_MAX_TIMES) {
225 ZLOGE("fail to register subscriber!");
226 return;
227 }
228 executors_->Schedule(std::chrono::seconds(RETRY_INTERVAL), GetTask(retry + 1));
229 };
230 }
231
GetMetaKvStore()232 KvStoreMetaManager::NbDelegate KvStoreMetaManager::GetMetaKvStore()
233 {
234 if (metaDelegate_ != nullptr) {
235 return metaDelegate_;
236 }
237 std::lock_guard<decltype(mutex_)> lock(mutex_);
238 if (metaDelegate_ != nullptr) {
239 return metaDelegate_;
240 }
241
242 metaDelegate_ = CreateMetaKvStore();
243 auto fullName = GetBackupPath();
244 auto backup = [executors = executors_, queue = std::make_shared<SafeBlockQueue<Backup>>(MAX_TASK_COUNT), fullName](
245 const auto &store) -> int32_t {
246 auto result = queue->PushNoWait([fullName](const auto &store) -> int32_t {
247 return store->Export(fullName, {}, true);
248 });
249 if (!result) {
250 return OK;
251 }
252 executors->Schedule(std::chrono::hours(RETRY_INTERVAL), GetBackupTask(queue, executors, store));
253 return OK;
254 };
255 MetaDataManager::GetInstance().Initialize(metaDelegate_, backup);
256 return metaDelegate_;
257 }
258
GetBackupTask(TaskQueue queue,std::shared_ptr<ExecutorPool> executors,const NbDelegate store)259 ExecutorPool::Task KvStoreMetaManager::GetBackupTask(
260 TaskQueue queue, std::shared_ptr<ExecutorPool> executors, const NbDelegate store)
261 {
262 return [queue, executors, store]() {
263 Backup backupTask;
264 if (!queue->PopNotWait(backupTask)) {
265 return;
266 }
267 if (backupTask(store) != OK && queue->PushNoWait(backupTask)) {
268 executors->Schedule(std::chrono::hours(RETRY_INTERVAL), GetBackupTask(queue, executors, store));
269 }
270 };
271 }
272
CreateMetaKvStore()273 KvStoreMetaManager::NbDelegate KvStoreMetaManager::CreateMetaKvStore()
274 {
275 DistributedDB::DBStatus dbStatusTmp = DistributedDB::DBStatus::NOT_SUPPORT;
276 DistributedDB::KvStoreNbDelegate::Option option;
277 InitDBOption(option);
278 DistributedDB::KvStoreNbDelegate *delegate = nullptr;
279 delegateManager_.GetKvStore(Bootstrap::GetInstance().GetMetaDBName(), option,
280 [&delegate, &dbStatusTmp](DistributedDB::DBStatus dbStatus, DistributedDB::KvStoreNbDelegate *nbDelegate) {
281 delegate = nbDelegate;
282 dbStatusTmp = dbStatus;
283 });
284
285 if (dbStatusTmp == DistributedDB::DBStatus::INVALID_PASSWD_OR_CORRUPTED_DB) {
286 ZLOGE("meta data corrupted!");
287 option.isNeedRmCorruptedDb = true;
288 delegateManager_.GetKvStore(Bootstrap::GetInstance().GetMetaDBName(), option,
289 [&delegate, &dbStatusTmp](DistributedDB::DBStatus dbStatus,
290 DistributedDB::KvStoreNbDelegate *nbDelegate) {
291 delegate = nbDelegate;
292 dbStatusTmp = dbStatus;
293 });
294 }
295
296 if (dbStatusTmp != DistributedDB::DBStatus::OK || delegate == nullptr) {
297 ZLOGE("GetKvStore return error status: %{public}d or delegate is nullptr", static_cast<int>(dbStatusTmp));
298 return nullptr;
299 }
300 delegate->SetRemotePushFinishedNotify([](const RemotePushNotifyInfo &info) {
301 DeviceMatrix::GetInstance().OnExchanged(info.deviceId, DeviceMatrix::META_STORE_MASK,
302 DeviceMatrix::LevelType::DYNAMIC, DeviceMatrix::ChangeType::CHANGE_REMOTE);
303 });
304 bool param = true;
305 auto data = static_cast<DistributedDB::PragmaData>(¶m);
306 delegate->Pragma(DistributedDB::SET_SYNC_RETRY, data);
307 auto release = [this](DistributedDB::KvStoreNbDelegate *delegate) {
308 ZLOGI("release meta data kv store");
309 if (delegate == nullptr) {
310 return;
311 }
312
313 auto result = delegateManager_.CloseKvStore(delegate);
314 if (result != DistributedDB::DBStatus::OK) {
315 ZLOGE("CloseMetaKvStore return error status: %{public}d", static_cast<int>(result));
316 }
317 };
318 return NbDelegate(delegate, release);
319 }
320
InitDBOption(DistributedDB::KvStoreNbDelegate::Option & option)321 void KvStoreMetaManager::InitDBOption(DistributedDB::KvStoreNbDelegate::Option &option)
322 {
323 option.createIfNecessary = true;
324 option.isMemoryDb = false;
325 option.createDirByStoreIdOnly = true;
326 option.isEncryptedDb = false;
327 option.isNeedIntegrityCheck = true;
328 option.isNeedRmCorruptedDb = false;
329 option.isNeedCompressOnSync = true;
330 option.compressionRate = COMPRESS_RATE;
331 option.secOption = { DistributedDB::S1, DistributedDB::ECE };
332 }
333
SetCloudSyncer()334 void KvStoreMetaManager::SetCloudSyncer()
335 {
336 auto cloudSyncer = [this]() {
337 std::lock_guard<decltype(mutex_)> lock(mutex_);
338 if (delaySyncTaskId_ == Executor::INVALID_TASK_ID) {
339 delaySyncTaskId_ = executors_->Schedule(std::chrono::milliseconds(DELAY_SYNC), CloudSyncTask());
340 } else {
341 delaySyncTaskId_ = executors_->Reset(delaySyncTaskId_, std::chrono::milliseconds(DELAY_SYNC));
342 }
343 };
344 MetaDataManager::GetInstance().SetCloudSyncer(cloudSyncer);
345 }
346
CloudSyncTask()347 std::function<void()> KvStoreMetaManager::CloudSyncTask()
348 {
349 return [this]() {
350 {
351 std::lock_guard<decltype(mutex_)> lock(mutex_);
352 delaySyncTaskId_ = ExecutorPool::INVALID_TASK_ID;
353 }
354 DeviceMatrix::GetInstance().OnChanged(DeviceMatrix::META_STORE_MASK);
355 };
356 }
357
SubscribeMetaKvStore()358 void KvStoreMetaManager::SubscribeMetaKvStore()
359 {
360 auto metaDelegate = GetMetaKvStore();
361 if (metaDelegate == nullptr) {
362 ZLOGW("register meta observer failed.");
363 return;
364 }
365
366 int mode = DistributedDB::OBSERVER_CHANGES_NATIVE | DistributedDB::OBSERVER_CHANGES_FOREIGN;
367 auto dbStatus = metaDelegate->RegisterObserver(DistributedDB::Key(), mode, &metaObserver_);
368 if (dbStatus != DistributedDB::DBStatus::OK) {
369 ZLOGW("register meta observer failed :%{public}d.", dbStatus);
370 }
371 }
372
~KvStoreMetaObserver()373 KvStoreMetaManager::KvStoreMetaObserver::~KvStoreMetaObserver()
374 {
375 ZLOGW("meta observer destruct.");
376 }
377
OnChange(const DistributedDB::KvStoreChangedData & data)378 void KvStoreMetaManager::KvStoreMetaObserver::OnChange(const DistributedDB::KvStoreChangedData &data)
379 {
380 ZLOGD("on data change.");
381 HandleChanges(CHANGE_FLAG::INSERT, data.GetEntriesInserted());
382 HandleChanges(CHANGE_FLAG::UPDATE, data.GetEntriesUpdated());
383 HandleChanges(CHANGE_FLAG::DELETE, data.GetEntriesDeleted());
384 KvStoreMetaManager::GetInstance().OnDataChange(CHANGE_FLAG::INSERT, data.GetEntriesInserted());
385 KvStoreMetaManager::GetInstance().OnDataChange(CHANGE_FLAG::UPDATE, data.GetEntriesUpdated());
386 KvStoreMetaManager::GetInstance().OnDataChange(CHANGE_FLAG::DELETE, data.GetEntriesDeleted());
387 }
388
HandleChanges(CHANGE_FLAG flag,const std::list<DistributedDB::Entry> & entries)389 void KvStoreMetaManager::KvStoreMetaObserver::HandleChanges(CHANGE_FLAG flag,
390 const std::list<DistributedDB::Entry> &entries)
391 {
392 for (const auto &entry : entries) {
393 std::string key(entry.key.begin(), entry.key.end());
394 for (const auto &item : handlerMap_) {
395 ZLOGI("flag:%{public}d, key:%{public}s", flag, Anonymous::Change(key).c_str());
396 if (key.find(item.first) == 0) {
397 item.second(entry.key, entry.value, flag);
398 }
399 }
400 }
401 }
402
OnDeviceChanged(const AppDistributedKv::DeviceInfo & info,const AppDistributedKv::DeviceChangeType & type) const403 void KvStoreMetaManager::MetaDeviceChangeListenerImpl::OnDeviceChanged(const AppDistributedKv::DeviceInfo &info,
404 const AppDistributedKv::DeviceChangeType &type) const
405 {
406 if (info.uuid == DmAdapter::CLOUD_DEVICE_UUID) {
407 return;
408 }
409 switch (type) {
410 case AppDistributedKv::DeviceChangeType::DEVICE_OFFLINE:
411 DeviceMatrix::GetInstance().Offline(info.uuid);
412 break;
413 case AppDistributedKv::DeviceChangeType::DEVICE_ONLINE:
414 DeviceMatrix::GetInstance().Online(info.uuid, RefCount([deviceId = info.uuid]() {
415 DmAdapter::GetInstance().NotifyReadyEvent(deviceId);
416 }));
417 break;
418 default:
419 ZLOGI("flag:%{public}d", type);
420 break;
421 }
422 }
423
GetChangeLevelType() const424 AppDistributedKv::ChangeLevelType KvStoreMetaManager::MetaDeviceChangeListenerImpl::GetChangeLevelType() const
425 {
426 return AppDistributedKv::ChangeLevelType::LOW;
427 }
428
GetBackupPath() const429 std::string KvStoreMetaManager::GetBackupPath() const
430 {
431 return (DirectoryManager::GetInstance().GetMetaBackupPath() + "/" +
432 Crypto::Sha256(label_ + "_" + Bootstrap::GetInstance().GetMetaDBName()));
433 }
434
BindExecutor(std::shared_ptr<ExecutorPool> executors)435 void KvStoreMetaManager::BindExecutor(std::shared_ptr<ExecutorPool> executors)
436 {
437 executors_ = executors;
438 }
439
OnDataChange(CHANGE_FLAG flag,const std::list<DistributedDB::Entry> & changedData)440 void KvStoreMetaManager::OnDataChange(CHANGE_FLAG flag, const std::list<DistributedDB::Entry>& changedData)
441 {
442 for (const auto& entry : changedData) {
443 std::string key(entry.key.begin(), entry.key.end());
444 if (key.find(StoreMetaData::GetKey({})) != 0) {
445 continue;
446 }
447 StoreMetaData metaData;
448 metaData.Unmarshall({ entry.value.begin(), entry.value.end() });
449 if (!metaData.isAutoSync) {
450 continue;
451 }
452 std::vector<DistributedDB::DBInfo> dbInfos;
453 AddDbInfo(metaData, dbInfos, flag == CHANGE_FLAG::DELETE);
454 DistributedDB::RuntimeConfig::NotifyDBInfos({ metaData.deviceId }, dbInfos);
455 }
456 }
457
GetDbInfosByDeviceId(const std::string & deviceId,std::vector<DistributedDB::DBInfo> & dbInfos)458 void KvStoreMetaManager::GetDbInfosByDeviceId(const std::string& deviceId, std::vector<DistributedDB::DBInfo>& dbInfos)
459 {
460 std::vector<StoreMetaData> metaData;
461 if (!MetaDataManager::GetInstance().LoadMeta(StoreMetaData::GetPrefix({ deviceId }), metaData)) {
462 ZLOGW("load meta failed, deviceId:%{public}s", Anonymous::Change(deviceId).c_str());
463 return;
464 }
465 for (auto const& data : metaData) {
466 if (data.isAutoSync) {
467 AddDbInfo(data, dbInfos);
468 }
469 }
470 }
471
AddDbInfo(const StoreMetaData & metaData,std::vector<DistributedDB::DBInfo> & dbInfos,bool isDeleted)472 void KvStoreMetaManager::AddDbInfo(const StoreMetaData& metaData, std::vector<DistributedDB::DBInfo>& dbInfos,
473 bool isDeleted)
474 {
475 DistributedDB::DBInfo dbInfo;
476 dbInfo.appId = metaData.deviceId;
477 dbInfo.userId = metaData.user;
478 dbInfo.storeId = metaData.storeId;
479 dbInfo.isNeedSync = !isDeleted;
480 dbInfo.syncDualTupleMode = true;
481 dbInfos.push_back(dbInfo);
482 }
483
OnDeviceChange(const std::string & deviceId)484 void KvStoreMetaManager::OnDeviceChange(const std::string& deviceId)
485 {
486 std::vector<DistributedDB::DBInfo> dbInfos;
487 GetDbInfosByDeviceId(deviceId, dbInfos);
488 DistributedDB::RuntimeConfig::NotifyDBInfos({ deviceId }, dbInfos);
489 }
490
NotifyAllAutoSyncDBInfo()491 void KvStoreMetaManager::NotifyAllAutoSyncDBInfo()
492 {
493 auto deviceId = DmAdapter::GetInstance().GetLocalDevice().uuid;
494 if (deviceId.empty()) {
495 ZLOGE("local deviceId empty");
496 return;
497 }
498 std::vector<StoreMetaData> metaData;
499 if (!MetaDataManager::GetInstance().LoadMeta(StoreMetaData::GetPrefix({ deviceId }), metaData)) {
500 ZLOGE("load meta failed, deviceId:%{public}s", Anonymous::Change(deviceId).c_str());
501 return;
502 }
503 std::vector<DistributedDB::DBInfo> dbInfos;
504 for (auto const& data : metaData) {
505 if (!data.isAutoSync) {
506 continue;
507 }
508 AddDbInfo(data, dbInfos);
509 }
510 if (!dbInfos.empty()) {
511 DistributedDB::RuntimeConfig::NotifyDBInfos({ deviceId }, dbInfos);
512 }
513 }
514
OnDeviceChanged(const AppDistributedKv::DeviceInfo & info,const DeviceChangeType & type) const515 void KvStoreMetaManager::DBInfoDeviceChangeListenerImpl::OnDeviceChanged(const AppDistributedKv::DeviceInfo& info,
516 const DeviceChangeType& type) const
517 {
518 if (type != DeviceChangeType::DEVICE_ONLINE) {
519 ZLOGD("offline or onReady ignore, type:%{public}d, deviceId:%{public}s", type,
520 Anonymous::Change(info.uuid).c_str());
521 return;
522 }
523 if (info.uuid == DistributedData::DeviceManagerAdapter::CLOUD_DEVICE_UUID) {
524 ZLOGD("Network change, ignore");
525 return;
526 }
527 KvStoreMetaManager::GetInstance().OnDeviceChange(info.uuid);
528 }
529
GetChangeLevelType() const530 AppDistributedKv::ChangeLevelType KvStoreMetaManager::DBInfoDeviceChangeListenerImpl::GetChangeLevelType() const
531 {
532 return AppDistributedKv::ChangeLevelType::MIN;
533 }
534 } // namespace DistributedKv
535 } // namespace OHOS