diff --git a/datamgr_service/services/distributeddataservice/framework/include/store/general_store.h b/datamgr_service/services/distributeddataservice/framework/include/store/general_store.h index 46b748d92e9dcca48f9b6c86bfbe2a5ecf24f509..b7a3775bfc647a9fcf2cd7361739a7202e48a246 100644 --- a/datamgr_service/services/distributeddataservice/framework/include/store/general_store.h +++ b/datamgr_service/services/distributeddataservice/framework/include/store/general_store.h @@ -24,7 +24,7 @@ namespace OHOS::DistributedData { class CloudDB; class AssetLoader; -class Database; +struct Database; class GeneralStore { public: using Watcher = GeneralWatcher; diff --git a/datamgr_service/services/distributeddataservice/service/permission/src/permit_delegate.cpp b/datamgr_service/services/distributeddataservice/service/permission/src/permit_delegate.cpp index 7a4bd29e6d157103362ab5adc9d3c80deb3e8a14..52b9af7c4e4c59c0c06f9c8d3c555f601a40d843 100644 --- a/datamgr_service/services/distributeddataservice/service/permission/src/permit_delegate.cpp +++ b/datamgr_service/services/distributeddataservice/service/permission/src/permit_delegate.cpp @@ -79,7 +79,7 @@ bool PermitDelegate::SyncActivate(const ActiveParam ¶m) bool PermitDelegate::VerifyPermission(const CheckParam ¶m, uint8_t flag) { ZLOGI("user:%{public}s, appId:%{public}s, storeId:%{public}s, remote devId:%{public}s, instanceId:%{public}d," - "flag:%{public}u", param.userId.c_str(), param.appId.c_str(), param.storeId.c_str(), + "flag:%{public}u", param.userId.c_str(), param.appId.c_str(), Anonymous::Change(param.storeId).c_str(), Anonymous::Change(param.deviceId).c_str(), param.instanceId, flag); auto devId = DeviceManagerAdapter::GetInstance().GetLocalDevice().uuid; diff --git a/datamgr_service/services/distributeddataservice/service/rdb/rdb_service_impl.cpp b/datamgr_service/services/distributeddataservice/service/rdb/rdb_service_impl.cpp index c1779c68e543d1cd53a13ba1d9e9d2a19a8398f8..e455ffc4cc1b892804ecd0de2cd1884781758e03 100644 --- a/datamgr_service/services/distributeddataservice/service/rdb/rdb_service_impl.cpp +++ b/datamgr_service/services/distributeddataservice/service/rdb/rdb_service_impl.cpp @@ -27,7 +27,6 @@ #include "metadata/appid_meta_data.h" #include "metadata/meta_data_manager.h" #include "metadata/store_meta_data.h" -#include "permission/permission_validator.h" #include "rdb_watcher.h" #include "rdb_notifier_proxy.h" #include "rdb_query.h" @@ -85,14 +84,14 @@ RdbServiceImpl::RdbServiceImpl() : autoLaunchObserver_(this) meta.instanceId = storeInfo.instanceId; meta.deviceId = DmAdapter::GetInstance().GetLocalDevice().uuid; if (!MetaDataManager::GetInstance().LoadMeta(meta.GetKey(), meta)) { - ZLOGE("meta empty, bundleName:%{public}s, storeId:%{public}s", - meta.bundleName.c_str(), meta.storeId.c_str()); + ZLOGE("meta empty, bundleName:%{public}s, storeId:%{public}s", meta.bundleName.c_str(), + Anonymous::Change(meta.storeId).c_str()); return; } auto watchers = GetWatchers(meta.tokenId, meta.storeId); auto store = AutoCache::GetInstance().GetStore(meta, watchers); if (store == nullptr) { - ZLOGE("store null, storeId:%{public}s", meta.storeId.c_str()); + ZLOGE("store null, storeId:%{public}s", Anonymous::Change(meta.storeId).c_str()); return; } }; @@ -335,7 +334,7 @@ std::pair RdbServiceImpl::DoSync(const RdbSyncerParam ¶m, if (syncer == nullptr) { return {RDB_ERROR, {}}; } - Details details; + Details details = {}; auto status = syncer->DoSync(option, pred, [&details](auto &&result) mutable { details = std::move(result); }); return { status, std::move(details) }; } @@ -464,8 +463,9 @@ int32_t RdbServiceImpl::Subscribe(const RdbSyncerParam ¶m, const SubscribeOp switch (option.mode) { case SubscribeMode::REMOTE: { auto identifier = GenIdentifier(param); - identifiers_.Insert(identifier, std::pair{ pid, tokenId }); - ZLOGI("%{public}s %{public}.6s %{public}d", param.storeName_.c_str(), identifier.c_str(), pid); + identifiers_.Insert(identifier, std::pair { pid, tokenId }); + ZLOGI("%{public}s %{public}.6s %{public}d", Anonymous::Change(param.storeName_).c_str(), + identifier.c_str(), pid); break; } case SubscribeMode::CLOUD: // fallthrough @@ -569,16 +569,16 @@ int32_t RdbServiceImpl::CreateMetaData(const RdbSyncerParam ¶m, StoreMetaDat old.area != meta.area)) { ZLOGE("meta bundle:%{public}s store:%{public}s type:%{public}d->%{public}d encrypt:%{public}d->%{public}d " "area:%{public}d->%{public}d", - meta.bundleName.c_str(), meta.storeId.c_str(), old.storeType, meta.storeType, old.isEncrypt, - meta.isEncrypt, old.area, meta.area); + meta.bundleName.c_str(), Anonymous::Change(meta.storeId).c_str(), old.storeType, meta.storeType, + old.isEncrypt, meta.isEncrypt, old.area, meta.area); return RDB_ERROR; } if (!isCreated || meta != old) { Upgrade(param, old); ZLOGD("meta bundle:%{public}s store:%{public}s type:%{public}d->%{public}d encrypt:%{public}d->%{public}d " "area:%{public}d->%{public}d", - meta.bundleName.c_str(), meta.storeId.c_str(), old.storeType, meta.storeType, old.isEncrypt, - meta.isEncrypt, old.area, meta.area); + meta.bundleName.c_str(), Anonymous::Change(meta.storeId).c_str(), old.storeType, meta.storeType, + old.isEncrypt, meta.isEncrypt, old.area, meta.area); MetaDataManager::GetInstance().SaveMeta(meta.GetKey(), meta); } AppIDMetaData appIdMeta; @@ -587,8 +587,8 @@ int32_t RdbServiceImpl::CreateMetaData(const RdbSyncerParam ¶m, StoreMetaDat if (!MetaDataManager::GetInstance().SaveMeta(appIdMeta.GetKey(), appIdMeta, true)) { ZLOGE("meta bundle:%{public}s store:%{public}s type:%{public}d->%{public}d encrypt:%{public}d->%{public}d " "area:%{public}d->%{public}d", - meta.bundleName.c_str(), meta.storeId.c_str(), old.storeType, meta.storeType, old.isEncrypt, - meta.isEncrypt, old.area, meta.area); + meta.bundleName.c_str(), Anonymous::Change(meta.storeId).c_str(), old.storeType, meta.storeType, + old.isEncrypt, meta.isEncrypt, old.area, meta.area); return RDB_ERROR; } if (!param.isEncrypt_ || param.password_.empty()) { diff --git a/datamgr_service/services/distributeddataservice/service/rdb/rdb_service_impl.h b/datamgr_service/services/distributeddataservice/service/rdb/rdb_service_impl.h index f527997c182735dd07c87308f68faa20924fe110..36d2041c232237d297a30eb3451b629bfe4471ad 100644 --- a/datamgr_service/services/distributeddataservice/service/rdb/rdb_service_impl.h +++ b/datamgr_service/services/distributeddataservice/service/rdb/rdb_service_impl.h @@ -123,7 +123,7 @@ private: static Factory factory_; int32_t syncerNum_ {}; ConcurrentMap syncers_; - ConcurrentMap> identifiers_; + ConcurrentMap> identifiers_;//identifier,pid,tokenid ConcurrentMap syncAgents_; RdbStoreObserverImpl autoLaunchObserver_; std::shared_ptr executors_; diff --git a/datamgr_service/services/distributeddataservice/service/rdb/rdb_service_stub.cpp b/datamgr_service/services/distributeddataservice/service/rdb/rdb_service_stub.cpp index 64fd4c854fd725a9875fe9dcad5a22f01d421bf5..87ec6b42deff513912922048ef083ba0e99aa876 100644 --- a/datamgr_service/services/distributeddataservice/service/rdb/rdb_service_stub.cpp +++ b/datamgr_service/services/distributeddataservice/service/rdb/rdb_service_stub.cpp @@ -102,7 +102,7 @@ int32_t RdbServiceStub::OnRemoteDoSync(MessageParcel &data, MessageParcel &reply return IPC_STUB_INVALID_DATA_ERR; } - Details result; + Details result = {}; auto status = Sync(param, option, predicates, [&result](Details &&details) { result = std::move(details); }); if (!ITypesUtil::Marshal(reply, status, result)) { ZLOGE("Marshal status:0x%{public}x result size:%{public}zu", status, result.size()); @@ -118,7 +118,8 @@ int32_t RdbServiceStub::OnRemoteDoAsync(MessageParcel &data, MessageParcel &repl RdbPredicates predicates; if (!ITypesUtil::Unmarshal(data, param, option, predicates)) { ZLOGE("Unmarshal bundleName_:%{public}s storeName_:%{public}s seqNum:%{public}u tables:%{public}s", - param.bundleName_.c_str(), param.storeName_.c_str(), option.seqNum, (*(predicates.tables_.begin())).c_str()); + param.bundleName_.c_str(), param.storeName_.c_str(), option.seqNum, + (*(predicates.tables_.begin())).c_str()); return IPC_STUB_INVALID_DATA_ERR; } auto status = Sync(param, option, predicates, nullptr); diff --git a/datamgr_service/services/distributeddataservice/service/rdb/rdb_syncer.cpp b/datamgr_service/services/distributeddataservice/service/rdb/rdb_syncer.cpp index 67812be793963ee789d53d257bd1909069e6b351..a9e83914e01cfc6bac393e922ef839db98b29893 100644 --- a/datamgr_service/services/distributeddataservice/service/rdb/rdb_syncer.cpp +++ b/datamgr_service/services/distributeddataservice/service/rdb/rdb_syncer.cpp @@ -23,21 +23,16 @@ #include "cloud/change_event.h" #include "crypto_manager.h" #include "device_manager_adapter.h" -#include "directory_manager.h" #include "eventcenter/event_center.h" -#include "kvstore_utils.h" #include "log_print.h" -#include "metadata/appid_meta_data.h" #include "metadata/meta_data_manager.h" -#include "metadata/store_meta_data.h" #include "rdb_query.h" #include "rdb_result_set_impl.h" #include "store/general_store.h" -#include "types.h" #include "types_export.h" +#include "utils/anonymous.h" #include "utils/constant.h" #include "utils/converter.h" -using OHOS::DistributedKv::KvStoreUtils; using OHOS::DistributedKv::AccountDelegate; using namespace OHOS::Security::AccessToken; using namespace OHOS::DistributedData; @@ -172,11 +167,11 @@ int32_t RdbSyncer::InitDBDelegate(const StoreMetaData &meta) } option.observer = observer_; std::string fileName = meta.dataDir; - ZLOGI("path=%{public}s storeId=%{public}s", fileName.c_str(), meta.storeId.c_str()); + ZLOGI("path=%{public}s storeId=%{public}s", fileName.c_str(), Anonymous::Change(meta.storeId).c_str()); auto status = manager_->OpenStore(fileName, meta.storeId, option, delegate_); if (status != DistributedDB::DBStatus::OK) { ZLOGE("open store failed, path=%{public}s storeId=%{public}s status=%{public}d", - fileName.c_str(), meta.storeId.c_str(), status); + fileName.c_str(), Anonymous::Change(meta.storeId).c_str(), status); return RDB_ERROR; } ZLOGI("open store success"); @@ -237,7 +232,7 @@ std::vector RdbSyncer::GetConnectDevices() } ZLOGI("size=%{public}u", static_cast(devices.size())); for (const auto& device: devices) { - ZLOGI("%{public}s", KvStoreUtils::ToBeAnonymous(device).c_str()); + ZLOGI("%{public}s", Anonymous::Change(device).c_str()); } return devices; } @@ -248,12 +243,11 @@ std::vector RdbSyncer::NetworkIdToUUID(const std::vector %{public}s", KvStoreUtils::ToBeAnonymous(networkId).c_str(), - KvStoreUtils::ToBeAnonymous(uuid).c_str()); + ZLOGI("%{public}s <--> %{public}s", Anonymous::Change(networkId).c_str(), Anonymous::Change(uuid).c_str()); } return uuids; } @@ -345,7 +339,8 @@ void RdbSyncer::Limit(const RdbPredicateOperation &operation, DistributedDB::Que DistributedDB::Query RdbSyncer::MakeQuery(const RdbPredicates &predicates) { ZLOGI("table=%{public}zu", predicates.tables_.size()); - auto query = predicates.tables_.size() == 1 ? DistributedDB::Query::Select(*predicates.tables_.begin()) : DistributedDB::Query::Select(); + auto query = predicates.tables_.size() == 1 ? DistributedDB::Query::Select(*predicates.tables_.begin()) + : DistributedDB::Query::Select(); if (predicates.tables_.size() > 1) { query.FromTable(predicates.tables_); } @@ -374,7 +369,6 @@ int32_t RdbSyncer::DoSync(const Option &option, const RdbPredicates &predicates, async(HandleSyncStatus(syncStatus)); }, option.isAsync); - } else if (option.mode < DistributedData::GeneralStore::CLOUD_END) { CloudEvent::StoreInfo storeInfo; storeInfo.bundleName = GetBundleName(); @@ -433,7 +427,7 @@ int32_t RdbSyncer::RemoveDeviceData() } DistributedDB::DBStatus status = delegate->RemoveDeviceData(); if (status != DistributedDB::DBStatus::OK) { - ZLOGE("DistributedDB RemoveDeviceData failed, status is %{public}d.", status); + ZLOGE("DistributedDB RemoveDeviceData failed, status is %{public}d.", status); return RDB_ERROR; } return RDB_OK; diff --git a/datamgr_service/services/distributeddataservice/service/rdb/rdb_syncer.h b/datamgr_service/services/distributeddataservice/service/rdb/rdb_syncer.h index e3c6cc13867a9ca5249aeb5c226215c7670d6e87..8f09fb341d642372584d52a98ad04035aceb3522 100644 --- a/datamgr_service/services/distributeddataservice/service/rdb/rdb_syncer.h +++ b/datamgr_service/services/distributeddataservice/service/rdb/rdb_syncer.h @@ -77,20 +77,20 @@ private: int32_t InitDBDelegate(const StoreMetaData &meta); - DistributedDB::RelationalStoreDelegate *GetDelegate(); + DistributedDB::RelationalStoreDelegate* GetDelegate(); std::mutex mutex_; - DistributedDB::RelationalStoreManager *manager_{}; - DistributedDB::RelationalStoreDelegate *delegate_{}; + DistributedDB::RelationalStoreManager* manager_ {}; + DistributedDB::RelationalStoreDelegate* delegate_ {}; RdbSyncerParam param_; - RdbStoreObserverImpl *observer_{}; - pid_t pid_{}; - pid_t uid_{}; - uint32_t token_{}; - uint64_t timerId_{}; + RdbStoreObserverImpl *observer_ {}; + pid_t pid_ {}; + pid_t uid_ {}; + uint32_t token_ {}; + uint64_t timerId_ {}; static std::vector GetConnectDevices(); - static std::vector NetworkIdToUUID(const std::vector &networkIds); + static std::vector NetworkIdToUUID(const std::vector& networkIds); static Details HandleSyncStatus(const std::map> &SyncStatus); static Details HandleGenDetails(const GenDetails &details); @@ -101,7 +101,7 @@ private: static void OrderBy(const RdbPredicateOperation &operation, DistributedDB::Query &query); static void Limit(const RdbPredicateOperation &operation, DistributedDB::Query &query); - using PredicateHandle = void (*)(const RdbPredicateOperation &operation, DistributedDB::Query &query); + using PredicateHandle = void(*)(const RdbPredicateOperation& operation, DistributedDB::Query& query); static inline PredicateHandle HANDLES[OPERATOR_MAX] = { [EQUAL_TO] = &RdbSyncer::EqualTo, [NOT_EQUAL_TO] = &RdbSyncer::NotEqualTo, diff --git a/datamgr_service/services/distributeddataservice/service/rdb/rdb_watcher.cpp b/datamgr_service/services/distributeddataservice/service/rdb/rdb_watcher.cpp index c929a7692689b6f85c01369e49bfc823f8898942..1294f292dde9e65e516e19b500a86b102bf74477 100644 --- a/datamgr_service/services/distributeddataservice/service/rdb/rdb_watcher.cpp +++ b/datamgr_service/services/distributeddataservice/service/rdb/rdb_watcher.cpp @@ -37,7 +37,7 @@ int32_t RdbWatcher::OnChange(const Origin &origin, const PRIFields &primaryField rdbOrigin.origin = origin.origin; rdbOrigin.id = origin.id; rdbOrigin.store = origin.store; - notifier->OnChange(rdbOrigin, primaryFields, std::move(values)); + // notifier->OnChange(rdbOrigin, primaryFields, std::move(values)) return E_OK; } diff --git a/datamgr_service/services/distributeddataservice/service/test/cloud_data_test.cpp b/datamgr_service/services/distributeddataservice/service/test/cloud_data_test.cpp index ae3708baa05d490e7d6d701e833919d5d7c09abb..8e9fb981d8fb71a80d4cd9605f9b336fccf15020 100644 --- a/datamgr_service/services/distributeddataservice/service/test/cloud_data_test.cpp +++ b/datamgr_service/services/distributeddataservice/service/test/cloud_data_test.cpp @@ -33,7 +33,7 @@ using namespace testing::ext; using namespace OHOS::DistributedData; using DmAdapter = OHOS::DistributedData::DeviceManagerAdapter; -namespace OHOS { +namespace OHOS::Test { namespace DistributedDataTest { static constexpr const char *TEST_CLOUD_BUNDLE = "test_cloud_bundleName"; static constexpr const char *TEST_CLOUD_APPID = "test_cloud_appid"; @@ -196,4 +196,4 @@ HWTEST_F(CloudDataTest, GetSchema, TestSize.Level0) ASSERT_EQ(to_string(schemaMeta.Marshall()), to_string(schemaMeta_.Marshall())); } } // namespace DistributedDataTest -} // namespace OHOS +} // namespace OHOS::Test diff --git a/relational_store/frameworks/js/napi/cloud_data/src/js_error_utils.cpp b/relational_store/frameworks/js/napi/cloud_data/src/js_error_utils.cpp index 59092fa55e8aa32b94e4219f9a1b0ab3886d377e..246a50767c2eac54afdee420085744d529ceb0a7 100644 --- a/relational_store/frameworks/js/napi/cloud_data/src/js_error_utils.cpp +++ b/relational_store/frameworks/js/napi/cloud_data/src/js_error_utils.cpp @@ -24,7 +24,7 @@ using JsErrorCode = OHOS::CloudData::JsErrorCode; static constexpr JsErrorCode JS_ERROR_CODE_MSGS[] = { { Status::INVALID_ARGUMENT, 401, "Parameter error." }, { Status::NOT_SUPPORT, 801, "Not support." }, - { Status::PERMISSION_DENIED, 202, "Permission denied,non-system app called system api." }, + { Status::PERMISSION_DENIED, 202, "Permission denied, non-system app called system api." }, { Status::CLOUD_CONFIG_PERMISSION_DENIED, 201, "Permission denied." } }; diff --git a/relational_store/frameworks/js/napi/relationalstore/src/napi_rdb_const_properties.cpp b/relational_store/frameworks/js/napi/relationalstore/src/napi_rdb_const_properties.cpp index 06629ba7246dcf087592f4960703fccf45c91e5b..7ef1543007f8be76c27b9122785e19810dcecddb 100644 --- a/relational_store/frameworks/js/napi/relationalstore/src/napi_rdb_const_properties.cpp +++ b/relational_store/frameworks/js/napi/relationalstore/src/napi_rdb_const_properties.cpp @@ -85,6 +85,7 @@ static napi_value ExportSecurityLevel(napi_env env) return securityLevel; } #endif + static napi_value ExportProgress(napi_env env) { napi_value progress = nullptr; diff --git a/relational_store/frameworks/js/napi/relationalstore/src/napi_rdb_store.cpp b/relational_store/frameworks/js/napi/relationalstore/src/napi_rdb_store.cpp index 2848ddc724f91d15e3e8a32b79a3411c502326bb..5013c2ca7f9764327dfc27322a53a90f3a698d88 100644 --- a/relational_store/frameworks/js/napi/relationalstore/src/napi_rdb_store.cpp +++ b/relational_store/frameworks/js/napi/relationalstore/src/napi_rdb_store.cpp @@ -385,7 +385,6 @@ int ParseValuesBucket(const napi_env &env, const napi_value &arg, std::shared_pt CHECK_RETURN_SET(status == napi_ok, std::make_shared("values", "a ValuesBucket.")); std::string keyStr = JSUtils::Convert2String(env, key); napi_value value; - napi_get_property(env, arg, key, &value); ValueObject valueObject; int32_t ret = JSUtils::Convert2Value(env, value, valueObject.value); if (ret == napi_ok) { diff --git a/relational_store/frameworks/native/rdb/include/rdb_security_manager.h b/relational_store/frameworks/native/rdb/include/rdb_security_manager.h index 08f95180bf02c885db94f11d00a70709150975c6..94265fa28523c2b62236443b6afc695d0d2e49ef 100644 --- a/relational_store/frameworks/native/rdb/include/rdb_security_manager.h +++ b/relational_store/frameworks/native/rdb/include/rdb_security_manager.h @@ -76,8 +76,6 @@ public: void DelRdbSecretDataFile(const std::string &path); void DelRdbSecretDataFile(RdbSecurityManager::KeyFileType keyFile); static RdbSecurityManager &GetInstance(); - int GetKeyDistributedStatus(KeyFileType keyFile, bool &status); - int SetKeyDistributedStatus(KeyFileType keyFile, bool status); void Init(const std::string &bundleName, const std::string &path); void UpdateKeyFile(); diff --git a/relational_store/frameworks/native/rdb/include/rdb_store_impl.h b/relational_store/frameworks/native/rdb/include/rdb_store_impl.h index 2fe5761e09ccd7d3e55e52d5c39b3f704aaaff9c..2fc02854733784da02250d771fc8fffc59ba048a 100644 --- a/relational_store/frameworks/native/rdb/include/rdb_store_impl.h +++ b/relational_store/frameworks/native/rdb/include/rdb_store_impl.h @@ -86,7 +86,9 @@ public: int Restore(const std::string &backupPath, const std::vector &newKey) override; int ChangeDbFileForRestore(const std::string &newPath, const std::string &backupPath, const std::vector &newKey) override; -// std::string GetName(); + void GetSchema(); + //std::string GetName(); + std::string GetOrgPath(); std::string GetFileType(); std::shared_ptr QueryByStep(const std::string &sql, std::vector selectionArgs) override; diff --git a/relational_store/frameworks/native/rdb/src/rdb_security_manager.cpp b/relational_store/frameworks/native/rdb/src/rdb_security_manager.cpp index eefbd80529a50dd36ea423218605b8da490e79a9..439e2f537b817851732a205fb4fa7022d611cb34 100644 --- a/relational_store/frameworks/native/rdb/src/rdb_security_manager.cpp +++ b/relational_store/frameworks/native/rdb/src/rdb_security_manager.cpp @@ -598,39 +598,6 @@ bool RdbSecurityManager::CheckKeyDataFileExists(RdbSecurityManager::KeyFileType } } -int RdbSecurityManager::GetKeyDistributedStatus(KeyFileType keyFile, bool &status) -{ - LOG_INFO("GetKeyDistributedStatus start."); - std::string keyPath; - GetKeyPath(keyFile, keyPath); - - RdbSecretKeyData keyData; - if (!LoadSecretKeyFromDisk(keyPath, keyData)) { - return E_ERROR; - } - - status = (keyData.distributed == DISTRIBUTED); - return E_OK; -} - -int RdbSecurityManager::SetKeyDistributedStatus(KeyFileType keyFile, bool status) -{ - LOG_INFO("SetKeyDistributedStatus start."); - std::string keyPath; - GetKeyPath(keyFile, keyPath); - RdbSecretKeyData keyData; - if (!LoadSecretKeyFromDisk(keyPath, keyData)) { - return E_ERROR; - } - - keyData.distributed = (status ? DISTRIBUTED : UNDISTRIBUTED); - if (!SaveSecretKeyToDisk(keyPath, keyData)) { - return E_ERROR; - } - - return E_OK; -} - void RdbSecurityManager::GetKeyPath(RdbSecurityManager::KeyFileType keyType, std::string &keyPath) { if (keyType == KeyFileType::PUB_KEY_FILE) { diff --git a/relational_store/frameworks/native/rdb/src/rdb_service_proxy.cpp b/relational_store/frameworks/native/rdb/src/rdb_service_proxy.cpp index 95c553c45c52465022c924ead5a296fdb635760d..76d7e565056109005c6a3546c4ef983946feefdd 100644 --- a/relational_store/frameworks/native/rdb/src/rdb_service_proxy.cpp +++ b/relational_store/frameworks/native/rdb/src/rdb_service_proxy.cpp @@ -18,8 +18,10 @@ #include "rdb_service_proxy.h" #include "itypes_util.h" #include "log_print.h" +#include "sqlite_utils.h" namespace OHOS::DistributedRdb { +using SqliteUtils = OHOS::NativeRdb::SqliteUtils; #define IPC_SEND(code, reply, ...) \ ({ \ int32_t __status = RDB_OK; \ @@ -79,7 +81,8 @@ std::string RdbServiceProxy::ObtainDistributedTableName(const std::string &devic MessageParcel reply; int32_t status = IPC_SEND(RDB_SERVICE_CMD_OBTAIN_TABLE, reply, device, table); if (status != RDB_OK) { - ZLOGE("status:%{public}d, device:%{public}.6s, table:%{public}s", status, device.c_str(), table.c_str()); + ZLOGE("status:%{public}d, device:%{public}.6s, table:%{public}s", status, + SqliteUtils::Anonymous(device).c_str(), SqliteUtils::Anonymous(table).c_str()); return ""; } return reply.ReadString(); @@ -136,7 +139,7 @@ std::pair RdbServiceProxy::DoSync(const RdbSyncerParam& param, status = IPC_SEND(RDB_SERVICE_CMD_SYNC, reply, param, option, predicates); if (status != RDB_OK) { ZLOGE("status:%{public}d, bundleName:%{public}s, storeName:%{public}s", - status, param.bundleName_.c_str(), param.storeName_.c_str()); + status, param.bundleName_.c_str(), SqliteUtils::Anonymous(param.storeName_).c_str()); return result; } @@ -170,7 +173,7 @@ int32_t RdbServiceProxy::DoAsync(const RdbSyncerParam ¶m, const Option &opti int32_t status = IPC_SEND(RDB_SERVICE_CMD_ASYNC, reply, param, option, predicates); if (status != RDB_OK) { ZLOGE("status:%{public}d, bundleName:%{public}s, storeName:%{public}s, seqNum:%{public}u", status, - param.bundleName_.c_str(), param.storeName_.c_str(), option.seqNum); + param.bundleName_.c_str(), SqliteUtils::Anonymous(param.storeName_).c_str(), option.seqNum); } return status; } @@ -203,7 +206,7 @@ int32_t RdbServiceProxy::SetDistributedTables(const RdbSyncerParam& param, const int32_t status = IPC_SEND(RDB_SERVICE_CMD_SET_DIST_TABLE, reply, param, tables); if (status != RDB_OK) { ZLOGE("status:%{public}d, bundleName:%{public}s, storeName:%{public}s", - status, param.bundleName_.c_str(), param.storeName_.c_str()); + status, param.bundleName_.c_str(), SqliteUtils::Anonymous(param.storeName_).c_str()); } return status; } @@ -259,7 +262,7 @@ int32_t RdbServiceProxy::DoSubscribe(const RdbSyncerParam ¶m, const Subscrib int32_t status = IPC_SEND(RDB_SERVICE_CMD_SUBSCRIBE, reply, param, option); if (status != RDB_OK) { ZLOGE("status:%{public}d, bundleName:%{public}s, storeName:%{public}s", - status, param.bundleName_.c_str(), param.storeName_.c_str()); + status, param.bundleName_.c_str(), SqliteUtils::Anonymous(param.storeName_).c_str()); } return status; } @@ -285,7 +288,7 @@ int32_t RdbServiceProxy::DoUnSubscribe(const RdbSyncerParam ¶m) int32_t status = IPC_SEND(RDB_SERVICE_CMD_UNSUBSCRIBE, reply, param); if (status != RDB_OK) { ZLOGE("status:%{public}d, bundleName:%{public}s, storeName:%{public}s", - status, param.bundleName_.c_str(), param.storeName_.c_str()); + status, param.bundleName_.c_str(), SqliteUtils::Anonymous(param.storeName_).c_str()); } return status; } @@ -297,7 +300,7 @@ int32_t RdbServiceProxy::RemoteQuery(const RdbSyncerParam& param, const std::str int32_t status = IPC_SEND(RDB_SERVICE_CMD_REMOTE_QUERY, reply, param, device, sql, selectionArgs); if (status != RDB_OK) { ZLOGE("status:%{public}d, bundleName:%{public}s, storeName:%{public}s, device:%{public}.6s", - status, param.bundleName_.c_str(), param.storeName_.c_str(), device.c_str()); + status, param.bundleName_.c_str(), SqliteUtils::Anonymous(param.storeName_).c_str(), device.c_str()); return status; } @@ -347,7 +350,7 @@ int32_t RdbServiceProxy::GetSchema(const RdbSyncerParam ¶m) ITypesUtil::Unmarshal(reply, status); if (status != RDB_OK) { ZLOGE("status:%{public}d, bundleName:%{public}s, storeName:%{public}s", status, param.bundleName_.c_str(), - param.storeName_.c_str()); + SqliteUtils::Anonymous(param.storeName_).c_str()); } return status; } diff --git a/relational_store/frameworks/native/rdb/src/rdb_store_impl.cpp b/relational_store/frameworks/native/rdb/src/rdb_store_impl.cpp index afb0da02ea48816496b76f02a312b8e2fb789f15..c125db0044de4cce9dec3bc5a04f014802bb15ba 100644 --- a/relational_store/frameworks/native/rdb/src/rdb_store_impl.cpp +++ b/relational_store/frameworks/native/rdb/src/rdb_store_impl.cpp @@ -92,27 +92,39 @@ int RdbStoreImpl::InnerOpen(const RdbStoreConfig &config) syncerParam_.type_ = config.GetDistributedType(); syncerParam_.isEncrypt_ = config.IsEncrypt(); syncerParam_.password_ = {}; + GetSchema(); +#endif + return E_OK; +} +#if !defined(WINDOWS_PLATFORM) && !defined(MAC_PLATFORM) && !defined(ANDROID_PLATFORM) && !defined(IOS_PLATFORM) +void RdbStoreImpl::GetSchema() +{ + auto [err, service] = DistributedRdb::RdbManagerImpl::GetInstance().GetRdbService(syncerParam_); + if (err != E_OK || service == nullptr) { + LOG_WARN("GetRdbService failed, err is %{public}d.", err); + return; + } + if (isEncrypt_) { + RdbPassword key = + RdbSecurityManager::GetInstance().GetRdbPassword(RdbSecurityManager::KeyFileType::PUB_KEY_FILE); + syncerParam_.password_ = std::vector(key.GetData(), key.GetData() + key.GetSize()); + } if (pool_ == nullptr) { pool_ = TaskExecutor::GetInstance().GetExecutor(); } if (pool_ != nullptr) { auto param = syncerParam_; - pool_->Execute([param]() { - auto [err, service] = DistributedRdb::RdbManagerImpl::GetInstance().GetRdbService(param); - if (err != E_OK || service == nullptr) { - LOG_WARN("GetRdbService failed, err is %{public}d.", err); - return; - } - err = service->GetSchema(param); + auto ser = service; + pool_->Execute([param, ser]() { + auto err = ser->GetSchema(param); if (err != E_OK) { LOG_ERROR("GetSchema failed, err is %{public}d.", err); } }); } -#endif - return E_OK; } +#endif RdbStoreImpl::RdbStoreImpl(const RdbStoreConfig &config) : rdbStoreConfig(config), connectionPool(nullptr), isOpen(false), path(""), orgPath(""), isReadOnly(false), @@ -123,6 +135,10 @@ RdbStoreImpl::RdbStoreImpl(const RdbStoreConfig &config) RdbStoreImpl::~RdbStoreImpl() { delete connectionPool; +#if !defined(WINDOWS_PLATFORM) && !defined(MAC_PLATFORM) && !defined(ANDROID_PLATFORM) && !defined(IOS_PLATFORM) + syncerParam_.password_.assign(syncerParam_.password_.size(), 0); + syncerParam_.password_.clear(); +#endif } #ifdef WINDOWS_PLATFORM @@ -1127,16 +1143,6 @@ int RdbStoreImpl::SetDistributedTables(const std::vector &tables, i LOG_WARN("The distributed tables to be set is empty."); return E_OK; } - if (isEncrypt_) { - bool status = false; - RdbSecurityManager::GetInstance().GetKeyDistributedStatus(RdbSecurityManager::KeyFileType::PUB_KEY_FILE, - status); - if (!status) { - RdbPassword key = - RdbSecurityManager::GetInstance().GetRdbPassword(RdbSecurityManager::KeyFileType::PUB_KEY_FILE); - syncerParam_.password_ = std::vector(key.GetData(), key.GetData() + key.GetSize()); - } - } auto [errCode, service] = DistributedRdb::RdbManagerImpl::GetInstance().GetRdbService(syncerParam_); if (errCode != E_OK) { return errCode; @@ -1144,17 +1150,8 @@ int RdbStoreImpl::SetDistributedTables(const std::vector &tables, i int32_t errorCode = service->SetDistributedTables(syncerParam_, tables, type); if (errorCode != E_OK) { LOG_ERROR("Fail to set distributed tables, error=%{public}d", errorCode); - syncerParam_.password_.assign(syncerParam_.password_.size(), 0); - syncerParam_.password_.clear(); return errorCode; } - - if (isEncrypt_) { - syncerParam_.password_.assign(syncerParam_.password_.size(), 0); - syncerParam_.password_.clear(); - RdbSecurityManager::GetInstance().SetKeyDistributedStatus( - RdbSecurityManager::KeyFileType::PUB_KEY_FILE, true); - } return E_OK; } diff --git a/relational_store/interfaces/inner_api/rdb/include/rdb_types.h b/relational_store/interfaces/inner_api/rdb/include/rdb_types.h index 8c88d5b3c770b6ccbe8fa5eebdb9071f4e44bdc8..569b11e08633efe3a167a18748800eff7300b83d 100644 --- a/relational_store/interfaces/inner_api/rdb/include/rdb_types.h +++ b/relational_store/interfaces/inner_api/rdb/include/rdb_types.h @@ -16,10 +16,8 @@ #ifndef DISTRIBUTED_RDB_RDB_TYPES_H #define DISTRIBUTED_RDB_RDB_TYPES_H -#include #include #include -#include #include #include #include @@ -96,12 +94,14 @@ struct ProgressDetail { TableDetails details; }; -using SyncResult = std::map; using Briefs = std::map; using Details = std::map; using AsyncBrief = std::function; using AsyncDetail = std::function; +using SyncResult = Briefs; +using SyncCallback = AsyncBrief; + enum RdbPredicateOperator { EQUAL_TO, NOT_EQUAL_TO, diff --git a/relational_store/interfaces/inner_api/rdb/mock/include/abs_rdb_predicates.h b/relational_store/interfaces/inner_api/rdb/mock/include/abs_rdb_predicates.h index a010d6801d1560a1285672c029eaef2410c8bb64..40f921994097058383118d62da03022854195bc4 100644 --- a/relational_store/interfaces/inner_api/rdb/mock/include/abs_rdb_predicates.h +++ b/relational_store/interfaces/inner_api/rdb/mock/include/abs_rdb_predicates.h @@ -23,7 +23,7 @@ namespace OHOS::NativeRdb { class AbsRdbPredicates : public AbsPredicates { public: explicit AbsRdbPredicates(std::string tableName); - + explicit AbsRdbPredicates(std::vector tables); ~AbsRdbPredicates() override {} void Clear() override; @@ -50,7 +50,7 @@ protected: int joinCount = 0; private: - std::string tableName; + std::string tableName_; }; } // namespace OHOS::NativeRdb diff --git a/relational_store/test/js/rdb/unittest/src/RdbStoreDistributedJsunit.test.js b/relational_store/test/js/rdb/unittest/src/RdbStoreDistributedJsunit.test.js index 80043f5b8f2b9085a6dffc471f77348c76de036b..8a83410d36ad3ac37f809e9389450beb6418bdd0 100644 --- a/relational_store/test/js/rdb/unittest/src/RdbStoreDistributedJsunit.test.js +++ b/relational_store/test/js/rdb/unittest/src/RdbStoreDistributedJsunit.test.js @@ -28,8 +28,7 @@ describe('rdbStoreDistributedTest', function () { } try { rdbStore = await dataRdb.getRdbStore(config, 1); - console.log(TAG + "create rdb store success") - expect(rdbStore).assertEqual(rdbStore) + console.log(TAG + "create rdb store success"); let sqlStatement = "CREATE TABLE IF NOT EXISTS employee (" + "id INTEGER PRIMARY KEY AUTOINCREMENT," + "name TEXT NOT NULL," + diff --git a/relational_store/test/js/relationalstore/unittest/src/RdbStoreDistributedJsunit.test.js b/relational_store/test/js/relationalstore/unittest/src/RdbStoreDistributedJsunit.test.js index cd1833066cca0f3eea9d79fdbb27ea2974ccde09..186c9f84609990bf75086b84328aeeecda7faf9a 100644 --- a/relational_store/test/js/relationalstore/unittest/src/RdbStoreDistributedJsunit.test.js +++ b/relational_store/test/js/relationalstore/unittest/src/RdbStoreDistributedJsunit.test.js @@ -33,7 +33,6 @@ describe('rdbStoreDistributedTest', function () { try { rdbStore = await data_relationalStore.getRdbStore(context, config); console.log(TAG + "create rdb store success") - expect(rdbStore).assertEqual(rdbStore) let sqlStatement = "CREATE TABLE IF NOT EXISTS employee (" + "id INTEGER PRIMARY KEY AUTOINCREMENT," + "name TEXT NOT NULL," + diff --git a/relational_store/test/native/rdb/distributedtest/rdb_store_impl_test/distributed_test_agent.cpp b/relational_store/test/native/rdb/distributedtest/rdb_store_impl_test/distributed_test_agent.cpp index 0bde80047037146a13623686dae47068de6f59b2..258ef9e80432091d935685830895a1f6252dd636 100644 --- a/relational_store/test/native/rdb/distributedtest/rdb_store_impl_test/distributed_test_agent.cpp +++ b/relational_store/test/native/rdb/distributedtest/rdb_store_impl_test/distributed_test_agent.cpp @@ -50,7 +50,7 @@ public: virtual int OnProcessMsg(const std::string &strMsg, int len, std::string &strReturnValue, int returnBufL); using SyncOption = DistributedRdb::SyncOption; - using SyncCallback = DistributedRdb::SyncCallback; + using SyncCallback = DistributedRdb::AsyncBrief; }; const std::string DistributedTestAgent::DATABASE_NAME = RDB_TEST_PATH + "distributed_rdb.db"; diff --git a/relational_store/test/native/rdb/fuzztest/rdbimpl_fuzzer/rdbimpl_fuzzer.cpp b/relational_store/test/native/rdb/fuzztest/rdbimpl_fuzzer/rdbimpl_fuzzer.cpp index dd799258a34a64a6812751469b78b5d851d64a6f..ac381ef363bb9a3a0566fad14ab0a92158b03a0f 100644 --- a/relational_store/test/native/rdb/fuzztest/rdbimpl_fuzzer/rdbimpl_fuzzer.cpp +++ b/relational_store/test/native/rdb/fuzztest/rdbimpl_fuzzer/rdbimpl_fuzzer.cpp @@ -25,7 +25,7 @@ void RdbStoreImplFuzz(const uint8_t *data, size_t size) std::string rawString(reinterpret_cast(data), size); std::vector tables; tables.push_back(rawString); - rdbStoreImpl.SetDistributedTables(tables); + rdbStoreImpl.SetDistributedTables(tables, size % 2); } } diff --git a/relational_store/test/native/rdb/unittest/rdb_encrypt_decrypt_test.cpp b/relational_store/test/native/rdb/unittest/rdb_encrypt_decrypt_test.cpp index 87a8fe237380055affba1f6facf544f6ec1ab076..b09486903db8d26da8248525d8a282939a2e066f 100644 --- a/relational_store/test/native/rdb/unittest/rdb_encrypt_decrypt_test.cpp +++ b/relational_store/test/native/rdb/unittest/rdb_encrypt_decrypt_test.cpp @@ -318,39 +318,3 @@ HWTEST_F(RdbEncryptTest, RdbStore_Encrypt_08, TestSize.Level1) errCode = RdbHelper::DeleteRdbStore(path); EXPECT_EQ(errCode, E_OK); } - -/** - * @tc.name: RdbStore_Encrypt_Decrypt_Test_009 - * @tc.desc: test GetKeyDistributedStatus and SetKeyDistributedStatus - * @tc.type: FUNC - */ -HWTEST_F(RdbEncryptTest, RdbStore_Encrypt_09, TestSize.Level1) -{ - RdbStoreConfig config(RdbEncryptTest::ENCRYPTED_DATABASE_NAME); - config.SetEncryptStatus(true); - config.SetBundleName("com.example.TestEncrypt9"); - EncryptTestOpenCallback helper; - int errCode; - std::shared_ptr store = RdbHelper::GetRdbStore(config, 1, helper, errCode); - EXPECT_NE(store, nullptr); - - bool distributedStatus = false; - int ret = RdbSecurityManager::GetInstance().GetKeyDistributedStatus( - RdbSecurityManager::KeyFileType::PUB_KEY_FILE, distributedStatus); - EXPECT_EQ(ret, E_OK); - EXPECT_EQ(distributedStatus, false); - ret = RdbSecurityManager::GetInstance().GetKeyDistributedStatus( - RdbSecurityManager::KeyFileType::PUB_KEY_FILE_NEW_KEY, distributedStatus); - EXPECT_EQ(ret, E_ERROR); - EXPECT_EQ(distributedStatus, false); - ret = RdbSecurityManager::GetInstance().SetKeyDistributedStatus( - RdbSecurityManager::KeyFileType::PUB_KEY_FILE, true); - EXPECT_EQ(ret, E_OK); - ret = RdbSecurityManager::GetInstance().GetKeyDistributedStatus( - RdbSecurityManager::KeyFileType::PUB_KEY_FILE, distributedStatus); - EXPECT_EQ(ret, E_OK); - EXPECT_EQ(distributedStatus, true); - ret = RdbSecurityManager::GetInstance().SetKeyDistributedStatus( - RdbSecurityManager::KeyFileType::PUB_KEY_FILE_NEW_KEY, distributedStatus); - EXPECT_EQ(ret, E_ERROR); -} diff --git a/relational_store/test/native/rdb/unittest/rdb_store_subscribe_test.cpp b/relational_store/test/native/rdb/unittest/rdb_store_subscribe_test.cpp index 0dde69e7351c09d51defaefd686d6f33a952242f..215fa70684ad5091b8a72a157c37d117a0c384d5 100644 --- a/relational_store/test/native/rdb/unittest/rdb_store_subscribe_test.cpp +++ b/relational_store/test/native/rdb/unittest/rdb_store_subscribe_test.cpp @@ -1,28 +1,28 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +* Copyright (c) 2023 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ #include #include +#include "cloud_manager.h" #include "common.h" #include "rdb_errno.h" #include "rdb_helper.h" #include "rdb_open_callback.h" #include "rdb_store_manager.h" #include "rdb_types.h" -#include "cloud_manager.h" using namespace testing::ext; using namespace OHOS::NativeRdb; using namespace OHOS::DistributedRdb; @@ -48,7 +48,7 @@ void RdbStoreSubTest::SetUpTestCase(void) { auto [success, service] = CloudManager::GetInstance().GetCloudService(); if (service != nullptr) { - service->EnableCloud("default", {{"relational_test", CloudService::SWITCH_ON}}); + service->EnableCloud("default", { { "relational_test", CloudService::SWITCH_ON } }); } RdbHelper::ClearCache(); RdbHelper::DeleteRdbStore(MAIN_DATABASE_NAME); @@ -88,8 +88,10 @@ int Callback::OnUpgrade(RdbStore &store, int oldVersion, int newVersion) class SubObserver : public RdbStoreObserver { public: - virtual ~SubObserver() {} - void OnChange(const std::vector& devices) override; + virtual ~SubObserver() + { + } + void OnChange(const std::vector &devices) override; }; void SubObserver::OnChange(const std::vector &devices) @@ -112,12 +114,12 @@ std::shared_ptr RdbStoreSubTest::CreateRDB(int version) } /** - * @tc.name: RdbStoreSubscribeRemote - * @tc.desc: RdbStoreSubscribe - * @tc.type: FUNC - * @tc.require: - * @tc.author: - */ +* @tc.name: RdbStoreSubscribeRemote +* @tc.desc: RdbStoreSubscribe +* @tc.type: FUNC +* @tc.require: +* @tc.author: +*/ HWTEST_F(RdbStoreSubTest, RdbStoreSubscribeRemote, TestSize.Level1) { EXPECT_NE(store, nullptr) << "store is nullptr"; @@ -127,12 +129,12 @@ HWTEST_F(RdbStoreSubTest, RdbStoreSubscribeRemote, TestSize.Level1) } /** - * @tc.name: RdbStoreSubscribeCloud - * @tc.desc: RdbStoreSubscribe - * @tc.type: FUNC - * @tc.require: - * @tc.author: - */ +* @tc.name: RdbStoreSubscribeCloud +* @tc.desc: RdbStoreSubscribe +* @tc.type: FUNC +* @tc.require: +* @tc.author: +*/ HWTEST_F(RdbStoreSubTest, RdbStoreSubscribeCloud, TestSize.Level1) { EXPECT_NE(store, nullptr) << "store is nullptr"; @@ -142,12 +144,12 @@ HWTEST_F(RdbStoreSubTest, RdbStoreSubscribeCloud, TestSize.Level1) } /** - * @tc.name: RdbStoreSubscribeCloudDetail - * @tc.desc: RdbStoreSubscribe - * @tc.type: FUNC - * @tc.require: - * @tc.author: - */ +* @tc.name: RdbStoreSubscribeCloudDetail +* @tc.desc: RdbStoreSubscribe +* @tc.type: FUNC +* @tc.require: +* @tc.author: +*/ HWTEST_F(RdbStoreSubTest, RdbStoreSubscribeCloudDetail, TestSize.Level1) { EXPECT_NE(store, nullptr) << "store is nullptr"; @@ -157,12 +159,12 @@ HWTEST_F(RdbStoreSubTest, RdbStoreSubscribeCloudDetail, TestSize.Level1) } /** - * @tc.name: RdbStoreSubscribeCloudDetail - * @tc.desc: RdbStoreSubscribe - * @tc.type: FUNC - * @tc.require: - * @tc.author: - */ +* @tc.name: RdbStoreSubscribeCloudDetail +* @tc.desc: RdbStoreSubscribe +* @tc.type: FUNC +* @tc.require: +* @tc.author: +*/ HWTEST_F(RdbStoreSubTest, Sync, TestSize.Level1) { EXPECT_NE(store, nullptr) << "store is nullptr"; @@ -170,8 +172,6 @@ HWTEST_F(RdbStoreSubTest, Sync, TestSize.Level1) option.mode = TIME_FIRST; option.isBlock = true; Details details; - auto status = store->Sync(option, {}, [&details](Details &&result) { - details = std::move(result); - }); + auto status = store->Sync(option, {}, [&details](Details &&result) { details = std::move(result); }); EXPECT_EQ(status, E_OK); } \ No newline at end of file