• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 #include "flat_object_storage_engine.h"
16 
17 #include "accesstoken_kit.h"
18 #include "ipc_skeleton.h"
19 #include "objectstore_errors.h"
20 #include "process_communicator_impl.h"
21 #include "softbus_adapter.h"
22 #include "string_utils.h"
23 #include "object_radar_reporter.h"
24 
25 namespace OHOS::ObjectStore {
~FlatObjectStorageEngine()26 FlatObjectStorageEngine::~FlatObjectStorageEngine()
27 {
28     if (!isOpened_) {
29         return;
30     }
31     storeManager_ = nullptr;
32     LOG_INFO("FlatObjectStorageEngine::~FlatObjectStorageEngine Crash! end");
33 }
34 
Open(const std::string & bundleName)35 uint32_t FlatObjectStorageEngine::Open(const std::string &bundleName)
36 {
37     if (isOpened_) {
38         LOG_INFO("FlatObjectDatabase: No need to reopen it");
39         return SUCCESS;
40     }
41     auto tokenId = IPCSkeleton::GetSelfTokenID();
42     int32_t ret = Security::AccessToken::AccessTokenKit::VerifyAccessToken(tokenId, DISTRIBUTED_DATASYNC);
43     LOG_INFO("bundleName:%{public}s, permission :%{public}d", bundleName.c_str(), ret);
44     if (ret == Security::AccessToken::PermissionState::PERMISSION_GRANTED) {
45         auto status = DistributedDB::KvStoreDelegateManager::SetProcessLabel("objectstoreDB", bundleName);
46         if (status != DistributedDB::DBStatus::OK) {
47             LOG_ERROR("delegate SetProcessLabel failed: %{public}d.", static_cast<int>(status));
48         }
49         status = DistributedDB::KvStoreDelegateManager::SetProcessCommunicator(
50             std::make_shared<ProcessCommunicatorImpl>());
51         if (status != DistributedDB::DBStatus::OK) {
52             LOG_ERROR("set distributed db communicator failed: %{public}d.", static_cast<int>(status));
53         }
54     }
55     storeManager_ = std::make_shared<DistributedDB::KvStoreDelegateManager>(bundleName, "default");
56     DistributedDB::KvStoreConfig config;
57     config.dataDir = "/data/log";
58     storeManager_->SetKvStoreConfig(config);
59     isOpened_ = true;
60     LOG_INFO("FlatObjectDatabase::Open Succeed");
61     return SUCCESS;
62 }
63 
Close()64 uint32_t FlatObjectStorageEngine::Close()
65 {
66     if (!isOpened_) {
67         LOG_INFO("FlatObjectStorageEngine::Close has been closed!");
68         return SUCCESS;
69     }
70     std::lock_guard<std::mutex> lock(operationMutex_);
71     storeManager_ = nullptr;
72     isOpened_ = false;
73     return SUCCESS;
74 }
75 
OnComplete(const std::string & key,const std::map<std::string,DistributedDB::DBStatus> & devices,std::shared_ptr<StatusWatcher> statusWatcher)76 void FlatObjectStorageEngine::OnComplete(const std::string &key,
77     const std::map<std::string, DistributedDB::DBStatus> &devices, std::shared_ptr<StatusWatcher> statusWatcher)
78 {
79     std::lock_guard<std::mutex> lock(watcherMutex_);
80     LOG_INFO("complete");
81     if (statusWatcher != nullptr) {
82         for (auto item : devices) {
83             statusWatcher->OnChanged(key, SoftBusAdapter::GetInstance()->ToNodeID(item.first),
84                 item.second == DistributedDB::OK ? "online" : "offline");
85         }
86     }
87 }
88 
CreateTable(const std::string & key)89 uint32_t FlatObjectStorageEngine::CreateTable(const std::string &key)
90 {
91     RadarReporter::ReportStage(std::string(__FUNCTION__), CREATE, CREATE_TABLE, IDLE);
92     if (!isOpened_) {
93         RadarReporter::ReportStateError(std::string(__FUNCTION__), CREATE, CREATE_TABLE,
94             RADAR_FAILED, DB_NOT_INIT, FINISHED);
95         return ERR_DB_NOT_INIT;
96     }
97     {
98         std::lock_guard<std::mutex> lock(operationMutex_);
99         if (delegates_.count(key) != 0) {
100             LOG_ERROR("FlatObjectStorageEngine::CreateTable %{public}s already created", key.c_str());
101             RadarReporter::ReportStateError(std::string(__FUNCTION__), CREATE, CREATE_TABLE, RADAR_FAILED,
102                 DUPLICATE_CREATE, FINISHED);
103             return ERR_EXIST;
104         }
105     }
106     DistributedDB::KvStoreNbDelegate *kvStore = nullptr;
107     DistributedDB::DBStatus status;
108     DistributedDB::KvStoreNbDelegate::Option option = { true, true, false };
109     LOG_INFO("start create table");
110     storeManager_->GetKvStore(key, option,
111         [&status, &kvStore](DistributedDB::DBStatus dbStatus, DistributedDB::KvStoreNbDelegate *kvStoreNbDelegate) {
112             status = dbStatus;
113             kvStore = kvStoreNbDelegate;
114             LOG_INFO("create table result %{public}d", status);
115         });
116     if (status != DistributedDB::DBStatus::OK || kvStore == nullptr) {
117         LOG_ERROR("FlatObjectStorageEngine::CreateTable %{public}s getkvstore fail[%{public}d]", key.c_str(), status);
118         RadarReporter::ReportStateError(std::string(__FUNCTION__), CREATE, CREATE_TABLE,
119             RADAR_FAILED, status, FINISHED);
120         return ERR_DB_GETKV_FAIL;
121     }
122     bool autoSync = true;
123     DistributedDB::PragmaData data = static_cast<DistributedDB::PragmaData>(&autoSync);
124     LOG_INFO("start Pragma");
125     status = kvStore->Pragma(DistributedDB::AUTO_SYNC, data);
126     if (status != DistributedDB::DBStatus::OK) {
127         LOG_ERROR("FlatObjectStorageEngine::CreateTable %{public}s Pragma fail[%{public}d]", key.c_str(), status);
128         RadarReporter::ReportStateError(std::string(__FUNCTION__), CREATE, CREATE_TABLE,
129             RADAR_FAILED, status, FINISHED);
130         return ERR_DB_GETKV_FAIL;
131     }
132     LOG_INFO("create table %{public}s success", key.c_str());
133     {
134         std::lock_guard<std::mutex> lock(operationMutex_);
135         delegates_.insert_or_assign(key, kvStore);
136     }
137     auto onComplete = [key, this](const std::map<std::string, DistributedDB::DBStatus> &devices) {
138         OnComplete(key, devices, statusWatcher_);
139     };
140     std::vector<DeviceInfo> devices = SoftBusAdapter::GetInstance()->GetDeviceList();
141     std::vector<std::string> deviceIds;
142     for (auto item : devices) {
143         deviceIds.push_back(item.deviceId);
144     }
145     SyncAllData(key, deviceIds, onComplete);
146     RadarReporter::ReportStateFinished(std::string(__FUNCTION__), CREATE, CREATE_TABLE, RADAR_SUCCESS, FINISHED);
147     return SUCCESS;
148 }
149 
GetTable(const std::string & key,std::map<std::string,Value> & result)150 uint32_t FlatObjectStorageEngine::GetTable(const std::string &key, std::map<std::string, Value> &result)
151 {
152     if (!isOpened_) {
153         LOG_ERROR("not opened %{public}s", key.c_str());
154         return ERR_DB_NOT_INIT;
155     }
156     std::lock_guard<std::mutex> lock(operationMutex_);
157     if (delegates_.count(key) == 0) {
158         LOG_INFO("FlatObjectStorageEngine::GetTable %{public}s not exist", key.c_str());
159         return ERR_DB_NOT_EXIST;
160     }
161     result.clear();
162     DistributedDB::KvStoreResultSet *resultSet = nullptr;
163     Key emptyKey;
164     LOG_DEBUG("start GetEntries");
165     auto delegate = delegates_.at(key);
166     DistributedDB::DBStatus status = delegate->GetEntries(emptyKey, resultSet);
167     if (status != DistributedDB::DBStatus::OK || resultSet == nullptr) {
168         LOG_INFO("FlatObjectStorageEngine::GetTable %{public}s GetEntries fail", key.c_str());
169         return ERR_DB_GET_FAIL;
170     }
171     LOG_DEBUG("end GetEntries");
172     while (resultSet->IsAfterLast()) {
173         DistributedDB::Entry entry;
174         status = resultSet->GetEntry(entry);
175         if (status != DistributedDB::DBStatus::OK) {
176             LOG_INFO("FlatObjectStorageEngine::GetTable GetEntry fail, errcode = %{public}d", status);
177             status = delegate->CloseResultSet(resultSet);
178             if (status != DistributedDB::DBStatus::OK) {
179                 LOG_INFO("KvStoreNbDelegate::CloseResultSet fail, errcode = %{public}d", status);
180                 return ERR_RESULTSET;
181             }
182             return ERR_DB_ENTRY_FAIL;
183         }
184         result.insert_or_assign(StringUtils::BytesToStr(entry.key), entry.value);
185         resultSet->MoveToNext();
186     }
187     status = delegate->CloseResultSet(resultSet);
188     if (status != DistributedDB::DBStatus::OK) {
189         LOG_INFO("KvStoreNbDelegate::CloseResultSet fail, errcode = %{public}d", status);
190         return ERR_RESULTSET;
191     }
192     return SUCCESS;
193 }
194 
UpdateItem(const std::string & key,const std::string & itemKey,Value & value)195 uint32_t FlatObjectStorageEngine::UpdateItem(const std::string &key, const std::string &itemKey, Value &value)
196 {
197     if (!isOpened_) {
198         return ERR_DB_NOT_INIT;
199     }
200     std::lock_guard<std::mutex> lock(operationMutex_);
201     if (delegates_.count(key) == 0) {
202         LOG_INFO("FlatObjectStorageEngine::GetTable %{public}s not exist", key.c_str());
203         return ERR_DB_NOT_EXIST;
204     }
205     auto delegate = delegates_.at(key);
206     LOG_DEBUG("start Put");
207     auto status = delegate->Put(StringUtils::StrToBytes(itemKey), value);
208     if (status != DistributedDB::DBStatus::OK) {
209         LOG_ERROR("%{public}s Put fail[%{public}d]", key.c_str(), status);
210         return ERR_CLOSE_STORAGE;
211     }
212     LOG_DEBUG("put success");
213     return SUCCESS;
214 }
215 
UpdateItems(const std::string & key,const std::map<std::string,std::vector<uint8_t>> & data)216 uint32_t FlatObjectStorageEngine::UpdateItems(
217     const std::string &key, const std::map<std::string, std::vector<uint8_t>> &data)
218 {
219     if (!isOpened_ || data.size() == 0) {
220         return ERR_DB_NOT_INIT;
221     }
222     std::lock_guard<std::mutex> lock(operationMutex_);
223     if (delegates_.count(key) == 0) {
224         LOG_INFO("FlatObjectStorageEngine::UpdateItems %{public}s not exist", key.c_str());
225         return ERR_DB_NOT_EXIST;
226     }
227 
228     std::vector<DistributedDB::Entry> entries;
229     for (auto &item : data) {
230         DistributedDB::Entry entry = { .key = StringUtils::StrToBytes(item.first), .value = item.second };
231         entries.emplace_back(entry);
232     }
233     auto delegate = delegates_.at(key);
234     LOG_DEBUG("start PutBatch");
235     auto status = delegate->PutBatch(entries);
236     if (status != DistributedDB::DBStatus::OK) {
237         LOG_ERROR("%{public}s PutBatch fail[%{public}d]", key.c_str(), status);
238         return ERR_CLOSE_STORAGE;
239     }
240     LOG_DEBUG("put success");
241     return SUCCESS;
242 }
243 
DeleteTable(const std::string & key)244 uint32_t FlatObjectStorageEngine::DeleteTable(const std::string &key)
245 {
246     if (!isOpened_) {
247         return ERR_DB_NOT_INIT;
248     }
249     std::lock_guard<std::mutex> lock(operationMutex_);
250     if (delegates_.count(key) == 0) {
251         LOG_INFO("FlatObjectStorageEngine::GetTable %{public}s not exist", key.c_str());
252         return ERR_DB_NOT_EXIST;
253     }
254     LOG_DEBUG("start DeleteTable %{public}s", key.c_str());
255     auto status = storeManager_->CloseKvStore(delegates_.at(key));
256     if (status != DistributedDB::DBStatus::OK) {
257         LOG_ERROR(
258             "FlatObjectStorageEngine::CloseKvStore %{public}s CloseKvStore fail[%{public}d]", key.c_str(), status);
259         return ERR_CLOSE_STORAGE;
260     }
261     LOG_DEBUG("DeleteTable success");
262     delegates_.erase(key);
263     return SUCCESS;
264 }
265 
GetItem(const std::string & key,const std::string & itemKey,Value & value)266 uint32_t FlatObjectStorageEngine::GetItem(const std::string &key, const std::string &itemKey, Value &value)
267 {
268     if (!isOpened_) {
269         return ERR_DB_NOT_INIT;
270     }
271     std::lock_guard<std::mutex> lock(operationMutex_);
272     if (delegates_.count(key) == 0) {
273         LOG_ERROR("FlatObjectStorageEngine::GetItem %{public}s not exist", key.c_str());
274         return ERR_DB_NOT_EXIST;
275     }
276     LOG_DEBUG("start Get %{public}s", key.c_str());
277     DistributedDB::DBStatus status = delegates_.at(key)->Get(StringUtils::StrToBytes(itemKey), value);
278     if (status != DistributedDB::DBStatus::OK) {
279         LOG_ERROR("FlatObjectStorageEngine::GetItem %{public}s item fail %{public}d", itemKey.c_str(), status);
280         return status;
281     }
282     LOG_DEBUG("end Get %{public}s", key.c_str());
283     return SUCCESS;
284 }
285 
RegisterObserver(const std::string & key,std::shared_ptr<TableWatcher> watcher)286 uint32_t FlatObjectStorageEngine::RegisterObserver(const std::string &key, std::shared_ptr<TableWatcher> watcher)
287 {
288     if (!isOpened_) {
289         LOG_ERROR("FlatObjectStorageEngine::RegisterObserver kvStore has not init");
290         return ERR_DB_NOT_INIT;
291     }
292     std::lock_guard<std::mutex> lock(operationMutex_);
293     if (delegates_.count(key) == 0) {
294         LOG_INFO("FlatObjectStorageEngine::RegisterObserver %{public}s not exist", key.c_str());
295         return ERR_DB_NOT_EXIST;
296     }
297     if (observerMap_.count(key) != 0) {
298         LOG_INFO("FlatObjectStorageEngine::RegisterObserver observer already exist.");
299         return SUCCESS;
300     }
301     auto delegate = delegates_.at(key);
302     std::vector<uint8_t> tmpKey;
303     LOG_DEBUG("start RegisterObserver %{public}s", key.c_str());
304     DistributedDB::DBStatus status =
305         delegate->RegisterObserver(tmpKey, DistributedDB::ObserverMode::OBSERVER_CHANGES_FOREIGN, watcher.get());
306     if (status != DistributedDB::DBStatus::OK) {
307         LOG_ERROR("FlatObjectStorageEngine::RegisterObserver watch err %{public}d", status);
308         return ERR_REGISTER;
309     }
310     LOG_DEBUG("end RegisterObserver %{public}s", key.c_str());
311     observerMap_.insert_or_assign(key, watcher);
312     return SUCCESS;
313 }
314 
UnRegisterObserver(const std::string & key)315 uint32_t FlatObjectStorageEngine::UnRegisterObserver(const std::string &key)
316 {
317     if (!isOpened_) {
318         LOG_ERROR("FlatObjectStorageEngine::RegisterObserver kvStore has not init");
319         return ERR_DB_NOT_INIT;
320     }
321     std::lock_guard<std::mutex> lock(operationMutex_);
322     if (delegates_.count(key) == 0) {
323         LOG_INFO("FlatObjectStorageEngine::RegisterObserver %{public}s not exist", key.c_str());
324         return ERR_DB_NOT_EXIST;
325     }
326     auto iter = observerMap_.find(key);
327     if (iter == observerMap_.end()) {
328         LOG_ERROR("FlatObjectStorageEngine::UnRegisterObserver observer not exist.");
329         return ERR_NO_OBSERVER;
330     }
331     auto delegate = delegates_.at(key);
332     std::shared_ptr<TableWatcher> watcher = iter->second;
333     LOG_DEBUG("start UnRegisterObserver %{public}s", key.c_str());
334     DistributedDB::DBStatus status = delegate->UnRegisterObserver(watcher.get());
335     if (status != DistributedDB::DBStatus::OK) {
336         LOG_ERROR("FlatObjectStorageEngine::UnRegisterObserver unRegister err %{public}d", status);
337         return ERR_UNRIGSTER;
338     }
339     LOG_DEBUG("end UnRegisterObserver %{public}s", key.c_str());
340     observerMap_.erase(key);
341     return SUCCESS;
342 }
343 
SetStatusNotifier(std::shared_ptr<StatusWatcher> watcher)344 uint32_t FlatObjectStorageEngine::SetStatusNotifier(std::shared_ptr<StatusWatcher> watcher)
345 {
346     if (!isOpened_) {
347         LOG_ERROR("FlatObjectStorageEngine::SetStatusNotifier kvStore has not init");
348         return ERR_DB_NOT_INIT;
349     }
350     auto databaseStatusNotifyCallback = [this](std::string userId, std::string appId, std::string storeId,
351                                             const std::string deviceId, bool onlineStatus) -> void {
352         std::lock_guard<std::mutex> lock(watcherMutex_);
353         LOG_INFO("complete");
354         if (statusWatcher_ == nullptr) {
355             LOG_INFO("FlatObjectStorageEngine::statusWatcher_ null");
356             return;
357         }
358         if (onlineStatus) {
359             auto onComplete = [this, storeId](const std::map<std::string, DistributedDB::DBStatus> &devices) {
360                 for (auto item : devices) {
361                     LOG_INFO("%{public}s pull data result %{public}d in device %{public}s",
362                         SoftBusAdapter::ToBeAnonymous(storeId).c_str(), item.second,
363                         SoftBusAdapter::ToBeAnonymous(SoftBusAdapter::GetInstance()->ToNodeID(item.first)).c_str());
364                 }
365                 if (statusWatcher_ != nullptr) {
366                     for (auto item : devices) {
367                         statusWatcher_->OnChanged(storeId, SoftBusAdapter::GetInstance()->ToNodeID(item.first),
368                             item.second == DistributedDB::OK ? "online" : "offline");
369                     }
370                 }
371             };
372             SyncAllData(storeId, std::vector<std::string>({ deviceId }), onComplete);
373         } else {
374             statusWatcher_->OnChanged(storeId, SoftBusAdapter::GetInstance()->ToNodeID(deviceId), "offline");
375         }
376     };
377     storeManager_->SetStoreStatusNotifier(databaseStatusNotifyCallback);
378     LOG_INFO("FlatObjectStorageEngine::SetStatusNotifier success");
379     std::lock_guard<std::mutex> lock(watcherMutex_);
380     statusWatcher_ = watcher;
381     return SUCCESS;
382 }
383 
SyncAllData(const std::string & sessionId,const std::vector<std::string> & deviceIds,const std::function<void (const std::map<std::string,DistributedDB::DBStatus> &)> & onComplete)384 uint32_t FlatObjectStorageEngine::SyncAllData(const std::string &sessionId, const std::vector<std::string> &deviceIds,
385     const std::function<void(const std::map<std::string, DistributedDB::DBStatus> &)> &onComplete)
386 {
387     LOG_INFO("start");
388     std::lock_guard<std::mutex> lock(operationMutex_);
389     if (delegates_.count(sessionId) == 0) {
390         LOG_ERROR("FlatObjectStorageEngine::SyncAllData %{public}s already deleted", sessionId.c_str());
391         return ERR_DB_NOT_EXIST;
392     }
393     DistributedDB::KvStoreNbDelegate *kvstore = delegates_.at(sessionId);
394     if (deviceIds.empty()) {
395         LOG_INFO("single device,no need sync");
396         return ERR_SINGLE_DEVICE;
397     }
398     LOG_INFO("start sync %{public}s", sessionId.c_str());
399     DistributedDB::DBStatus status = kvstore->Sync(deviceIds, DistributedDB::SyncMode::SYNC_MODE_PULL_ONLY, onComplete);
400     if (status != DistributedDB::DBStatus::OK) {
401         LOG_ERROR("FlatObjectStorageEngine::UnRegisterObserver unRegister err %{public}d", status);
402         return ERR_UNRIGSTER;
403     }
404     LOG_INFO("end sync %{public}s", sessionId.c_str());
405     return SUCCESS;
406 }
407 
GetItems(const std::string & key,std::map<std::string,std::vector<uint8_t>> & data)408 uint32_t FlatObjectStorageEngine::GetItems(const std::string &key, std::map<std::string, std::vector<uint8_t>> &data)
409 {
410     if (!isOpened_) {
411         LOG_ERROR("FlatObjectStorageEngine::GetItems %{public}s not init", key.c_str());
412         return ERR_DB_NOT_INIT;
413     }
414     std::lock_guard<std::mutex> lock(operationMutex_);
415     if (delegates_.count(key) == 0) {
416         LOG_ERROR("FlatObjectStorageEngine::GetItems %{public}s not exist", key.c_str());
417         return ERR_DB_NOT_EXIST;
418     }
419     LOG_INFO("start Get %{public}s", key.c_str());
420     std::vector<DistributedDB::Entry> entries;
421     DistributedDB::DBStatus status = delegates_.at(key)->GetEntries(StringUtils::StrToBytes(""), entries);
422     if (status != DistributedDB::DBStatus::OK) {
423         LOG_ERROR("FlatObjectStorageEngine::GetItems item fail status = %{public}d", status);
424         return status;
425     }
426     for (auto &item : entries) {
427         data[StringUtils::BytesToStr(item.key)] = item.value;
428     }
429     LOG_INFO("end Get %{public}s", key.c_str());
430     return SUCCESS;
431 }
432 
NotifyStatus(const std::string & sessionId,const std::string & deviceId,const std::string & status)433 void FlatObjectStorageEngine::NotifyStatus(const std::string &sessionId, const std::string &deviceId,
434                                            const std::string &status)
435 {
436     std::lock_guard<std::mutex> lock(watcherMutex_);
437     if (statusWatcher_ == nullptr) {
438         return;
439     }
440     statusWatcher_->OnChanged(sessionId, deviceId, status);
441 }
442 
NotifyChange(const std::string & sessionId,const std::map<std::string,std::vector<uint8_t>> & changedData)443 void FlatObjectStorageEngine::NotifyChange(const std::string &sessionId,
444                                            const std::map<std::string, std::vector<uint8_t>> &changedData)
445 {
446     std::lock_guard<std::mutex> lock(operationMutex_);
447     if (observerMap_.count(sessionId) == 0) {
448         return;
449     }
450     std::vector<std::string> data {};
451     for (const auto &item : changedData) {
452         std::string key = item.first;
453         if (key.compare(0, FIELDS_PREFIX_LEN, FIELDS_PREFIX) == 0) {
454             key = key.substr(FIELDS_PREFIX_LEN);
455         }
456         data.push_back(key);
457     }
458     observerMap_[sessionId]->OnChanged(sessionId, data, false);
459 }
OnChange(const DistributedDB::KvStoreChangedData & data)460 void Watcher::OnChange(const DistributedDB::KvStoreChangedData &data)
461 {
462     std::vector<std::string> changedData;
463     std::string tmp;
464     for (DistributedDB::Entry item : data.GetEntriesInserted()) {
465         tmp = StringUtils::BytesToStr(item.key);
466         LOG_INFO("inserted %{public}s", tmp.c_str());
467         // property key start with p_, 2 is p_ size
468         if (tmp.compare(0, FIELDS_PREFIX_LEN, FIELDS_PREFIX) == 0) {
469             changedData.push_back(tmp.substr(FIELDS_PREFIX_LEN));
470         }
471     }
472     for (DistributedDB::Entry item : data.GetEntriesUpdated()) {
473         tmp = StringUtils::BytesToStr(item.key);
474         LOG_INFO("updated %{public}s", tmp.c_str());
475         // property key start with p_, 2 is p_ size
476         if (tmp.compare(0, FIELDS_PREFIX_LEN, FIELDS_PREFIX) == 0) {
477             changedData.push_back(tmp.substr(FIELDS_PREFIX_LEN));
478         }
479     }
480     this->OnChanged(sessionId_, changedData, true);
481 }
482 
Watcher(const std::string & sessionId)483 Watcher::Watcher(const std::string &sessionId) : sessionId_(sessionId)
484 {
485 }
486 } // namespace OHOS::ObjectStore
487