From c05e2d0cf5a140497e1369db59ed3c7fc705533f Mon Sep 17 00:00:00 2001 From: Axi_Beft Date: Wed, 26 Mar 2025 11:05:21 +0800 Subject: [PATCH 1/2] object cppCheck fix Signed-off-by: Axi_Beft --- bundle.json | 1 + .../app/src/kvstore_data_service.cpp | 3 ++ .../service/data_share/BUILD.gn | 2 ++ .../data_share/data_share_service_impl.cpp | 29 ++++++++++++++---- .../data_share/data_share_service_impl.h | 1 + .../data_share/data_share_service_stub.cpp | 30 ++++++++++++++++++- .../data_share/data_share_service_stub.h | 1 + .../object/src/object_asset_machine.cpp | 8 ++--- .../service/object/src/object_manager.cpp | 4 +-- .../service/test/BUILD.gn | 2 ++ .../datashareservicestub_fuzzer/BUILD.gn | 2 ++ 11 files changed, 71 insertions(+), 12 deletions(-) diff --git a/bundle.json b/bundle.json index b1a8472db..e80707c82 100644 --- a/bundle.json +++ b/bundle.json @@ -81,6 +81,7 @@ "napi", "netmanager_base", "os_account", + "qos_manager", "relational_store", "resource_management", "safwk", diff --git a/services/distributeddataservice/app/src/kvstore_data_service.cpp b/services/distributeddataservice/app/src/kvstore_data_service.cpp index 8d732f7d0..5b034427d 100755 --- a/services/distributeddataservice/app/src/kvstore_data_service.cpp +++ b/services/distributeddataservice/app/src/kvstore_data_service.cpp @@ -319,6 +319,9 @@ void KvStoreDataService::OnStart() } AddSystemAbilityListener(COMMON_EVENT_SERVICE_ID); AddSystemAbilityListener(MEMORY_MANAGER_SA_ID); + AddSystemAbilityListener(COMM_NET_CONN_MANAGER_SYS_ABILITY_ID); + AddSystemAbilityListener(SUBSYS_ACCOUNT_SYS_ABILITY_ID_BEGIN); + AddSystemAbilityListener(CONCURRENT_TASK_SERVICE_ID); RegisterStoreInfo(); Handler handlerStoreInfo = std::bind(&KvStoreDataService::DumpStoreInfo, this, std::placeholders::_1, std::placeholders::_2); diff --git a/services/distributeddataservice/service/data_share/BUILD.gn b/services/distributeddataservice/service/data_share/BUILD.gn index 5f435aa5e..eaf4be146 100644 --- a/services/distributeddataservice/service/data_share/BUILD.gn +++ b/services/distributeddataservice/service/data_share/BUILD.gn @@ -130,6 +130,8 @@ ohos_source_set("data_share_service") { "json:nlohmann_json_static", "kv_store:datamgr_common", "kv_store:distributeddb", + "qos_manager:concurrent_task_client", + "qos_manager:qos", "relational_store:native_rdb", "relational_store:rdb_data_share_adapter", "samgr:samgr_proxy", 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 a837f76f9..c946063c3 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp @@ -24,6 +24,7 @@ #include "app_connect_manager.h" #include "common_event_manager.h" #include "common_event_support.h" +#include "concurrent_task_client.h" #include "data_ability_observer_interface.h" #include "data_share_profile_config.h" #include "dataobs_mgr_client.h" @@ -83,11 +84,17 @@ public: void DataShareServiceImpl::SystemAbilityStatusChangeListener::OnAddSystemAbility( int32_t systemAbilityId, const std::string &deviceId) { - if (systemAbilityId != COMMON_EVENT_SERVICE_ID) { - return; - } - ZLOGI("Common event service start. saId:%{public}d", systemAbilityId); - InitSubEvent(); + ZLOGI("saId:%{public}d", systemAbilityId); + if (systemAbilityId == COMMON_EVENT_SERVICE_ID) { + InitSubEvent(); + } else if (systemAbilityId == CONCURRENT_TASK_SERVICE_ID) { + std::unordered_map payload; + // get current thread pid + payload["pid"] = std::to_string(getpid()); + // request qos auth for current pid + OHOS::ConcurrentTask::ConcurrentTaskClient::GetInstance().RequestAuth(payload); + } + return; } DataShareServiceImpl::Factory::Factory() @@ -589,6 +596,7 @@ int32_t DataShareServiceImpl::OnBind(const BindInfo &binderInfo) DBDelegate::SetExecutorPool(binderInfo.executors); HiViewAdapter::GetInstance().SetThreadPool(binderInfo.executors); SubscribeCommonEvent(); + SubscribeConcurrentTask(); SubscribeTimeChanged(); SubscribeChange(); ZLOGI("end"); @@ -606,6 +614,17 @@ void DataShareServiceImpl::SubscribeCommonEvent() systemManager->SubscribeSystemAbility(COMMON_EVENT_SERVICE_ID, callback); } +void DataShareServiceImpl::SubscribeConcurrentTask() +{ + sptr systemManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (systemManager == nullptr) { + ZLOGE("System mgr is nullptr"); + return; + } + sptr callback(new SystemAbilityStatusChangeListener()); + systemManager->SubscribeSystemAbility(CONCURRENT_TASK_SERVICE_ID, callback); +} + void DataShareServiceImpl::SubscribeChange() { EventCenter::GetInstance().Subscribe(RemoteChangeEvent::RDB_META_SAVE, [this](const Event &event) { diff --git a/services/distributeddataservice/service/data_share/data_share_service_impl.h b/services/distributeddataservice/service/data_share/data_share_service_impl.h index e4d0a7d9d..1b7e57ba6 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.h +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.h @@ -125,6 +125,7 @@ private: std::pair GetCallerInfo(std::string &bundleName, int32_t &appIndex); int32_t GetBMSAndMetaDataStatus(const std::string &uri, const int32_t tokenId); void SubscribeCommonEvent(); + void SubscribeConcurrentTask(); static void InitSubEvent(); void AutoLaunch(const DistributedData::Event &event); void SubscribeChange(); 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 229afde95..24fdc3d03 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_stub.cpp +++ b/services/distributeddataservice/service/data_share/data_share_service_stub.cpp @@ -25,10 +25,25 @@ #include "ishared_result_set.h" #include "itypes_util.h" #include "log_print.h" +#include "qos.h" #include "utils/anonymous.h" namespace OHOS { namespace DataShare { + +class DataShareServiceStub::QosManager { +public: + QosManager() + { + // set thread qos QOS_USER_INTERACTIVE + QOS::SetThreadQos(QOS::QosLevel::QOS_USER_INTERACTIVE); + } + ~QosManager() + { + QOS::ResetThreadQos(); + } +}; + bool DataShareServiceStub::CheckInterfaceToken(MessageParcel &data) { auto localDescriptor = IDataShareService::GetDescriptor(); @@ -51,6 +66,8 @@ int32_t DataShareServiceStub::OnInsertEx(MessageParcel &data, MessageParcel &rep return IPC_STUB_INVALID_DATA_ERR; } auto [errCode, status] = InsertEx(uri, extUri, bucket); + ZLOGI("Insert uri:%{public}s, errCode:%{public}x, status:%{public}x", + DistributedData::Anonymous::Change(uri).c_str(), errCode, status); if (!ITypesUtil::Marshal(reply, errCode, status)) { ZLOGE("Marshal errCode: 0x%{public}x, status: 0x%{public}x", errCode, status); return IPC_STUB_WRITE_PARCEL_ERR; @@ -70,6 +87,8 @@ int32_t DataShareServiceStub::OnUpdateEx(MessageParcel &data, MessageParcel &rep return IPC_STUB_INVALID_DATA_ERR; } auto [errCode, status] = UpdateEx(uri, extUri, predicate, bucket); + ZLOGI("Update uri:%{public}s, errCode:%{public}x, status:%{public}x", + DistributedData::Anonymous::Change(uri).c_str(), errCode, status); if (!ITypesUtil::Marshal(reply, errCode, status)) { ZLOGE("Marshal errCode: 0x%{public}x, status: 0x%{public}x", errCode, status); return IPC_STUB_WRITE_PARCEL_ERR; @@ -87,6 +106,8 @@ int32_t DataShareServiceStub::OnDeleteEx(MessageParcel &data, MessageParcel &rep return IPC_STUB_INVALID_DATA_ERR; } auto [errCode, status] = DeleteEx(uri, extUri, predicate); + ZLOGI("Delete uri:%{public}s, errCode:%{public}x, status:%{public}x", + DistributedData::Anonymous::Change(uri).c_str(), errCode, status); if (!ITypesUtil::Marshal(reply, errCode, status)) { ZLOGE("Marshal errCode: 0x%{public}x, status: 0x%{public}x", errCode, status); return IPC_STUB_WRITE_PARCEL_ERR; @@ -327,6 +348,12 @@ int32_t DataShareServiceStub::OnNotifyConnectDone(MessageParcel &data, MessagePa int DataShareServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply) { + // set thread qos + DataShareServiceStub::QosManager qos; + // check thread qos + QOS::QosLevel curLevel; + int qosRet = QOS::GetThreadQos(curLevel); + int tryTimes = TRY_TIMES; while (!isReady_.load() && tryTimes > 0) { tryTimes--; @@ -334,7 +361,8 @@ int DataShareServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, Me } auto callingPid = IPCSkeleton::GetCallingPid(); 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); + ZLOGI("code:%{public}u, callingPid:%{public}d, qosRet:%{public}d, curLevel:%{public}d", + code, callingPid, qosRet, curLevel); } if (!CheckInterfaceToken(data)) { return DATA_SHARE_ERROR; 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 d13b20993..47603e959 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_stub.h +++ b/services/distributeddataservice/service/data_share/data_share_service_stub.h @@ -27,6 +27,7 @@ public: void SetServiceReady(); private: + class QosManager; static constexpr std::chrono::milliseconds TIME_THRESHOLD = std::chrono::milliseconds(500); static bool CheckInterfaceToken(MessageParcel& data); int32_t OnQuery(MessageParcel& data, MessageParcel& reply); diff --git a/services/distributeddataservice/service/object/src/object_asset_machine.cpp b/services/distributeddataservice/service/object/src/object_asset_machine.cpp index dcb034ad9..6d1d11fb7 100644 --- a/services/distributeddataservice/service/object/src/object_asset_machine.cpp +++ b/services/distributeddataservice/service/object/src/object_asset_machine.cpp @@ -57,12 +57,12 @@ static int32_t Recover(int32_t eventId, ChangedAssetInfo& changedAsset, Asset& a static int32_t UpdateStore(ChangedAssetInfo& changedAsset); -static AutoCache::Store GetStore(ChangedAssetInfo& changedAsset); +static AutoCache::Store GetStore(const ChangedAssetInfo& changedAsset); static VBuckets GetMigratedData(AutoCache::Store& store, AssetBindInfo& assetBindInfo, const Asset& newAsset); static void MergeAssetData(VBucket& record, const Asset& newAsset, const AssetBindInfo& assetBindInfo); static void MergeAsset(Asset& oldAsset, const Asset& newAsset); static std::string BuildSql(const AssetBindInfo& bindInfo, Values& args); -static BindEvent::BindEventInfo MakeBindInfo(ChangedAssetInfo& changedAsset); +static BindEvent::BindEventInfo MakeBindInfo(const ChangedAssetInfo& changedAsset); static const DFAAction AssetDFA[STATUS_BUTT][EVENT_BUTT] = { { @@ -287,7 +287,7 @@ static void MergeAsset(Asset& oldAsset, const Asset& newAsset) oldAsset.path = newAsset.path; } -static AutoCache::Store GetStore(ChangedAssetInfo& changedAsset) +static AutoCache::Store GetStore(const ChangedAssetInfo& changedAsset) { StoreMetaData meta; meta.storeId = changedAsset.bindInfo.storeName; @@ -347,7 +347,7 @@ static int32_t Recover(int32_t eventId, ChangedAssetInfo& changedAsset, Asset& a return E_OK; } -static BindEvent::BindEventInfo MakeBindInfo(ChangedAssetInfo& changedAsset) +static BindEvent::BindEventInfo MakeBindInfo(const ChangedAssetInfo& changedAsset) { BindEvent::BindEventInfo bindEventInfo; bindEventInfo.bundleName = changedAsset.storeInfo.bundleName; diff --git a/services/distributeddataservice/service/object/src/object_manager.cpp b/services/distributeddataservice/service/object/src/object_manager.cpp index 3e3c554ff..63f90ce8c 100644 --- a/services/distributeddataservice/service/object/src/object_manager.cpp +++ b/services/distributeddataservice/service/object/src/object_manager.cpp @@ -847,7 +847,7 @@ int32_t ObjectStoreManager::SaveToStore(const std::string &appId, const std::str saveInfoEntry.value = std::vector(saveInfoValue.begin(), saveInfoValue.end()); std::vector entries; entries.emplace_back(saveInfoEntry); - for (auto &item : data) { + for (const auto &item : data) { DistributedDB::Entry entry; std::string key = GetPropertyPrefix(appId, sessionId, toDeviceId) + timestamp + SEPERATOR + item.first; entry.key = std::vector(key.begin(), key.end()); @@ -1110,7 +1110,7 @@ SequenceSyncManager::Result SequenceSyncManager::Process( return ERR_SID_NOT_EXIST; } std::map syncResults; - for (auto &item : results) { + for (const auto &item : results) { syncResults[item.first] = item.second == DistributedDB::DBStatus::OK ? 0 : -1; } seqIdCallbackRelations_[sequenceId](syncResults); diff --git a/services/distributeddataservice/service/test/BUILD.gn b/services/distributeddataservice/service/test/BUILD.gn index 9b359e5aa..31ac44d70 100755 --- a/services/distributeddataservice/service/test/BUILD.gn +++ b/services/distributeddataservice/service/test/BUILD.gn @@ -1053,6 +1053,8 @@ ohos_unittest("DataShareServiceImplTest") { "json:nlohmann_json_static", "kv_store:distributeddata_inner", "kv_store:distributeddb", + "qos_manager:concurrent_task_client", + "qos_manager:qos", "relational_store:native_rdb", "relational_store:rdb_data_share_adapter", "resource_management:global_resmgr", diff --git a/services/distributeddataservice/service/test/fuzztest/datashareservicestub_fuzzer/BUILD.gn b/services/distributeddataservice/service/test/fuzztest/datashareservicestub_fuzzer/BUILD.gn index 67dd09415..d9a46ea9f 100644 --- a/services/distributeddataservice/service/test/fuzztest/datashareservicestub_fuzzer/BUILD.gn +++ b/services/distributeddataservice/service/test/fuzztest/datashareservicestub_fuzzer/BUILD.gn @@ -129,6 +129,8 @@ ohos_fuzztest("DataShareServiceStubFuzzTest") { "ipc:ipc_core", "kv_store:distributeddata_inner", "kv_store:distributeddb", + "qos_manager:concurrent_task_client", + "qos_manager:qos", "relational_store:native_rdb", "relational_store:rdb_data_share_adapter", "resource_management:global_resmgr", -- Gitee From c4601c594daa2544a1fbeb27710de09d538b0a50 Mon Sep 17 00:00:00 2001 From: Axi_Beft Date: Fri, 25 Apr 2025 17:22:07 +0800 Subject: [PATCH 2/2] data_share add qso Signed-off-by: Axi_Beft --- .../app/src/kvstore_data_service.cpp | 1 - .../service/data_share/data_share_service_stub.cpp | 6 ------ .../service/object/src/object_asset_machine.cpp | 8 ++++---- .../service/object/src/object_manager.cpp | 4 ++-- 4 files changed, 6 insertions(+), 13 deletions(-) diff --git a/services/distributeddataservice/app/src/kvstore_data_service.cpp b/services/distributeddataservice/app/src/kvstore_data_service.cpp index 5b034427d..c0a0d2e30 100755 --- a/services/distributeddataservice/app/src/kvstore_data_service.cpp +++ b/services/distributeddataservice/app/src/kvstore_data_service.cpp @@ -320,7 +320,6 @@ void KvStoreDataService::OnStart() AddSystemAbilityListener(COMMON_EVENT_SERVICE_ID); AddSystemAbilityListener(MEMORY_MANAGER_SA_ID); AddSystemAbilityListener(COMM_NET_CONN_MANAGER_SYS_ABILITY_ID); - AddSystemAbilityListener(SUBSYS_ACCOUNT_SYS_ABILITY_ID_BEGIN); AddSystemAbilityListener(CONCURRENT_TASK_SERVICE_ID); RegisterStoreInfo(); Handler handlerStoreInfo = std::bind(&KvStoreDataService::DumpStoreInfo, this, std::placeholders::_1, 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 24fdc3d03..b941e2275 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_stub.cpp +++ b/services/distributeddataservice/service/data_share/data_share_service_stub.cpp @@ -66,8 +66,6 @@ int32_t DataShareServiceStub::OnInsertEx(MessageParcel &data, MessageParcel &rep return IPC_STUB_INVALID_DATA_ERR; } auto [errCode, status] = InsertEx(uri, extUri, bucket); - ZLOGI("Insert uri:%{public}s, errCode:%{public}x, status:%{public}x", - DistributedData::Anonymous::Change(uri).c_str(), errCode, status); if (!ITypesUtil::Marshal(reply, errCode, status)) { ZLOGE("Marshal errCode: 0x%{public}x, status: 0x%{public}x", errCode, status); return IPC_STUB_WRITE_PARCEL_ERR; @@ -87,8 +85,6 @@ int32_t DataShareServiceStub::OnUpdateEx(MessageParcel &data, MessageParcel &rep return IPC_STUB_INVALID_DATA_ERR; } auto [errCode, status] = UpdateEx(uri, extUri, predicate, bucket); - ZLOGI("Update uri:%{public}s, errCode:%{public}x, status:%{public}x", - DistributedData::Anonymous::Change(uri).c_str(), errCode, status); if (!ITypesUtil::Marshal(reply, errCode, status)) { ZLOGE("Marshal errCode: 0x%{public}x, status: 0x%{public}x", errCode, status); return IPC_STUB_WRITE_PARCEL_ERR; @@ -106,8 +102,6 @@ int32_t DataShareServiceStub::OnDeleteEx(MessageParcel &data, MessageParcel &rep return IPC_STUB_INVALID_DATA_ERR; } auto [errCode, status] = DeleteEx(uri, extUri, predicate); - ZLOGI("Delete uri:%{public}s, errCode:%{public}x, status:%{public}x", - DistributedData::Anonymous::Change(uri).c_str(), errCode, status); if (!ITypesUtil::Marshal(reply, errCode, status)) { ZLOGE("Marshal errCode: 0x%{public}x, status: 0x%{public}x", errCode, status); return IPC_STUB_WRITE_PARCEL_ERR; diff --git a/services/distributeddataservice/service/object/src/object_asset_machine.cpp b/services/distributeddataservice/service/object/src/object_asset_machine.cpp index 6d1d11fb7..dcb034ad9 100644 --- a/services/distributeddataservice/service/object/src/object_asset_machine.cpp +++ b/services/distributeddataservice/service/object/src/object_asset_machine.cpp @@ -57,12 +57,12 @@ static int32_t Recover(int32_t eventId, ChangedAssetInfo& changedAsset, Asset& a static int32_t UpdateStore(ChangedAssetInfo& changedAsset); -static AutoCache::Store GetStore(const ChangedAssetInfo& changedAsset); +static AutoCache::Store GetStore(ChangedAssetInfo& changedAsset); static VBuckets GetMigratedData(AutoCache::Store& store, AssetBindInfo& assetBindInfo, const Asset& newAsset); static void MergeAssetData(VBucket& record, const Asset& newAsset, const AssetBindInfo& assetBindInfo); static void MergeAsset(Asset& oldAsset, const Asset& newAsset); static std::string BuildSql(const AssetBindInfo& bindInfo, Values& args); -static BindEvent::BindEventInfo MakeBindInfo(const ChangedAssetInfo& changedAsset); +static BindEvent::BindEventInfo MakeBindInfo(ChangedAssetInfo& changedAsset); static const DFAAction AssetDFA[STATUS_BUTT][EVENT_BUTT] = { { @@ -287,7 +287,7 @@ static void MergeAsset(Asset& oldAsset, const Asset& newAsset) oldAsset.path = newAsset.path; } -static AutoCache::Store GetStore(const ChangedAssetInfo& changedAsset) +static AutoCache::Store GetStore(ChangedAssetInfo& changedAsset) { StoreMetaData meta; meta.storeId = changedAsset.bindInfo.storeName; @@ -347,7 +347,7 @@ static int32_t Recover(int32_t eventId, ChangedAssetInfo& changedAsset, Asset& a return E_OK; } -static BindEvent::BindEventInfo MakeBindInfo(const ChangedAssetInfo& changedAsset) +static BindEvent::BindEventInfo MakeBindInfo(ChangedAssetInfo& changedAsset) { BindEvent::BindEventInfo bindEventInfo; bindEventInfo.bundleName = changedAsset.storeInfo.bundleName; diff --git a/services/distributeddataservice/service/object/src/object_manager.cpp b/services/distributeddataservice/service/object/src/object_manager.cpp index 63f90ce8c..3e3c554ff 100644 --- a/services/distributeddataservice/service/object/src/object_manager.cpp +++ b/services/distributeddataservice/service/object/src/object_manager.cpp @@ -847,7 +847,7 @@ int32_t ObjectStoreManager::SaveToStore(const std::string &appId, const std::str saveInfoEntry.value = std::vector(saveInfoValue.begin(), saveInfoValue.end()); std::vector entries; entries.emplace_back(saveInfoEntry); - for (const auto &item : data) { + for (auto &item : data) { DistributedDB::Entry entry; std::string key = GetPropertyPrefix(appId, sessionId, toDeviceId) + timestamp + SEPERATOR + item.first; entry.key = std::vector(key.begin(), key.end()); @@ -1110,7 +1110,7 @@ SequenceSyncManager::Result SequenceSyncManager::Process( return ERR_SID_NOT_EXIST; } std::map syncResults; - for (const auto &item : results) { + for (auto &item : results) { syncResults[item.first] = item.second == DistributedDB::DBStatus::OK ? 0 : -1; } seqIdCallbackRelations_[sequenceId](syncResults); -- Gitee