From 77b1ce5fe9a908b182ad858cb936e032de9b2f8d Mon Sep 17 00:00:00 2001 From: htt1997 Date: Wed, 7 May 2025 11:41:39 +0800 Subject: [PATCH 1/3] obtain distributedtable from service Signed-off-by: htt1997 --- .../adapter/bundle_mgr/BUILD.gn | 58 +++++++++++++++++++ .../adapter/bundle_mgr/bundle_mgr_adapter.cpp | 40 +++++++++++++ .../adapter/bundle_mgr/bundle_mgr_adapter.h | 31 ++++++++++ .../service/rdb/BUILD.gn | 1 + .../service/rdb/rdb_service_impl.cpp | 12 +++- .../service/rdb/rdb_service_stub.cpp | 3 +- .../service/test/BUILD.gn | 34 ++--------- 7 files changed, 145 insertions(+), 34 deletions(-) create mode 100644 services/distributeddataservice/adapter/bundle_mgr/BUILD.gn create mode 100644 services/distributeddataservice/adapter/bundle_mgr/bundle_mgr_adapter.cpp create mode 100644 services/distributeddataservice/adapter/bundle_mgr/bundle_mgr_adapter.h diff --git a/services/distributeddataservice/adapter/bundle_mgr/BUILD.gn b/services/distributeddataservice/adapter/bundle_mgr/BUILD.gn new file mode 100644 index 000000000..3ea018ef3 --- /dev/null +++ b/services/distributeddataservice/adapter/bundle_mgr/BUILD.gn @@ -0,0 +1,58 @@ +# Copyright (c) 2025 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. +import("//build/ohos.gni") +import("//foundation/distributeddatamgr/datamgr_service/datamgr_service.gni") + +config("module_public_config") { + visibility = [ ":*" ] + include_dirs = [ "${data_service_path}/adapter" ] +} + +ohos_source_set("distributeddata_bundle_mgr") { + branch_protector_ret = "pac_ret" + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + boundary_sanitize = true + ubsan = true + } + sources = [] + cflags_cc = [ + "-fvisibility=hidden", + "-Oz", + "-fstack-protector-strong", + ] + + public_configs = [ ":module_public_config" ] + cflags = [ + "-fdata-sections", + "-ffunction-sections", + "-Werror", + "-Wno-multichar", + "-Wno-c99-designator", + "-D_LIBCPP_HAS_COND_CLOCKWAIT", + "-Oz", + "-fstack-protector-strong", + ] + + external_deps = [ "kv_store:datamgr_common" ] + sources += [ "bundle_mgr_adapter.cpp" ] + external_deps += [ + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "hilog:libhilog", + ] + subsystem_name = "distributeddatamgr" + part_name = "datamgr_service" +} diff --git a/services/distributeddataservice/adapter/bundle_mgr/bundle_mgr_adapter.cpp b/services/distributeddataservice/adapter/bundle_mgr/bundle_mgr_adapter.cpp new file mode 100644 index 000000000..8e2340f58 --- /dev/null +++ b/services/distributeddataservice/adapter/bundle_mgr/bundle_mgr_adapter.cpp @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2025 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. + */ + +#define LOG_TAG "bundle_mgr_adapter" +#include "bundle_mgr/bundle_mgr_adapter.h" +#include "bundle_mgr_client.h" +#include "log_print.h" +using namespace OHOS::AppExecFwk; +namespace OHOS::DistributedData { + +BundleMgrAdapter &BundleMgrAdapter::GetInstance() +{ + static BundleMgrAdapter instance; + return instance; +} + +std::string BundleMgrAdapter::GetBundleName(int32_t uid) +{ + BundleMgrClient client; + std::string bundleName; + auto code = client.GetNameForUid(uid, bundleName); + if (code != 0) { + ZLOGE("failed. uid:%{public}d, code:%{public}d", uid, code); + return ""; + } + return bundleName; +} +} // namespace OHOS::DistributedData \ No newline at end of file diff --git a/services/distributeddataservice/adapter/bundle_mgr/bundle_mgr_adapter.h b/services/distributeddataservice/adapter/bundle_mgr/bundle_mgr_adapter.h new file mode 100644 index 000000000..e955a6fba --- /dev/null +++ b/services/distributeddataservice/adapter/bundle_mgr/bundle_mgr_adapter.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2025 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. + */ +#ifndef DISTRIBUTEDDATAMGR_DATAMGR_BUNDLE_MANAGER_ADAPTER_H +#define DISTRIBUTEDDATAMGR_DATAMGR_BUNDLE_MANAGER_ADAPTER_H + +#include +#include +#include "visibility.h" + +namespace OHOS { +namespace DistributedData { +class API_EXPORT BundleMgrAdapter { +public: + static BundleMgrAdapter &GetInstance(); + std::string GetBundleName(int32_t uid); +}; +} // namespace DistributedData +} // namespace OHOS +#endif //DISTRIBUTEDDATAMGR_DATAMGR_BUNDLE_MANAGER_ADAPTER_H diff --git a/services/distributeddataservice/service/rdb/BUILD.gn b/services/distributeddataservice/service/rdb/BUILD.gn index ad693d92d..9692c996e 100644 --- a/services/distributeddataservice/service/rdb/BUILD.gn +++ b/services/distributeddataservice/service/rdb/BUILD.gn @@ -67,6 +67,7 @@ ohos_source_set("distributeddata_rdb") { ] deps = [ + "${data_service_path}/adapter/bundle_mgr:distributeddata_bundle_mgr", "${data_service_path}/service/bootstrap:distributeddata_bootstrap", "${data_service_path}/service/common:distributeddata_common", "${data_service_path}/service/crypto:distributeddata_crypto", diff --git a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp index 61bff0d76..1403d3c1f 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp +++ b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp @@ -18,6 +18,7 @@ #include "abs_rdb_predicates.h" #include "accesstoken_kit.h" #include "account/account_delegate.h" +#include "bundle_mgr/bundle_mgr_adapter.h" #include "changeevent/remote_change_event.h" #include "checker/checker_manager.h" #include "cloud/change_event.h" @@ -233,10 +234,15 @@ bool RdbServiceImpl::CheckAccess(const std::string& bundleName, const std::strin std::string RdbServiceImpl::ObtainDistributedTableName(const std::string &device, const std::string &table) { - ZLOGI("device=%{public}s table=%{public}s", Anonymous::Change(device).c_str(), table.c_str()); - auto uuid = DmAdapter::GetInstance().GetUuidByNetworkId(device); + ZLOGI("device=%{public}s table=%{public}s", Anonymous::Change(device).c_str(), Anonymous::Change(table).c_str()); + auto uid = IPCSkeleton::GetCallingUid(); + auto bundleName = BundleMgrAdapter::GetInstance().GetBundleName(uid); + auto tokenId = IPCSkeleton::GetCallingTokenID(); + auto appId = CheckerManager::GetInstance().GetAppId({ uid, tokenId, bundleName }); + auto uuid = DmAdapter::GetInstance().CalcClientUuid(appId, DmAdapter::GetInstance().ToUUID(device)); if (uuid.empty()) { - ZLOGE("get uuid failed"); + ZLOGE("get uuid failed, bundle:%{public}s, deviceId:%{public}s, table:%{public}s", bundleName.c_str(), + Anonymous::Change(device).c_str(), Anonymous::Change(table).c_str()); return ""; } return DistributedDB::RelationalStoreManager::GetDistributedTableName(uuid, table); diff --git a/services/distributeddataservice/service/rdb/rdb_service_stub.cpp b/services/distributeddataservice/service/rdb/rdb_service_stub.cpp index 737b216bb..fd7ee6ee4 100755 --- a/services/distributeddataservice/service/rdb/rdb_service_stub.cpp +++ b/services/distributeddataservice/service/rdb/rdb_service_stub.cpp @@ -36,7 +36,8 @@ int32_t RdbServiceStub::OnRemoteObtainDistributedTableName(MessageParcel &data, } std::string distributedTableName = ObtainDistributedTableName(device, table); - if (!ITypesUtil::Marshal(reply, distributedTableName)) { + int32_t status = distributedTableName.empty() ? RDB_ERROR : RDB_OK; + if (!ITypesUtil::Marshal(reply, status, distributedTableName)) { ZLOGE("Marshal distributedTableName:%{public}s", distributedTableName.c_str()); return IPC_STUB_WRITE_PARCEL_ERR; } diff --git a/services/distributeddataservice/service/test/BUILD.gn b/services/distributeddataservice/service/test/BUILD.gn index b2f90d849..93d041ccf 100755 --- a/services/distributeddataservice/service/test/BUILD.gn +++ b/services/distributeddataservice/service/test/BUILD.gn @@ -96,20 +96,6 @@ ohos_unittest("CloudDataTest") { "${data_service_path}/service/matrix/src/matrix_event.cpp", "${data_service_path}/service/permission/src/permission_validator.cpp", "${data_service_path}/service/permission/src/permit_delegate.cpp", - "${data_service_path}/service/rdb/cache_cursor.cpp", - "${data_service_path}/service/rdb/rdb_asset_loader.cpp", - "${data_service_path}/service/rdb/rdb_cloud.cpp", - "${data_service_path}/service/rdb/rdb_cursor.cpp", - "${data_service_path}/service/rdb/rdb_general_store.cpp", - "${data_service_path}/service/rdb/rdb_hiview_adapter.cpp", - "${data_service_path}/service/rdb/rdb_notifier_proxy.cpp", - "${data_service_path}/service/rdb/rdb_query.cpp", - "${data_service_path}/service/rdb/rdb_result_set_impl.cpp", - "${data_service_path}/service/rdb/rdb_result_set_stub.cpp", - "${data_service_path}/service/rdb/rdb_schema_config.cpp", - "${data_service_path}/service/rdb/rdb_service_impl.cpp", - "${data_service_path}/service/rdb/rdb_service_stub.cpp", - "${data_service_path}/service/rdb/rdb_watcher.cpp", "${data_service_path}/service/test/mock/checker_mock.cpp", "cloud_data_test.cpp", ] @@ -143,7 +129,8 @@ ohos_unittest("CloudDataTest") { "${data_service_path}/adapter/account:distributeddata_account", "${data_service_path}/adapter/communicator:distributeddata_communicator", "${data_service_path}/adapter/schema_helper:distributeddata_schema_helper", - "../../framework:distributeddatasvcfwk", + "${data_service_path}/service/rdb:distributeddata_rdb", + "${data_service_path}/framework:distributeddatasvcfwk", "mock:distributeddata_mock_static", "//third_party/googletest:gtest_main", ] @@ -192,20 +179,6 @@ ohos_unittest("CloudServiceImplTest") { "${data_service_path}/service/matrix/src/matrix_event.cpp", "${data_service_path}/service/permission/src/permission_validator.cpp", "${data_service_path}/service/permission/src/permit_delegate.cpp", - "${data_service_path}/service/rdb/cache_cursor.cpp", - "${data_service_path}/service/rdb/rdb_asset_loader.cpp", - "${data_service_path}/service/rdb/rdb_cloud.cpp", - "${data_service_path}/service/rdb/rdb_cursor.cpp", - "${data_service_path}/service/rdb/rdb_general_store.cpp", - "${data_service_path}/service/rdb/rdb_hiview_adapter.cpp", - "${data_service_path}/service/rdb/rdb_notifier_proxy.cpp", - "${data_service_path}/service/rdb/rdb_query.cpp", - "${data_service_path}/service/rdb/rdb_result_set_impl.cpp", - "${data_service_path}/service/rdb/rdb_result_set_stub.cpp", - "${data_service_path}/service/rdb/rdb_schema_config.cpp", - "${data_service_path}/service/rdb/rdb_service_impl.cpp", - "${data_service_path}/service/rdb/rdb_service_stub.cpp", - "${data_service_path}/service/rdb/rdb_watcher.cpp", "${data_service_path}/service/test/mock/checker_mock.cpp", "cloud_service_impl_test.cpp", ] @@ -239,7 +212,8 @@ ohos_unittest("CloudServiceImplTest") { "${data_service_path}/adapter/account:distributeddata_account", "${data_service_path}/adapter/communicator:distributeddata_communicator", "${data_service_path}/adapter/schema_helper:distributeddata_schema_helper", - "../../framework:distributeddatasvcfwk", + "${data_service_path}/service/rdb:distributeddata_rdb", + "${data_service_path}/framework:distributeddatasvcfwk", "mock:distributeddata_mock_static", "//third_party/googletest:gtest_main", ] -- Gitee From 21e56f013627d73a41244625ff9e1b22b9585037 Mon Sep 17 00:00:00 2001 From: htt1997 Date: Wed, 7 May 2025 16:38:11 +0800 Subject: [PATCH 2/3] add ut Signed-off-by: htt1997 --- .../adapter/bundle_mgr/BUILD.gn | 3 +- .../adapter/bundle_mgr/bundle_mgr_adapter.cpp | 2 +- .../adapter/bundle_mgr/test/BUILD.gn | 42 ++++++++++ .../bundle_mgr/test/bundle_mgr_test.cpp | 45 +++++++++++ .../adapter/test/BUILD.gn | 6 +- .../service/rdb/rdb_service_impl.cpp | 5 +- .../service/test/BUILD.gn | 77 ++----------------- .../fuzztest/cloudservicestub_fuzzer/BUILD.gn | 51 ++---------- .../fuzztest/rdbservicestub_fuzzer/BUILD.gn | 37 ++------- 9 files changed, 116 insertions(+), 152 deletions(-) create mode 100644 services/distributeddataservice/adapter/bundle_mgr/test/BUILD.gn create mode 100644 services/distributeddataservice/adapter/bundle_mgr/test/bundle_mgr_test.cpp diff --git a/services/distributeddataservice/adapter/bundle_mgr/BUILD.gn b/services/distributeddataservice/adapter/bundle_mgr/BUILD.gn index 3ea018ef3..7ca4db4f9 100644 --- a/services/distributeddataservice/adapter/bundle_mgr/BUILD.gn +++ b/services/distributeddataservice/adapter/bundle_mgr/BUILD.gn @@ -27,7 +27,7 @@ ohos_source_set("distributeddata_bundle_mgr") { boundary_sanitize = true ubsan = true } - sources = [] + sources = [ "bundle_mgr_adapter.cpp" ] cflags_cc = [ "-fvisibility=hidden", "-Oz", @@ -47,7 +47,6 @@ ohos_source_set("distributeddata_bundle_mgr") { ] external_deps = [ "kv_store:datamgr_common" ] - sources += [ "bundle_mgr_adapter.cpp" ] external_deps += [ "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", diff --git a/services/distributeddataservice/adapter/bundle_mgr/bundle_mgr_adapter.cpp b/services/distributeddataservice/adapter/bundle_mgr/bundle_mgr_adapter.cpp index 8e2340f58..efd9d203a 100644 --- a/services/distributeddataservice/adapter/bundle_mgr/bundle_mgr_adapter.cpp +++ b/services/distributeddataservice/adapter/bundle_mgr/bundle_mgr_adapter.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#define LOG_TAG "bundle_mgr_adapter" +#define LOG_TAG "BundleMgrAdapter" #include "bundle_mgr/bundle_mgr_adapter.h" #include "bundle_mgr_client.h" #include "log_print.h" diff --git a/services/distributeddataservice/adapter/bundle_mgr/test/BUILD.gn b/services/distributeddataservice/adapter/bundle_mgr/test/BUILD.gn new file mode 100644 index 000000000..193ada6a4 --- /dev/null +++ b/services/distributeddataservice/adapter/bundle_mgr/test/BUILD.gn @@ -0,0 +1,42 @@ +# Copyright (c) 2025 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. +import("//build/test.gni") +import("//foundation/distributeddatamgr/datamgr_service/datamgr_service.gni") +module_output_path = "datamgr_service/datamgr_service/distributeddatafwk" + +############################################################################### +ohos_unittest("BundleMgrTest") { + module_out_path = module_output_path + + sources = [ "bundle_mgr_test.cpp" ] + + cflags = [ "-Werror" ] + deps = [ "${data_service_path}/adapter/bundle_mgr:distributeddata_bundle_mgr" ] + + external_deps = [ + "googletest:gtest_main", + "hilog:libhilog", + "ipc:ipc_core", + "kv_store:datamgr_common", + ] +} + +############################################################################### +group("unittest") { + testonly = true + + deps = [] + + deps += [ ":BundleMgrTest" ] +} +############################################################################### diff --git a/services/distributeddataservice/adapter/bundle_mgr/test/bundle_mgr_test.cpp b/services/distributeddataservice/adapter/bundle_mgr/test/bundle_mgr_test.cpp new file mode 100644 index 000000000..bf5590727 --- /dev/null +++ b/services/distributeddataservice/adapter/bundle_mgr/test/bundle_mgr_test.cpp @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2025 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 "bundle_mgr/bundle_mgr_adapter.h" +#include "ipc_skeleton.h" +namespace { +using namespace OHOS; +using namespace OHOS::DistributedData; +using namespace testing::ext; + +class BundleMgrTest : public testing::Test { +public: + static void SetUpTestCase(void) {} + static void TearDownTestCase(void) {} + void SetUp() {} + void TearDown() {} +}; + +/** +* @tc.name: GetBundleName +* @tc.desc: GetBundleName test +* @tc.type: FUNC +* @tc.require: +* @tc.author: +*/ +HWTEST_F(BundleMgrTest, GetBundleName, TestSize.Level0) +{ + auto bundleName = BundleMgrAdapter::GetInstance().GetBundleName(0); + EXPECT_TRUE(bundleName.empty()); +} +} // namespace \ No newline at end of file diff --git a/services/distributeddataservice/adapter/test/BUILD.gn b/services/distributeddataservice/adapter/test/BUILD.gn index 6f6f3b435..7e5686d14 100755 --- a/services/distributeddataservice/adapter/test/BUILD.gn +++ b/services/distributeddataservice/adapter/test/BUILD.gn @@ -20,11 +20,15 @@ group("unittest") { deps += [ "../account/test:unittest", + "../bundle_mgr/test:unittest", "../communicator/test:unittest", "../dfx/test:unittest", - "../screenlock/test:unittest", ] + if (defined(global_parts_info) && defined(global_parts_info.theme_screenlock_mgr)) { + deps += [ "${data_service_path}/adapter/screenlock/test:unittest" ] + } + if (datamgr_service_cloud) { deps += [ "../network/test:unittest" ] } diff --git a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp index 1403d3c1f..3d5f48302 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp +++ b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp @@ -238,7 +238,10 @@ std::string RdbServiceImpl::ObtainDistributedTableName(const std::string &device auto uid = IPCSkeleton::GetCallingUid(); auto bundleName = BundleMgrAdapter::GetInstance().GetBundleName(uid); auto tokenId = IPCSkeleton::GetCallingTokenID(); - auto appId = CheckerManager::GetInstance().GetAppId({ uid, tokenId, bundleName }); + std::string appId = " "; + if (AccessTokenKit::GetTokenTypeFlag(tokenId) == Security::AccessToken::TOKEN_HAP) { + appId = CheckerManager::GetInstance().GetAppId({ uid, tokenId, bundleName }); + } auto uuid = DmAdapter::GetInstance().CalcClientUuid(appId, DmAdapter::GetInstance().ToUUID(device)); if (uuid.empty()) { ZLOGE("get uuid failed, bundle:%{public}s, deviceId:%{public}s, table:%{public}s", bundleName.c_str(), diff --git a/services/distributeddataservice/service/test/BUILD.gn b/services/distributeddataservice/service/test/BUILD.gn index 93d041ccf..ef922b621 100755 --- a/services/distributeddataservice/service/test/BUILD.gn +++ b/services/distributeddataservice/service/test/BUILD.gn @@ -67,8 +67,6 @@ ohos_unittest("CloudDataTest") { } module_out_path = module_output_path sources = [ - "${data_service_path}/service/backup/src/backup_manager.cpp", - "${data_service_path}/service/bootstrap/src/bootstrap.cpp", "${data_service_path}/service/cloud/cloud_data_translate.cpp", "${data_service_path}/service/cloud/cloud_service_impl.cpp", "${data_service_path}/service/cloud/cloud_service_stub.cpp", @@ -76,26 +74,6 @@ ohos_unittest("CloudDataTest") { "${data_service_path}/service/cloud/cloud_value_util.cpp", "${data_service_path}/service/cloud/sync_manager.cpp", "${data_service_path}/service/cloud/sync_strategies/network_sync_strategy.cpp", - "${data_service_path}/service/common/common_types_utils.cpp", - "${data_service_path}/service/common/value_proxy.cpp", - "${data_service_path}/service/common/xcollie.cpp", - "${data_service_path}/service/config/src/config_factory.cpp", - "${data_service_path}/service/config/src/model/app_id_mapping_config.cpp", - "${data_service_path}/service/config/src/model/backup_config.cpp", - "${data_service_path}/service/config/src/model/checker_config.cpp", - "${data_service_path}/service/config/src/model/cloud_config.cpp", - "${data_service_path}/service/config/src/model/component_config.cpp", - "${data_service_path}/service/config/src/model/directory_config.cpp", - "${data_service_path}/service/config/src/model/global_config.cpp", - "${data_service_path}/service/config/src/model/network_config.cpp", - "${data_service_path}/service/config/src/model/protocol_config.cpp", - "${data_service_path}/service/config/src/model/thread_config.cpp", - "${data_service_path}/service/crypto/src/crypto_manager.cpp", - "${data_service_path}/service/kvdb/user_delegate.cpp", - "${data_service_path}/service/matrix/src/device_matrix.cpp", - "${data_service_path}/service/matrix/src/matrix_event.cpp", - "${data_service_path}/service/permission/src/permission_validator.cpp", - "${data_service_path}/service/permission/src/permit_delegate.cpp", "${data_service_path}/service/test/mock/checker_mock.cpp", "cloud_data_test.cpp", ] @@ -103,32 +81,24 @@ ohos_unittest("CloudDataTest") { configs = [ ":module_private_config" ] external_deps = [ - "ability_base:base", - "ability_base:want", "access_token:libaccesstoken_sdk", "access_token:libtoken_setproc", "access_token:libtokenid_sdk", - "bundle_framework:appexecfwk_base", - "bundle_framework:appexecfwk_core", "c_utils:utils", - "device_manager:devicemanagersdk", "hicollie:libhicollie", - "hilog:libhilog", - "hisysevent:libhisysevent", - "huks:libhukssdk", - "ipc:ipc_core", + "json:nlohmann_json_static", "kv_store:distributeddata_inner", "kv_store:distributeddb", - "netmanager_base:net_conn_manager_if", "relational_store:native_rdb", - "resource_management:global_resmgr", - "samgr:samgr_proxy", ] deps = [ "${data_service_path}/adapter/account:distributeddata_account", "${data_service_path}/adapter/communicator:distributeddata_communicator", + "${data_service_path}/adapter/dfx:distributeddata_dfx", "${data_service_path}/adapter/schema_helper:distributeddata_schema_helper", + "${data_service_path}/service/bootstrap:distributeddata_bootstrap", + "${data_service_path}/service/common:distributeddata_common", "${data_service_path}/service/rdb:distributeddata_rdb", "${data_service_path}/framework:distributeddatasvcfwk", "mock:distributeddata_mock_static", @@ -150,8 +120,6 @@ ohos_unittest("CloudServiceImplTest") { } module_out_path = module_output_path sources = [ - "${data_service_path}/service/backup/src/backup_manager.cpp", - "${data_service_path}/service/bootstrap/src/bootstrap.cpp", "${data_service_path}/service/cloud/cloud_data_translate.cpp", "${data_service_path}/service/cloud/cloud_service_impl.cpp", "${data_service_path}/service/cloud/cloud_service_stub.cpp", @@ -159,26 +127,6 @@ ohos_unittest("CloudServiceImplTest") { "${data_service_path}/service/cloud/cloud_value_util.cpp", "${data_service_path}/service/cloud/sync_manager.cpp", "${data_service_path}/service/cloud/sync_strategies/network_sync_strategy.cpp", - "${data_service_path}/service/common/common_types_utils.cpp", - "${data_service_path}/service/common/value_proxy.cpp", - "${data_service_path}/service/common/xcollie.cpp", - "${data_service_path}/service/config/src/config_factory.cpp", - "${data_service_path}/service/config/src/model/app_id_mapping_config.cpp", - "${data_service_path}/service/config/src/model/backup_config.cpp", - "${data_service_path}/service/config/src/model/checker_config.cpp", - "${data_service_path}/service/config/src/model/cloud_config.cpp", - "${data_service_path}/service/config/src/model/component_config.cpp", - "${data_service_path}/service/config/src/model/directory_config.cpp", - "${data_service_path}/service/config/src/model/global_config.cpp", - "${data_service_path}/service/config/src/model/network_config.cpp", - "${data_service_path}/service/config/src/model/protocol_config.cpp", - "${data_service_path}/service/config/src/model/thread_config.cpp", - "${data_service_path}/service/crypto/src/crypto_manager.cpp", - "${data_service_path}/service/kvdb/user_delegate.cpp", - "${data_service_path}/service/matrix/src/device_matrix.cpp", - "${data_service_path}/service/matrix/src/matrix_event.cpp", - "${data_service_path}/service/permission/src/permission_validator.cpp", - "${data_service_path}/service/permission/src/permit_delegate.cpp", "${data_service_path}/service/test/mock/checker_mock.cpp", "cloud_service_impl_test.cpp", ] @@ -186,32 +134,23 @@ ohos_unittest("CloudServiceImplTest") { configs = [ ":module_private_config" ] external_deps = [ - "ability_base:base", - "ability_base:want", "access_token:libaccesstoken_sdk", "access_token:libtoken_setproc", - "access_token:libtokenid_sdk", - "bundle_framework:appexecfwk_base", - "bundle_framework:appexecfwk_core", "c_utils:utils", - "device_manager:devicemanagersdk", "hicollie:libhicollie", - "hilog:libhilog", - "hisysevent:libhisysevent", - "huks:libhukssdk", - "ipc:ipc_core", + "json:nlohmann_json_static", "kv_store:distributeddata_inner", "kv_store:distributeddb", - "netmanager_base:net_conn_manager_if", "relational_store:native_rdb", - "resource_management:global_resmgr", - "samgr:samgr_proxy", ] deps = [ "${data_service_path}/adapter/account:distributeddata_account", "${data_service_path}/adapter/communicator:distributeddata_communicator", + "${data_service_path}/adapter/dfx:distributeddata_dfx", "${data_service_path}/adapter/schema_helper:distributeddata_schema_helper", + "${data_service_path}/service/bootstrap:distributeddata_bootstrap", + "${data_service_path}/service/common:distributeddata_common", "${data_service_path}/service/rdb:distributeddata_rdb", "${data_service_path}/framework:distributeddatasvcfwk", "mock:distributeddata_mock_static", diff --git a/services/distributeddataservice/service/test/fuzztest/cloudservicestub_fuzzer/BUILD.gn b/services/distributeddataservice/service/test/fuzztest/cloudservicestub_fuzzer/BUILD.gn index 3cb8f10bd..809567f62 100644 --- a/services/distributeddataservice/service/test/fuzztest/cloudservicestub_fuzzer/BUILD.gn +++ b/services/distributeddataservice/service/test/fuzztest/cloudservicestub_fuzzer/BUILD.gn @@ -64,65 +64,24 @@ ohos_fuzztest("CloudServiceStubFuzzTest") { sources = [ "${data_service_path}/app/src/checker/bundle_checker.cpp", "${data_service_path}/app/src/checker/system_checker.cpp", - "${data_service_path}/service/backup/src/backup_manager.cpp", - "${data_service_path}/service/bootstrap/src/bootstrap.cpp", - "${data_service_path}/service/cloud/cloud_data_translate.cpp", - "${data_service_path}/service/cloud/cloud_service_impl.cpp", - "${data_service_path}/service/cloud/cloud_service_stub.cpp", - "${data_service_path}/service/cloud/cloud_types_util.cpp", - "${data_service_path}/service/cloud/cloud_value_util.cpp", - "${data_service_path}/service/cloud/sync_manager.cpp", - "${data_service_path}/service/cloud/sync_strategies/network_sync_strategy.cpp", - "${data_service_path}/service/common/common_types_utils.cpp", - "${data_service_path}/service/common/value_proxy.cpp", - "${data_service_path}/service/common/xcollie.cpp", - "${data_service_path}/service/config/src/config_factory.cpp", - "${data_service_path}/service/config/src/model/app_id_mapping_config.cpp", - "${data_service_path}/service/config/src/model/backup_config.cpp", - "${data_service_path}/service/config/src/model/checker_config.cpp", - "${data_service_path}/service/config/src/model/cloud_config.cpp", - "${data_service_path}/service/config/src/model/component_config.cpp", - "${data_service_path}/service/config/src/model/directory_config.cpp", - "${data_service_path}/service/config/src/model/global_config.cpp", - "${data_service_path}/service/config/src/model/network_config.cpp", - "${data_service_path}/service/config/src/model/protocol_config.cpp", - "${data_service_path}/service/config/src/model/thread_config.cpp", - "${data_service_path}/service/crypto/src/crypto_manager.cpp", - "${data_service_path}/service/kvdb/user_delegate.cpp", - "${data_service_path}/service/permission/src/permission_validator.cpp", - "${data_service_path}/service/permission/src/permit_delegate.cpp", - "${data_service_path}/service/rdb/cache_cursor.cpp", - "${data_service_path}/service/rdb/rdb_asset_loader.cpp", - "${data_service_path}/service/rdb/rdb_cloud.cpp", - "${data_service_path}/service/rdb/rdb_cursor.cpp", - "${data_service_path}/service/rdb/rdb_general_store.cpp", - "${data_service_path}/service/rdb/rdb_hiview_adapter.cpp", - "${data_service_path}/service/rdb/rdb_notifier_proxy.cpp", - "${data_service_path}/service/rdb/rdb_query.cpp", - "${data_service_path}/service/rdb/rdb_result_set_impl.cpp", - "${data_service_path}/service/rdb/rdb_result_set_stub.cpp", - "${data_service_path}/service/rdb/rdb_schema_config.cpp", - "${data_service_path}/service/rdb/rdb_service_impl.cpp", - "${data_service_path}/service/rdb/rdb_service_stub.cpp", - "${data_service_path}/service/rdb/rdb_watcher.cpp", "cloudservicestub_fuzzer.cpp", ] deps = [ "${data_service_path}/adapter/account:distributeddata_account", + "${data_service_path}/adapter/dfx:distributeddata_dfx", "${data_service_path}/adapter/network:distributeddata_network", "${data_service_path}/adapter/schema_helper:distributeddata_schema_helper", "${data_service_path}/adapter/utils:distributeddata_utils", "${data_service_path}/framework:distributeddatasvcfwk", - "${data_service_path}/service:distributeddatasvc", + "${data_service_path}/service/bootstrap:distributeddata_bootstrap", + "${data_service_path}/service/cloud:distributeddata_cloud", + "${data_service_path}/service/common:distributeddata_common", + "${data_service_path}/service/rdb:distributeddata_rdb", "${kv_store_distributeddb_path}:distributeddb", ] external_deps = [ - "ability_base:want", - "ability_base:zuri", - "ability_runtime:ability_manager", - "ability_runtime:dataobs_manager", "access_token:libaccesstoken_sdk", "access_token:libtoken_setproc", "access_token:libtokenid_sdk", diff --git a/services/distributeddataservice/service/test/fuzztest/rdbservicestub_fuzzer/BUILD.gn b/services/distributeddataservice/service/test/fuzztest/rdbservicestub_fuzzer/BUILD.gn index e51d78511..820172706 100644 --- a/services/distributeddataservice/service/test/fuzztest/rdbservicestub_fuzzer/BUILD.gn +++ b/services/distributeddataservice/service/test/fuzztest/rdbservicestub_fuzzer/BUILD.gn @@ -64,46 +64,19 @@ ohos_fuzztest("RdbServiceStubFuzzTest") { sources = [ "${data_service_path}/app/src/checker/bundle_checker.cpp", "${data_service_path}/app/src/checker/system_checker.cpp", - "${data_service_path}/service/backup/src/backup_manager.cpp", - "${data_service_path}/service/bootstrap/src/bootstrap.cpp", - "${data_service_path}/service/common/value_proxy.cpp", - "${data_service_path}/service/common/xcollie.cpp", - "${data_service_path}/service/config/src/config_factory.cpp", - "${data_service_path}/service/config/src/model/app_id_mapping_config.cpp", - "${data_service_path}/service/config/src/model/backup_config.cpp", - "${data_service_path}/service/config/src/model/checker_config.cpp", - "${data_service_path}/service/config/src/model/cloud_config.cpp", - "${data_service_path}/service/config/src/model/component_config.cpp", - "${data_service_path}/service/config/src/model/directory_config.cpp", - "${data_service_path}/service/config/src/model/global_config.cpp", - "${data_service_path}/service/config/src/model/network_config.cpp", - "${data_service_path}/service/config/src/model/protocol_config.cpp", - "${data_service_path}/service/config/src/model/thread_config.cpp", - "${data_service_path}/service/crypto/src/crypto_manager.cpp", - "${data_service_path}/service/rdb/cache_cursor.cpp", - "${data_service_path}/service/rdb/rdb_asset_loader.cpp", - "${data_service_path}/service/rdb/rdb_cloud.cpp", - "${data_service_path}/service/rdb/rdb_cursor.cpp", - "${data_service_path}/service/rdb/rdb_general_store.cpp", - "${data_service_path}/service/rdb/rdb_hiview_adapter.cpp", - "${data_service_path}/service/rdb/rdb_notifier_proxy.cpp", - "${data_service_path}/service/rdb/rdb_query.cpp", - "${data_service_path}/service/rdb/rdb_result_set_impl.cpp", - "${data_service_path}/service/rdb/rdb_result_set_stub.cpp", - "${data_service_path}/service/rdb/rdb_schema_config.cpp", - "${data_service_path}/service/rdb/rdb_service_impl.cpp", - "${data_service_path}/service/rdb/rdb_service_stub.cpp", - "${data_service_path}/service/rdb/rdb_watcher.cpp", "rdbservicestub_fuzzer.cpp", ] deps = [ "${data_service_path}/adapter/account:distributeddata_account", + "${data_service_path}/adapter/dfx:distributeddata_dfx", "${data_service_path}/adapter/utils:distributeddata_utils", "${data_service_path}/framework:distributeddatasvcfwk", - "${data_service_path}/service:distributeddatasvc", + "${data_service_path}/service/bootstrap:distributeddata_bootstrap", + "${data_service_path}/service/cloud:distributeddata_cloud", + "${data_service_path}/service/common:distributeddata_common", + "${data_service_path}/service/rdb:distributeddata_rdb", "${kv_store_distributeddb_path}:distributeddb", - "${relational_store_inner_api_path}:native_rdb_static", ] external_deps = [ -- Gitee From 415a61a07cbd2929bc7fa87bf70e71c503798c3d Mon Sep 17 00:00:00 2001 From: htt1997 Date: Thu, 8 May 2025 16:00:03 +0800 Subject: [PATCH 3/3] fix Signed-off-by: htt1997 --- .../adapter/bundle_mgr/BUILD.gn | 57 ------------------- .../adapter/bundle_mgr/bundle_mgr_adapter.cpp | 40 ------------- .../adapter/bundle_mgr/bundle_mgr_adapter.h | 31 ---------- .../adapter/bundle_mgr/test/BUILD.gn | 42 -------------- .../bundle_mgr/test/bundle_mgr_test.cpp | 45 --------------- .../adapter/test/BUILD.gn | 1 - .../service/rdb/BUILD.gn | 1 - .../service/rdb/rdb_service_impl.cpp | 16 +++--- .../service/rdb/rdb_service_impl.h | 3 +- .../service/rdb/rdb_service_stub.cpp | 5 +- 10 files changed, 14 insertions(+), 227 deletions(-) delete mode 100644 services/distributeddataservice/adapter/bundle_mgr/BUILD.gn delete mode 100644 services/distributeddataservice/adapter/bundle_mgr/bundle_mgr_adapter.cpp delete mode 100644 services/distributeddataservice/adapter/bundle_mgr/bundle_mgr_adapter.h delete mode 100644 services/distributeddataservice/adapter/bundle_mgr/test/BUILD.gn delete mode 100644 services/distributeddataservice/adapter/bundle_mgr/test/bundle_mgr_test.cpp diff --git a/services/distributeddataservice/adapter/bundle_mgr/BUILD.gn b/services/distributeddataservice/adapter/bundle_mgr/BUILD.gn deleted file mode 100644 index 7ca4db4f9..000000000 --- a/services/distributeddataservice/adapter/bundle_mgr/BUILD.gn +++ /dev/null @@ -1,57 +0,0 @@ -# Copyright (c) 2025 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. -import("//build/ohos.gni") -import("//foundation/distributeddatamgr/datamgr_service/datamgr_service.gni") - -config("module_public_config") { - visibility = [ ":*" ] - include_dirs = [ "${data_service_path}/adapter" ] -} - -ohos_source_set("distributeddata_bundle_mgr") { - branch_protector_ret = "pac_ret" - sanitize = { - cfi = true - cfi_cross_dso = true - debug = false - boundary_sanitize = true - ubsan = true - } - sources = [ "bundle_mgr_adapter.cpp" ] - cflags_cc = [ - "-fvisibility=hidden", - "-Oz", - "-fstack-protector-strong", - ] - - public_configs = [ ":module_public_config" ] - cflags = [ - "-fdata-sections", - "-ffunction-sections", - "-Werror", - "-Wno-multichar", - "-Wno-c99-designator", - "-D_LIBCPP_HAS_COND_CLOCKWAIT", - "-Oz", - "-fstack-protector-strong", - ] - - external_deps = [ "kv_store:datamgr_common" ] - external_deps += [ - "bundle_framework:appexecfwk_base", - "bundle_framework:appexecfwk_core", - "hilog:libhilog", - ] - subsystem_name = "distributeddatamgr" - part_name = "datamgr_service" -} diff --git a/services/distributeddataservice/adapter/bundle_mgr/bundle_mgr_adapter.cpp b/services/distributeddataservice/adapter/bundle_mgr/bundle_mgr_adapter.cpp deleted file mode 100644 index efd9d203a..000000000 --- a/services/distributeddataservice/adapter/bundle_mgr/bundle_mgr_adapter.cpp +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2025 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. - */ - -#define LOG_TAG "BundleMgrAdapter" -#include "bundle_mgr/bundle_mgr_adapter.h" -#include "bundle_mgr_client.h" -#include "log_print.h" -using namespace OHOS::AppExecFwk; -namespace OHOS::DistributedData { - -BundleMgrAdapter &BundleMgrAdapter::GetInstance() -{ - static BundleMgrAdapter instance; - return instance; -} - -std::string BundleMgrAdapter::GetBundleName(int32_t uid) -{ - BundleMgrClient client; - std::string bundleName; - auto code = client.GetNameForUid(uid, bundleName); - if (code != 0) { - ZLOGE("failed. uid:%{public}d, code:%{public}d", uid, code); - return ""; - } - return bundleName; -} -} // namespace OHOS::DistributedData \ No newline at end of file diff --git a/services/distributeddataservice/adapter/bundle_mgr/bundle_mgr_adapter.h b/services/distributeddataservice/adapter/bundle_mgr/bundle_mgr_adapter.h deleted file mode 100644 index e955a6fba..000000000 --- a/services/distributeddataservice/adapter/bundle_mgr/bundle_mgr_adapter.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2025 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. - */ -#ifndef DISTRIBUTEDDATAMGR_DATAMGR_BUNDLE_MANAGER_ADAPTER_H -#define DISTRIBUTEDDATAMGR_DATAMGR_BUNDLE_MANAGER_ADAPTER_H - -#include -#include -#include "visibility.h" - -namespace OHOS { -namespace DistributedData { -class API_EXPORT BundleMgrAdapter { -public: - static BundleMgrAdapter &GetInstance(); - std::string GetBundleName(int32_t uid); -}; -} // namespace DistributedData -} // namespace OHOS -#endif //DISTRIBUTEDDATAMGR_DATAMGR_BUNDLE_MANAGER_ADAPTER_H diff --git a/services/distributeddataservice/adapter/bundle_mgr/test/BUILD.gn b/services/distributeddataservice/adapter/bundle_mgr/test/BUILD.gn deleted file mode 100644 index 193ada6a4..000000000 --- a/services/distributeddataservice/adapter/bundle_mgr/test/BUILD.gn +++ /dev/null @@ -1,42 +0,0 @@ -# Copyright (c) 2025 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. -import("//build/test.gni") -import("//foundation/distributeddatamgr/datamgr_service/datamgr_service.gni") -module_output_path = "datamgr_service/datamgr_service/distributeddatafwk" - -############################################################################### -ohos_unittest("BundleMgrTest") { - module_out_path = module_output_path - - sources = [ "bundle_mgr_test.cpp" ] - - cflags = [ "-Werror" ] - deps = [ "${data_service_path}/adapter/bundle_mgr:distributeddata_bundle_mgr" ] - - external_deps = [ - "googletest:gtest_main", - "hilog:libhilog", - "ipc:ipc_core", - "kv_store:datamgr_common", - ] -} - -############################################################################### -group("unittest") { - testonly = true - - deps = [] - - deps += [ ":BundleMgrTest" ] -} -############################################################################### diff --git a/services/distributeddataservice/adapter/bundle_mgr/test/bundle_mgr_test.cpp b/services/distributeddataservice/adapter/bundle_mgr/test/bundle_mgr_test.cpp deleted file mode 100644 index bf5590727..000000000 --- a/services/distributeddataservice/adapter/bundle_mgr/test/bundle_mgr_test.cpp +++ /dev/null @@ -1,45 +0,0 @@ -/* -* Copyright (c) 2025 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 "bundle_mgr/bundle_mgr_adapter.h" -#include "ipc_skeleton.h" -namespace { -using namespace OHOS; -using namespace OHOS::DistributedData; -using namespace testing::ext; - -class BundleMgrTest : public testing::Test { -public: - static void SetUpTestCase(void) {} - static void TearDownTestCase(void) {} - void SetUp() {} - void TearDown() {} -}; - -/** -* @tc.name: GetBundleName -* @tc.desc: GetBundleName test -* @tc.type: FUNC -* @tc.require: -* @tc.author: -*/ -HWTEST_F(BundleMgrTest, GetBundleName, TestSize.Level0) -{ - auto bundleName = BundleMgrAdapter::GetInstance().GetBundleName(0); - EXPECT_TRUE(bundleName.empty()); -} -} // namespace \ No newline at end of file diff --git a/services/distributeddataservice/adapter/test/BUILD.gn b/services/distributeddataservice/adapter/test/BUILD.gn index 7e5686d14..db76543eb 100755 --- a/services/distributeddataservice/adapter/test/BUILD.gn +++ b/services/distributeddataservice/adapter/test/BUILD.gn @@ -20,7 +20,6 @@ group("unittest") { deps += [ "../account/test:unittest", - "../bundle_mgr/test:unittest", "../communicator/test:unittest", "../dfx/test:unittest", ] diff --git a/services/distributeddataservice/service/rdb/BUILD.gn b/services/distributeddataservice/service/rdb/BUILD.gn index 9692c996e..ad693d92d 100644 --- a/services/distributeddataservice/service/rdb/BUILD.gn +++ b/services/distributeddataservice/service/rdb/BUILD.gn @@ -67,7 +67,6 @@ ohos_source_set("distributeddata_rdb") { ] deps = [ - "${data_service_path}/adapter/bundle_mgr:distributeddata_bundle_mgr", "${data_service_path}/service/bootstrap:distributeddata_bootstrap", "${data_service_path}/service/common:distributeddata_common", "${data_service_path}/service/crypto:distributeddata_crypto", diff --git a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp index 3d5f48302..a060d5df3 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp +++ b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp @@ -18,7 +18,6 @@ #include "abs_rdb_predicates.h" #include "accesstoken_kit.h" #include "account/account_delegate.h" -#include "bundle_mgr/bundle_mgr_adapter.h" #include "changeevent/remote_change_event.h" #include "checker/checker_manager.h" #include "cloud/change_event.h" @@ -232,19 +231,22 @@ bool RdbServiceImpl::CheckAccess(const std::string& bundleName, const std::strin return !CheckerManager::GetInstance().GetAppId(storeInfo).empty(); } -std::string RdbServiceImpl::ObtainDistributedTableName(const std::string &device, const std::string &table) +std::string RdbServiceImpl::ObtainDistributedTableName(const RdbSyncerParam ¶m, const std::string &device, + const std::string &table) { - ZLOGI("device=%{public}s table=%{public}s", Anonymous::Change(device).c_str(), Anonymous::Change(table).c_str()); - auto uid = IPCSkeleton::GetCallingUid(); - auto bundleName = BundleMgrAdapter::GetInstance().GetBundleName(uid); + if (!CheckAccess(param.bundleName_, "")) { + ZLOGE("bundleName:%{public}s. Permission error", param.bundleName_.c_str()); + return ""; + } auto tokenId = IPCSkeleton::GetCallingTokenID(); std::string appId = " "; if (AccessTokenKit::GetTokenTypeFlag(tokenId) == Security::AccessToken::TOKEN_HAP) { - appId = CheckerManager::GetInstance().GetAppId({ uid, tokenId, bundleName }); + auto uid = IPCSkeleton::GetCallingUid(); + appId = CheckerManager::GetInstance().GetAppId({ uid, tokenId, param.bundleName_ }); } auto uuid = DmAdapter::GetInstance().CalcClientUuid(appId, DmAdapter::GetInstance().ToUUID(device)); if (uuid.empty()) { - ZLOGE("get uuid failed, bundle:%{public}s, deviceId:%{public}s, table:%{public}s", bundleName.c_str(), + ZLOGE("get uuid failed, bundle:%{public}s, deviceId:%{public}s, table:%{public}s", param.bundleName_.c_str(), Anonymous::Change(device).c_str(), Anonymous::Change(table).c_str()); return ""; } diff --git a/services/distributeddataservice/service/rdb/rdb_service_impl.h b/services/distributeddataservice/service/rdb/rdb_service_impl.h index b876a2f40..ee9cc076a 100755 --- a/services/distributeddataservice/service/rdb/rdb_service_impl.h +++ b/services/distributeddataservice/service/rdb/rdb_service_impl.h @@ -53,7 +53,8 @@ public: virtual ~RdbServiceImpl(); /* IPC interface */ - std::string ObtainDistributedTableName(const std::string& device, const std::string& table) override; + std::string ObtainDistributedTableName(const RdbSyncerParam ¶m, const std::string &device, + const std::string &table) override; int32_t InitNotifier(const RdbSyncerParam ¶m, sptr notifier) override; diff --git a/services/distributeddataservice/service/rdb/rdb_service_stub.cpp b/services/distributeddataservice/service/rdb/rdb_service_stub.cpp index fd7ee6ee4..f52549c1f 100755 --- a/services/distributeddataservice/service/rdb/rdb_service_stub.cpp +++ b/services/distributeddataservice/service/rdb/rdb_service_stub.cpp @@ -28,14 +28,15 @@ namespace OHOS::DistributedRdb { using Anonymous = DistributedData::Anonymous; int32_t RdbServiceStub::OnRemoteObtainDistributedTableName(MessageParcel &data, MessageParcel &reply) { + RdbSyncerParam param; std::string device; std::string table; - if (!ITypesUtil::Unmarshal(data, device, table)) { + if (!ITypesUtil::Unmarshal(data, param, device, table)) { ZLOGE("Unmarshal device:%{public}s table:%{public}s", Anonymous::Change(device).c_str(), table.c_str()); return IPC_STUB_INVALID_DATA_ERR; } - std::string distributedTableName = ObtainDistributedTableName(device, table); + std::string distributedTableName = ObtainDistributedTableName(param, device, table); int32_t status = distributedTableName.empty() ? RDB_ERROR : RDB_OK; if (!ITypesUtil::Marshal(reply, status, distributedTableName)) { ZLOGE("Marshal distributedTableName:%{public}s", distributedTableName.c_str()); -- Gitee