diff --git a/services/distributeddataservice/service/data_share/common/db_delegate.h b/services/distributeddataservice/service/data_share/common/db_delegate.h index 67bde3ade94818ace61918e5354756df6b303efd..a52ace0ca2381de292c3511fadfb6918713d6c5d 100644 --- a/services/distributeddataservice/service/data_share/common/db_delegate.h +++ b/services/distributeddataservice/service/data_share/common/db_delegate.h @@ -128,8 +128,8 @@ public: static std::shared_ptr GetInstance( bool reInit = false, const std::string &dir = "", const std::shared_ptr &executors = nullptr); virtual ~KvDBDelegate() = default; - virtual int32_t Upsert(const std::string &collectionName, const KvData &value) = 0; - virtual int32_t Delete(const std::string &collectionName, const std::string &filter) = 0; + virtual std::pair Upsert(const std::string &collectionName, const KvData &value) = 0; + virtual std::pair Delete(const std::string &collectionName, const std::string &filter) = 0; virtual int32_t Get(const std::string &collectionName, const Id &id, std::string &value) = 0; virtual int32_t Get(const std::string &collectionName, const std::string &filter, const std::string &projection, std::string &result) = 0; diff --git a/services/distributeddataservice/service/data_share/common/kv_delegate.cpp b/services/distributeddataservice/service/data_share/common/kv_delegate.cpp index 06f8cc6a2f803af9f0b12b1318ff9445ddc3e7ed..be360b40b615c146e1bcbf45acd12be84951b573 100644 --- a/services/distributeddataservice/service/data_share/common/kv_delegate.cpp +++ b/services/distributeddataservice/service/data_share/common/kv_delegate.cpp @@ -40,7 +40,8 @@ const char* g_backupFiles[] = { "dataShare.db.safe", "dataShare.db.undo", }; -const char* BACKUP_SUFFIX = ".backup"; +constexpr const char* BACKUP_SUFFIX = ".backup"; +constexpr std::chrono::milliseconds COPY_TIME_OUT_MS = std::chrono::milliseconds(500); // If isBackUp is true, remove db backup files. Otherwise remove source db files. void KvDelegate::RemoveDbFile(bool isBackUp) const @@ -65,12 +66,15 @@ bool KvDelegate::CopyFile(bool isBackup) std::filesystem::copy_options options = std::filesystem::copy_options::overwrite_existing; std::error_code code; bool ret = true; + int index = 0; for (auto &fileName : g_backupFiles) { std::string src = path_ + "/" + fileName; std::string dst = src; isBackup ? dst.append(BACKUP_SUFFIX) : src.append(BACKUP_SUFFIX); + TimeoutReport timeoutReport({"", "", "", __FUNCTION__, 0}); // If src doesn't exist, error will be returned through `std::error_code` bool copyRet = std::filesystem::copy_file(src, dst, options, code); + timeoutReport.Report(("file index:" + std::to_string(index)), COPY_TIME_OUT_MS); if (!copyRet) { ZLOGE("failed to copy file %{public}s, isBackup %{public}d, err: %{public}s", fileName, isBackup, code.message().c_str()); @@ -78,6 +82,7 @@ bool KvDelegate::CopyFile(bool isBackup) RemoveDbFile(isBackup); break; } + index++; } return ret; } @@ -128,29 +133,30 @@ bool KvDelegate::RestoreIfNeed(int32_t dbStatus) return false; } -int64_t KvDelegate::Upsert(const std::string &collectionName, const std::string &filter, const std::string &value) +std::pair KvDelegate::Upsert(const std::string &collectionName, const std::string &filter, + const std::string &value) { std::lock_guard lock(mutex_); if (!Init()) { ZLOGE("init failed, %{public}s", collectionName.c_str()); - return E_ERROR; + return std::make_pair(E_ERROR, 0); } - int count = GRD_UpsertDoc(db_, collectionName.c_str(), filter.c_str(), value.c_str(), 0); + int32_t count = GRD_UpsertDoc(db_, collectionName.c_str(), filter.c_str(), value.c_str(), 0); if (count <= 0) { ZLOGE("GRD_UpSertDoc failed,status %{public}d", count); RestoreIfNeed(count); - return count; + return std::make_pair(count, 0); } Flush(); - return E_OK; + return std::make_pair(E_OK, count); } -int32_t KvDelegate::Delete(const std::string &collectionName, const std::string &filter) +std::pair KvDelegate::Delete(const std::string &collectionName, const std::string &filter) { std::lock_guard lock(mutex_); if (!Init()) { ZLOGE("init failed, %{public}s", collectionName.c_str()); - return E_ERROR; + return std::make_pair(E_ERROR, 0); } std::vector queryResults; @@ -158,23 +164,25 @@ int32_t KvDelegate::Delete(const std::string &collectionName, const std::string if (status != E_OK) { ZLOGE("db GetBatch failed, %{public}s %{public}d", filter.c_str(), status); // `GetBatch` should decide whether to restore before errors are returned, so skip restoration here. - return status; + return std::make_pair(status, 0); } + int32_t deleteCount = 0; for (auto &result : queryResults) { auto count = GRD_DeleteDoc(db_, collectionName.c_str(), result.c_str(), 0); if (count < 0) { ZLOGE("GRD_DeleteDoc failed,status %{public}d %{public}s", count, result.c_str()); if (RestoreIfNeed(count)) { - return count; + return std::make_pair(count, 0); } continue; } + deleteCount += count; } Flush(); if (queryResults.size() > 0) { ZLOGI("Delete, %{public}s, count %{public}zu", collectionName.c_str(), queryResults.size()); } - return E_OK; + return std::make_pair(E_OK, deleteCount); } bool KvDelegate::Init() @@ -232,7 +240,7 @@ KvDelegate::~KvDelegate() } } -int32_t KvDelegate::Upsert(const std::string &collectionName, const KvData &value) +std::pair KvDelegate::Upsert(const std::string &collectionName, const KvData &value) { std::string id = value.GetId(); if (value.HasVersion() && value.GetVersion() != 0) { @@ -241,7 +249,7 @@ int32_t KvDelegate::Upsert(const std::string &collectionName, const KvData &valu if (value.GetVersion() <= version) { ZLOGE("GetVersion failed,%{public}s id %{private}s %{public}d %{public}d", collectionName.c_str(), id.c_str(), value.GetVersion(), version); - return E_VERSION_NOT_NEWER; + return std::make_pair(E_VERSION_NOT_NEWER, 0); } } } diff --git a/services/distributeddataservice/service/data_share/common/kv_delegate.h b/services/distributeddataservice/service/data_share/common/kv_delegate.h index 3ec92c7cdf01e3fb8c1c79dda4c4bf859e1541f2..fce4ecf31a44784043a05c323ff0e5084f8e7024 100644 --- a/services/distributeddataservice/service/data_share/common/kv_delegate.h +++ b/services/distributeddataservice/service/data_share/common/kv_delegate.h @@ -28,8 +28,8 @@ class KvDelegate final : public KvDBDelegate { public: KvDelegate(const std::string &path, const std::shared_ptr &executors); ~KvDelegate() override; - int32_t Upsert(const std::string &collectionName, const KvData &value) override; - int32_t Delete(const std::string &collectionName, const std::string &filter) override; + std::pair Upsert(const std::string &collectionName, const KvData &value) override; + std::pair Delete(const std::string &collectionName, const std::string &filter) override; int32_t Get(const std::string &collectionName, const Id &id, std::string &value) override; int32_t Get(const std::string &collectionName, const std::string &filter, const std::string &projection, @@ -41,7 +41,8 @@ public: private: bool Init(); bool GetVersion(const std::string &collectionName, const std::string &filter, int &version); - int64_t Upsert(const std::string &collectionName, const std::string &filter, const std::string &value); + std::pair Upsert(const std::string &collectionName, const std::string &filter, + const std::string &value); void Flush(); bool RestoreIfNeed(int32_t dbStatus); void Backup(); diff --git a/services/distributeddataservice/service/data_share/common/rdb_delegate.cpp b/services/distributeddataservice/service/data_share/common/rdb_delegate.cpp index 9ccf692579bc545f9a899c70bb0c85685d202a39..1a55c0d1b18ed02d072ae6f5d0f64d05fcbb2cf7 100644 --- a/services/distributeddataservice/service/data_share/common/rdb_delegate.cpp +++ b/services/distributeddataservice/service/data_share/common/rdb_delegate.cpp @@ -341,7 +341,7 @@ bool RdbDelegate::IsLimit(int count, int32_t callingPid, uint32_t callingTokenId }); ZLOGE("resultSetCount is full, pid: %{public}d, owner is %{public}s", callingPid, logStr.c_str()); std::string appendix = "callingName:" + HiViewFaultAdapter::GetCallingName(callingTokenId).first; - DataShareFaultInfo faultInfo{RESULTSET_FULL, "callingTokenId:" + std::to_string(callingTokenId), + DataShareFaultInfo faultInfo{HiViewFaultAdapter::resultsetFull, "callingTokenId:" + std::to_string(callingTokenId), "Pid:" + std::to_string(callingPid), "owner:" + logStr, __FUNCTION__, E_RESULTSET_BUSY, appendix}; HiViewFaultAdapter::ReportDataFault(faultInfo); return true; diff --git a/services/distributeddataservice/service/data_share/data/published_data.cpp b/services/distributeddataservice/service/data_share/data/published_data.cpp index 894a8e58346f1623103f86b440c0b39e123a9596..359db675e1d56fa28cfc87985f2e70c07b0c895d 100644 --- a/services/distributeddataservice/service/data_share/data/published_data.cpp +++ b/services/distributeddataservice/service/data_share/data/published_data.cpp @@ -170,7 +170,7 @@ void PublishedData::Delete(const std::string &bundleName, const int32_t userId) ZLOGE("db open failed"); return; } - int32_t status = delegate->Delete(KvDBDelegate::DATA_TABLE, + auto [status, count] = delegate->Delete(KvDBDelegate::DATA_TABLE, "{\"bundleName\":\"" + bundleName + "\", \"userId\": " + std::to_string(userId) + "}"); if (status != E_OK) { ZLOGE("db Delete failed, %{public}s %{public}d", bundleName.c_str(), status); @@ -209,9 +209,9 @@ void PublishedData::ClearAging() } if (data.timestamp < lastValidTime && PublishedDataSubscriberManager::GetInstance() .GetCount(PublishedDataKey(data.key, data.bundleName, data.subscriberId)) == 0) { - status = delegate->Delete(KvDBDelegate::DATA_TABLE, + auto [errorCode, count] = delegate->Delete(KvDBDelegate::DATA_TABLE, Id(PublishedData::GenId(data.key, data.bundleName, data.subscriberId), data.userId)); - if (status != E_OK) { + if (errorCode != E_OK) { ZLOGE("db Delete failed, %{public}s %{public}s", data.key.c_str(), data.bundleName.c_str()); } agingSize++; @@ -249,8 +249,8 @@ void PublishedData::UpdateTimestamp( return; } data.timestamp = now; - status = delegate->Upsert(KvDBDelegate::DATA_TABLE, PublishedData(data)); - if (status == E_OK) { + auto [errorCode, count] = delegate->Upsert(KvDBDelegate::DATA_TABLE, PublishedData(data)); + if (errorCode == E_OK) { ZLOGI("update timestamp %{private}s", data.key.c_str()); } } diff --git a/services/distributeddataservice/service/data_share/data/template_data.cpp b/services/distributeddataservice/service/data_share/data/template_data.cpp index baf5dc4d5dda77ae2d5773dba7ec7c9410ec25f7..2807844ff08e4fe9ae52d3ce914a9c404467a384 100644 --- a/services/distributeddataservice/service/data_share/data/template_data.cpp +++ b/services/distributeddataservice/service/data_share/data/template_data.cpp @@ -135,13 +135,15 @@ bool TemplateData::Delete(const std::string &bundleName, const int32_t userId) ZLOGE("db open failed"); return false; } - auto status = delegate->Delete(KvDBDelegate::TEMPLATE_TABLE, + auto [status, count] = delegate->Delete(KvDBDelegate::TEMPLATE_TABLE, "{\"bundleName\":\"" + bundleName + "\", \"userId\": " + std::to_string(userId) + "}"); if (status != E_OK) { ZLOGE("db DeleteById failed, %{public}d", status); return false; } - delegate->NotifyBackup(); + if (count > 0) { + delegate->NotifyBackup(); + } return true; } @@ -154,12 +156,14 @@ bool TemplateData::Add(const std::string &uri, const int32_t userId, const std:: return false; } TemplateData data(uri, bundleName, subscriberId, userId, aTemplate); - auto status = delegate->Upsert(KvDBDelegate::TEMPLATE_TABLE, data); + auto [status, count] = delegate->Upsert(KvDBDelegate::TEMPLATE_TABLE, data); if (status != E_OK) { ZLOGE("db Upsert failed, %{public}d", status); return false; } - delegate->NotifyBackup(); + if (count > 0) { + delegate->NotifyBackup(); + } return true; } @@ -171,13 +175,15 @@ bool TemplateData::Delete( ZLOGE("db open failed"); return false; } - auto status = delegate->Delete(KvDBDelegate::TEMPLATE_TABLE, + auto [status, count] = delegate->Delete(KvDBDelegate::TEMPLATE_TABLE, static_cast(Id(TemplateData::GenId(uri, bundleName, subscriberId), userId))); if (status != E_OK) { ZLOGE("db DeleteById failed, %{public}d", status); return false; } - delegate->NotifyBackup(); + if (count > 0) { + delegate->NotifyBackup(); + } return true; } diff --git a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp index a837f76f94fd64a2ad543c4eb976173a5ae91d9b..93f4e572bab29d1984cf14115befeba2c8223f32 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp @@ -1135,7 +1135,7 @@ void DataShareServiceImpl::ReportExcuteFault(uint32_t callingTokenId, DataProvid int32_t errCode, std::string &func) { std::string appendix = "callingName:" + HiViewFaultAdapter::GetCallingName(callingTokenId).first; - DataShareFaultInfo faultInfo = {CURD_FAILED, providerInfo.bundleName, providerInfo.moduleName, + DataShareFaultInfo faultInfo = {HiViewFaultAdapter::curdFailed, providerInfo.bundleName, providerInfo.moduleName, providerInfo.storeName, func, errCode, appendix}; HiViewFaultAdapter::ReportDataFault(faultInfo); } diff --git a/services/distributeddataservice/service/data_share/data_share_service_stub.cpp b/services/distributeddataservice/service/data_share/data_share_service_stub.cpp index 229afde9572d7e6fbe7db80d62848490b6cfdfb6..c7a43a7a6363d5bdf7efebce1b2ce8e20ce98aa1 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_stub.cpp +++ b/services/distributeddataservice/service/data_share/data_share_service_stub.cpp @@ -18,6 +18,8 @@ #include "data_share_service_stub.h" #include +#include "accesstoken_kit.h" +#include "tokenid_kit.h" #include "data_share_obs_proxy.h" #include "hiview_adapter.h" #include "hiview_fault_adapter.h" @@ -325,6 +327,24 @@ int32_t DataShareServiceStub::OnNotifyConnectDone(MessageParcel &data, MessagePa return 0; } +bool DataShareServiceStub::CheckProxyCallingPermission(uint32_t tokenId) +{ + Security::AccessToken::ATokenTypeEnum tokenType = + Security::AccessToken::AccessTokenKit::GetTokenTypeFlag(tokenId); + return (tokenType == Security::AccessToken::ATokenTypeEnum::TOKEN_NATIVE || + tokenType == Security::AccessToken::ATokenTypeEnum::TOKEN_SHELL); +} + +// GetTokenType use tokenId, and IsSystemApp use fullTokenId, these are different +bool DataShareServiceStub::CheckSystemUidCallingPermission(uint32_t tokenId, uint64_t fullTokenId) +{ + if (CheckProxyCallingPermission(tokenId)) { + return true; + } + // IsSystemAppByFullTokenID here is not IPC + return Security::AccessToken::TokenIdKit::IsSystemAppByFullTokenID(fullTokenId); +} + int DataShareServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply) { int tryTimes = TRY_TIMES; @@ -333,6 +353,15 @@ int DataShareServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, Me std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME)); } auto callingPid = IPCSkeleton::GetCallingPid(); + if (code >= DATA_SHARE_CMD_SYSTEM_CODE) { + auto fullTokenId = IPCSkeleton::GetCallingFullTokenID(); + if (!CheckSystemUidCallingPermission(IPCSkeleton::GetCallingTokenID(), fullTokenId)) { + ZLOGE("CheckSystemUidCallingPermission fail, token:%{public}" PRIx64 + ", callingPid:%{public}d, code:%{public}u", fullTokenId, callingPid, code); + return E_NOT_SYSTEM_APP; + } + code = code - DATA_SHARE_CMD_SYSTEM_CODE; + } if (code != DATA_SHARE_SERVICE_CMD_QUERY && code != DATA_SHARE_SERVICE_CMD_GET_SILENT_PROXY_STATUS) { ZLOGI("code:%{public}u, callingPid:%{public}d", code, callingPid); } diff --git a/services/distributeddataservice/service/data_share/data_share_service_stub.h b/services/distributeddataservice/service/data_share/data_share_service_stub.h index d13b2099344894592e4804216ed2b2ef2a231625..8a7653f3f3b0d28d0815d417cf86d3c51d9719f0 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_stub.h +++ b/services/distributeddataservice/service/data_share/data_share_service_stub.h @@ -29,6 +29,8 @@ public: private: static constexpr std::chrono::milliseconds TIME_THRESHOLD = std::chrono::milliseconds(500); static bool CheckInterfaceToken(MessageParcel& data); + bool CheckProxyCallingPermission(uint32_t tokenId); + bool CheckSystemUidCallingPermission(uint32_t tokenId, uint64_t fullTokenId); int32_t OnQuery(MessageParcel& data, MessageParcel& reply); int32_t OnAddTemplate(MessageParcel& data, MessageParcel& reply); int32_t OnDelTemplate(MessageParcel& data, MessageParcel& reply); diff --git a/services/distributeddataservice/service/data_share/dfx/hiview_fault_adapter.cpp b/services/distributeddataservice/service/data_share/dfx/hiview_fault_adapter.cpp index 6f8713521a0b4f483f70526afbd4c6dac0aa73aa..dc8bfbd7b9281095fc4c9c9c03ff36901c821831 100644 --- a/services/distributeddataservice/service/data_share/dfx/hiview_fault_adapter.cpp +++ b/services/distributeddataservice/service/data_share/dfx/hiview_fault_adapter.cpp @@ -86,19 +86,19 @@ std::pair HiViewFaultAdapter::GetCallingName(uint32_t callingT return std::make_pair(callingName, result); } -void TimeoutReport::Report() +void TimeoutReport::Report(const std::string &timeoutAppendix, const std::chrono::milliseconds timeoutms) { auto end = std::chrono::steady_clock::now(); std::chrono::milliseconds duration = std::chrono::duration_cast(end - start); // Used to report DFX timeout faults - if (needFaultReport && duration > DFX_TIME_OUT_MS) { + if (needFaultReport && duration > HiViewFaultAdapter::dfxTimeOutMs) { DFXReport(duration); } // Used to report log timeout - if (duration > TIME_OUT_MS) { + if (duration > timeoutms) { int64_t milliseconds = duration.count(); - ZLOGE("over time when doing %{public}s, cost:%{public}" PRIi64 "ms", dfxInfo.businessType.c_str(), - milliseconds); + ZLOGE("over time when doing %{public}s, %{public}s, cost:%{public}" PRIi64 "ms", + dfxInfo.businessType.c_str(), timeoutAppendix.c_str(), milliseconds); } } @@ -107,11 +107,11 @@ void TimeoutReport::Report(const std::string &user, uint32_t callingPid, int32_t auto end = std::chrono::steady_clock::now(); std::chrono::milliseconds duration = std::chrono::duration_cast(end - start); // Used to report DFX timeout faults - if (needFaultReport && duration > DFX_TIME_OUT_MS) { + if (needFaultReport && duration > HiViewFaultAdapter::dfxTimeOutMs) { DFXReport(duration); } // Used to report log timeout - if (duration > TIME_OUT_MS) { + if (duration > HiViewFaultAdapter::timeOutMs) { int64_t milliseconds = duration.count(); std::string timeoutAppendix = "bundleName: " + dfxInfo.bundleName + ", user: " + user + ", callingPid: " + std::to_string(callingPid); @@ -134,8 +134,8 @@ void TimeoutReport::DFXReport(const std::chrono::milliseconds &duration) int64_t milliseconds = duration.count(); std::string appendix = "callingName:" + HiViewFaultAdapter::GetCallingName(dfxInfo.callingTokenId).first; appendix += ",cost:" + std::to_string(milliseconds) + "ms"; - DataShareFaultInfo faultInfo{TIME_OUT, dfxInfo.bundleName, dfxInfo.moduleName, dfxInfo.storeName, - dfxInfo.businessType, errorCode, appendix}; + DataShareFaultInfo faultInfo{HiViewFaultAdapter::timeOut, dfxInfo.bundleName, dfxInfo.moduleName, + dfxInfo.storeName, dfxInfo.businessType, errorCode, appendix}; HiViewFaultAdapter::ReportDataFault(faultInfo); } } diff --git a/services/distributeddataservice/service/data_share/dfx/hiview_fault_adapter.h b/services/distributeddataservice/service/data_share/dfx/hiview_fault_adapter.h index 00cb42a5873f0e20605ad5d2a2946e706596c554..04a55e0c7e3e0b77b90c8d135fcd33a4732d910b 100644 --- a/services/distributeddataservice/service/data_share/dfx/hiview_fault_adapter.h +++ b/services/distributeddataservice/service/data_share/dfx/hiview_fault_adapter.h @@ -34,6 +34,17 @@ struct DataShareFaultInfo { std::string appendix; }; +class HiViewFaultAdapter { +public: + static constexpr const std::chrono::milliseconds timeOutMs = std::chrono::milliseconds(300); + static constexpr const std::chrono::milliseconds dfxTimeOutMs = std::chrono::milliseconds(2000); + static constexpr const char* timeOut = "TIME_OUT"; + static constexpr const char* resultsetFull = "RESULTSET_FULL"; + static constexpr const char* curdFailed = "CURD_FAILED"; + static void ReportDataFault(const DataShareFaultInfo &faultInfo); + static std::pair GetCallingName(uint32_t callingTokenid); +}; + // TimeoutReport is used for recording the time usage of multiple interfaces; // It can set up a timeout threshold, and when the time usage exceeds this threshold, will print log; // If want to record DFX fault report, need to set needFaultReport to true (default is false); @@ -54,24 +65,12 @@ struct TimeoutReport { explicit TimeoutReport(const DfxInfo &dfxInfo, bool needFaultReport = false) : dfxInfo(dfxInfo), needFaultReport(needFaultReport) {} - void Report(); + void Report(const std::string &timeoutAppendix = "", + const std::chrono::milliseconds timeoutms = HiViewFaultAdapter::timeOutMs); void Report(const std::string &user, uint32_t callingPid, int32_t appIndex = -1, int32_t instanceId = -1); void DFXReport(const std::chrono::milliseconds &duration); ~TimeoutReport() = default; }; - - -class HiViewFaultAdapter { -public: - static void ReportDataFault(const DataShareFaultInfo &faultInfo); - static std::pair GetCallingName(uint32_t callingTokenid); -}; - -inline const char* TIME_OUT = "TIME_OUT"; -inline const char* RESULTSET_FULL = "RESULTSET_FULL"; -inline const char* CURD_FAILED = "CURD_FAILED"; -inline const std::chrono::milliseconds TIME_OUT_MS = std::chrono::milliseconds(300); -inline const std::chrono::milliseconds DFX_TIME_OUT_MS = std::chrono::milliseconds(2000); } } #endif \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/idata_share_service.h b/services/distributeddataservice/service/data_share/idata_share_service.h index e57489fecdeda12978ad666a1fd1518c064aacc6..54c7213b74d4af3987fee845682e04b4d8d310e0 100644 --- a/services/distributeddataservice/service/data_share/idata_share_service.h +++ b/services/distributeddataservice/service/data_share/idata_share_service.h @@ -29,6 +29,7 @@ namespace OHOS::DataShare { class IDataShareService { public: + static constexpr int DATA_SHARE_CMD_SYSTEM_CODE = 100; enum { DATA_SHARE_SERVICE_CMD_QUERY, DATA_SHARE_SERVICE_CMD_ADD_TEMPLATE, @@ -52,7 +53,30 @@ public: DATA_SHARE_SERVICE_CMD_INSERTEX, DATA_SHARE_SERVICE_CMD_DELETEEX, DATA_SHARE_SERVICE_CMD_UPDATEEX, - DATA_SHARE_SERVICE_CMD_MAX + DATA_SHARE_SERVICE_CMD_MAX, + DATA_SHARE_SERVICE_CMD_QUERY_SYSTEM = DATA_SHARE_CMD_SYSTEM_CODE, + DATA_SHARE_SERVICE_CMD_ADD_TEMPLATE_SYSTEM, + DATA_SHARE_SERVICE_CMD_DEL_TEMPLATE_SYSTEM, + DATA_SHARE_SERVICE_CMD_PUBLISH_SYSTEM, + DATA_SHARE_SERVICE_CMD_GET_DATA_SYSTEM, + DATA_SHARE_SERVICE_CMD_SUBSCRIBE_RDB_SYSTEM, + DATA_SHARE_SERVICE_CMD_UNSUBSCRIBE_RDB_SYSTEM, + DATA_SHARE_SERVICE_CMD_ENABLE_SUBSCRIBE_RDB_SYSTEM, + DATA_SHARE_SERVICE_CMD_DISABLE_SUBSCRIBE_RDB_SYSTEM, + DATA_SHARE_SERVICE_CMD_SUBSCRIBE_PUBLISHED_SYSTEM, + DATA_SHARE_SERVICE_CMD_UNSUBSCRIBE_PUBLISHED_SYSTEM, + DATA_SHARE_SERVICE_CMD_ENABLE_SUBSCRIBE_PUBLISHED_SYSTEM, + DATA_SHARE_SERVICE_CMD_DISABLE_SUBSCRIBE_PUBLISHED_SYSTEM, + DATA_SHARE_SERVICE_CMD_NOTIFY_SYSTEM, + DATA_SHARE_SERVICE_CMD_NOTIFY_OBSERVERS_SYSTEM, + DATA_SHARE_SERVICE_CMD_SET_SILENT_SWITCH_SYSTEM, + DATA_SHARE_SERVICE_CMD_GET_SILENT_PROXY_STATUS_SYSTEM, + DATA_SHARE_SERVICE_CMD_REGISTER_OBSERVER_SYSTEM, + DATA_SHARE_SERVICE_CMD_UNREGISTER_OBSERVER_SYSTEM, + DATA_SHARE_SERVICE_CMD_INSERTEX_SYSTEM, + DATA_SHARE_SERVICE_CMD_DELETEEX_SYSTEM, + DATA_SHARE_SERVICE_CMD_UPDATEEX_SYSTEM, + DATA_SHARE_SERVICE_CMD_MAX_SYSTEM }; enum { DATA_SHARE_ERROR = -1, DATA_SHARE_OK = 0 }; diff --git a/services/distributeddataservice/service/data_share/strategies/publish_strategy.cpp b/services/distributeddataservice/service/data_share/strategies/publish_strategy.cpp index 26b116d48aa72f13b7cd02ef3adaa4d144e59bf7..c2cd252f4ab13b06475bf4182b8ee65c495d6ae6 100644 --- a/services/distributeddataservice/service/data_share/strategies/publish_strategy.cpp +++ b/services/distributeddataservice/service/data_share/strategies/publish_strategy.cpp @@ -45,7 +45,7 @@ int32_t PublishStrategy::Execute(std::shared_ptr context, const Publish PublishedDataNode node(context->uri, context->calledBundleName, item.subscriberId_, context->currentUserId, PublishedDataNode::MoveTo(value)); PublishedData data(node, context->version); - int32_t status = delegate->Upsert(KvDBDelegate::DATA_TABLE, data); + auto [status, count] = delegate->Upsert(KvDBDelegate::DATA_TABLE, data); if (status != E_OK) { ZLOGE("db Upsert failed, %{public}s %{public}s %{public}d", context->calledBundleName.c_str(), DistributedData::Anonymous::Change(context->uri).c_str(), status);