From 09dd1d4d15dbf17120d0598831394c20b0a3c1a0 Mon Sep 17 00:00:00 2001 From: bigteer Date: Sat, 2 Aug 2025 19:20:20 +0800 Subject: [PATCH 1/5] ACL Signed-off-by: bigteer --- .../service/common/BUILD.gn | 1 + .../service/common/bundle_utils.cpp | 42 +++++++++++++++++ .../service/common/bundle_utils.h | 41 +++++++++++++++++ .../data_share/common/bundle_mgr_proxy.cpp | 24 ++++++++++ .../data_share/common/bundle_mgr_proxy.h | 1 + .../data_share/data_share_service_impl.cpp | 7 +++ .../service/rdb/rdb_service_impl.cpp | 10 ++++ .../service/test/BUILD.gn | 2 + .../test/data_share_service_impl_test.cpp | 46 +++++++++++++++++++ .../datashareserviceimpl_fuzzer/BUILD.gn | 1 + .../datashareservicestub_fuzzer/BUILD.gn | 1 + .../datasharesubscriber_fuzzer/BUILD.gn | 1 + 12 files changed, 177 insertions(+) create mode 100644 services/distributeddataservice/service/common/bundle_utils.cpp create mode 100644 services/distributeddataservice/service/common/bundle_utils.h diff --git a/services/distributeddataservice/service/common/BUILD.gn b/services/distributeddataservice/service/common/BUILD.gn index 50a08c56e..98a8c1c55 100644 --- a/services/distributeddataservice/service/common/BUILD.gn +++ b/services/distributeddataservice/service/common/BUILD.gn @@ -23,6 +23,7 @@ ohos_source_set("distributeddata_common") { ubsan = true } sources = [ + "bundle_utils.cpp", "common_types_utils.cpp", "value_proxy.cpp", "xcollie.cpp", diff --git a/services/distributeddataservice/service/common/bundle_utils.cpp b/services/distributeddataservice/service/common/bundle_utils.cpp new file mode 100644 index 000000000..d0ae140bb --- /dev/null +++ b/services/distributeddataservice/service/common/bundle_utils.cpp @@ -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. +*/ + +#include "bundle_utils.h" + +namespace OHOS::DistributedData { +std::shared_ptr Bundle_Utils::GetInstance() +{ + static std::shared_ptr instance = nullptr; + if (instance == nullptr) { + instance = std::make_shared(); + } + return instance; +} + +void Bundle_Utils::SetBundleInfoCallback(Callback callback) +{ + std::lock_guard lock(lock_); + bundleInfoCallback_ = callback; +} + +std::pair Bundle_Utils::CheckSilentConfig(const std::string &bundleName, int32_t userId) +{ + std::lock_guard lock(lock_); + if (bundleInfoCallback_ == nullptr) { + return std::make_pair(-1, false); + } + return bundleInfoCallback_(bundleName, userId); +} +} \ No newline at end of file diff --git a/services/distributeddataservice/service/common/bundle_utils.h b/services/distributeddataservice/service/common/bundle_utils.h new file mode 100644 index 000000000..fda93d197 --- /dev/null +++ b/services/distributeddataservice/service/common/bundle_utils.h @@ -0,0 +1,41 @@ +/* +* 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 OHOS_DISTRIBUTED_DATA_DATAMGR_SERVICE_BUNDLEINFO_UTILS_H +#define OHOS_DISTRIBUTED_DATA_DATAMGR_SERVICE_BUNDLEINFO_UTILS_H + +#include +#include +#include +#include +#include + +namespace OHOS::DistributedData { +using Callback = std::function(const std::string &bundleName, int32_t userId)>; +class Bundle_Utils { +public: + Bundle_Utils() = default; + static std::shared_ptr GetInstance(); + + std::pair CheckSilentConfig(const std::string &bundleName, int32_t userId); + + void SetBundleInfoCallback(Callback callback); + +private: + std::mutex lock_; + Callback bundleInfoCallback_; +}; +} +#endif // OHOS_DISTRIBUTED_DATA_DATAMGR_SERVICE_BUNDLEINFO_UTILS_H \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/common/bundle_mgr_proxy.cpp b/services/distributeddataservice/service/data_share/common/bundle_mgr_proxy.cpp index 267a66c32..34f5feb23 100644 --- a/services/distributeddataservice/service/data_share/common/bundle_mgr_proxy.cpp +++ b/services/distributeddataservice/service/data_share/common/bundle_mgr_proxy.cpp @@ -290,4 +290,28 @@ std::pair> BundleMgrProxy::ConvertHapModuleInfo( } return std::make_pair(E_OK, hapModuleInfos); } + +std::pair BundleMgrProxy::CheckSilentConfig(const std::string &bundleName, int32_t userId) +{ + AppExecFwk::BundleInfo bundleInfo; + auto bmsClient = GetBundleMgrProxy(); + if (bmsClient == nullptr) { + ZLOGE("GetBundleMgrProxy is nullptr!"); + return std::make_pair(E_BMS_NOT_READY, false); + } + + auto ret = bmsClient->GetBundleInfo(bundleName, + static_cast(AppExecFwk::GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_HAP_MODULE), bundleInfo, userId); + if (!ret) { + ZLOGE("Get bundleInfo failed! ret: %{public}d", ret); + return std::make_pair(E_ERROR, false); + } + + for (auto &hapModuleInfo : bundleInfo.hapModuleInfos) { + if (!hapModuleInfo.proxyDatas.empty()) { + return std::make_pair(E_OK, true); + } + } + return std::make_pair(E_SILENT_PROXY_DISABLE, false); +} } // namespace OHOS::DataShare \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/common/bundle_mgr_proxy.h b/services/distributeddataservice/service/data_share/common/bundle_mgr_proxy.h index 7198715f1..6f6ca58c4 100644 --- a/services/distributeddataservice/service/data_share/common/bundle_mgr_proxy.h +++ b/services/distributeddataservice/service/data_share/common/bundle_mgr_proxy.h @@ -85,6 +85,7 @@ public: BundleConfig &bundleConfig, int32_t appIndex = 0); int GetBundleInfoFromBMSWithCheck(const std::string &bundleName, int32_t userId, BundleConfig &bundleConfig, int32_t appIndex = 0); + std::pair CheckSilentConfig(const std::string &bundleName, int32_t userId); void Delete(const std::string &bundleName, int32_t userId, int32_t appIndex); sptr CheckBMS(); std::pair GetCallerAppIdentifier(const std::string &bundleName, int32_t userId); 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 b6c6ef150..969dd88bf 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp @@ -22,6 +22,8 @@ #include "account/account_delegate.h" #include "app_connect_manager.h" +#include "bundle_mgr_proxy.h" +#include "bundle_utils.h" #include "block_data.h" #include "common_event_manager.h" #include "common_event_support.h" @@ -667,6 +669,11 @@ int32_t DataShareServiceImpl::OnBind(const BindInfo &binderInfo) SubscribeConcurrentTask(); SubscribeTimeChanged(); SubscribeChange(); + + auto task = [](const std::string &bundleName, int32_t userId) { + return BundleMgrProxy::GetInstance()->CheckSilentConfig(bundleName, userId); + }; + Bundle_Utils::GetInstance()->SetBundleInfoCallback(task); ZLOGI("end"); return E_OK; } diff --git a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp index 3f2341dee..29fa28924 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp +++ b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp @@ -19,6 +19,7 @@ #include "accesstoken_kit.h" #include "account/account_delegate.h" #include "bootstrap.h" +#include "bundle_utils.h" #include "changeevent/remote_change_event.h" #include "checker/checker_manager.h" #include "cloud/change_event.h" @@ -880,6 +881,15 @@ int32_t RdbServiceImpl::BeforeOpen(RdbSyncerParam ¶m) return RDB_NO_META; } SetReturnParam(meta, param); + if (param.isSilent_) { + return RDB_OK; + } + if (param.isSearchable_) { + param.isSilent_ = true; + return RDB_OK; + } + auto [err, flag] = Bundle_Utils::GetInstance()->CheckSilentConfig(meta.bundleName, std::stoi(meta.user)); + param.isSilent_ = flag; return RDB_OK; } diff --git a/services/distributeddataservice/service/test/BUILD.gn b/services/distributeddataservice/service/test/BUILD.gn index 791ef3b46..495684a21 100644 --- a/services/distributeddataservice/service/test/BUILD.gn +++ b/services/distributeddataservice/service/test/BUILD.gn @@ -1161,6 +1161,7 @@ ohos_unittest("DataShareServiceImplTest") { ] sources = [ + "${data_service_path}/service/common/bundle_utils.cpp", "${data_service_path}/service/common/xcollie.cpp", "${data_service_path}/service/data_share/common/app_connect_manager.cpp", "${data_service_path}/service/data_share/common/bundle_mgr_proxy.cpp", @@ -1291,6 +1292,7 @@ ohos_unittest("DataShareServiceImplMockTest") { include_dirs = [ "${data_service_path}/service/config/include" ] sources = [ + "${data_service_path}/service/common/bundle_utils.cpp", "${data_service_path}/service/common/xcollie.cpp", "${data_service_path}/service/config/src/model/app_access_check_config.cpp", "${data_service_path}/service/config/src/model/app_id_mapping_config.cpp", diff --git a/services/distributeddataservice/service/test/data_share_service_impl_test.cpp b/services/distributeddataservice/service/test/data_share_service_impl_test.cpp index cd59ac22f..7e3126442 100644 --- a/services/distributeddataservice/service/test/data_share_service_impl_test.cpp +++ b/services/distributeddataservice/service/test/data_share_service_impl_test.cpp @@ -21,6 +21,8 @@ #include "accesstoken_kit.h" #include "account_delegate_mock.h" +#include "bundle_mgr_proxy.h" +#include "bundle_utils.h" #include "data_share_service_stub.h" #include "device_manager_adapter.h" #include "dump/dump_manager.h" @@ -563,4 +565,48 @@ HWTEST_F(DataShareServiceImplTest, UpdateLaunchInfo001, TestSize.Level1) EXPECT_EQ(storeMetaData.size(), 0); ZLOGI("DataShareServiceImplTest UpdateLaunchInfo001 end"); } + +/** +* @tc.name: BundleMgrProxyTest001 +* @tc.desc: Test the CheckSilentConfig method of BundleMgrProxy +* @tc.type: FUNC +* @tc.require: +*/ +HWTEST_F(DataShareServiceImplTest, BundleMgrProxyTest001, TestSize.Level1) +{ + ZLOGI("DataShareServiceImplTest BundleMgrProxyTest001 start"); + int32_t user = static_cast(USER_TEST); + auto bundleMgr = BundleMgrProxy::GetInstance(); + auto [err, ret] = bundleMgr->CheckSilentConfig(BUNDLE_NAME, user); + EXPECT_EQ(err, OHOS::DataShare::E_SILENT_PROXY_DISABLE); + EXPECT_EQ(ret, false); + auto [err2, ret2] = bundleMgr->CheckSilentConfig("", user); + EXPECT_NE(err2, OHOS::DataShare::E_OK); + EXPECT_EQ(ret2, false); + ZLOGI("DataShareServiceImplTest BundleMgrProxyTest001 end"); +} + +/** +* @tc.name: BundleUtilsTest001 +* @tc.desc: Test the SetBundleInfoCallback and CheckSilentConfig methods of Bundle_Utils +* @tc.type: FUNC +* @tc.require: +*/ +HWTEST_F(DataShareServiceImplTest, BundleUtilsTest001, TestSize.Level1) +{ + ZLOGI("DataShareServiceImplTest BundleUtilsTest001 start"); + + auto [err, ret] = Bundle_Utils::GetInstance()->CheckSilentConfig("", 0); + EXPECT_EQ(err, -1); + EXPECT_EQ(ret, false); + + auto task = [](const std::string &bundleName, int32_t userId) { + return std::make_pair(0, true); + }; + Bundle_Utils::GetInstance()->SetBundleInfoCallback(task); + auto [err2, ret2] = Bundle_Utils::GetInstance()->CheckSilentConfig("", 0); + EXPECT_EQ(err2, 0); + EXPECT_EQ(ret2, true); + ZLOGI("DataShareServiceImplTest BundleUtilsTest001 end"); +} } // namespace OHOS::Test \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/datashareserviceimpl_fuzzer/BUILD.gn b/services/distributeddataservice/service/test/fuzztest/datashareserviceimpl_fuzzer/BUILD.gn index 17ca41e7e..a9fa1ed93 100644 --- a/services/distributeddataservice/service/test/fuzztest/datashareserviceimpl_fuzzer/BUILD.gn +++ b/services/distributeddataservice/service/test/fuzztest/datashareserviceimpl_fuzzer/BUILD.gn @@ -50,6 +50,7 @@ ohos_fuzztest("DataShareServiceImplFuzzTest") { ] sources = [ + "${data_service_path}/service/common/bundle_utils.cpp", "${data_service_path}/service/common/xcollie.cpp", "${data_service_path}/service/data_share/common/app_connect_manager.cpp", "${data_service_path}/service/data_share/common/bundle_mgr_proxy.cpp", diff --git a/services/distributeddataservice/service/test/fuzztest/datashareservicestub_fuzzer/BUILD.gn b/services/distributeddataservice/service/test/fuzztest/datashareservicestub_fuzzer/BUILD.gn index 8f2dc9fbb..122e80ed1 100644 --- a/services/distributeddataservice/service/test/fuzztest/datashareservicestub_fuzzer/BUILD.gn +++ b/services/distributeddataservice/service/test/fuzztest/datashareservicestub_fuzzer/BUILD.gn @@ -48,6 +48,7 @@ ohos_fuzztest("DataShareServiceStubFuzzTest") { ] sources = [ + "${data_service_path}/service/common/bundle_utils.cpp", "${data_service_path}/service/common/xcollie.cpp", "${data_service_path}/service/data_share/common/app_connect_manager.cpp", "${data_service_path}/service/data_share/common/bundle_mgr_proxy.cpp", diff --git a/services/distributeddataservice/service/test/fuzztest/datasharesubscriber_fuzzer/BUILD.gn b/services/distributeddataservice/service/test/fuzztest/datasharesubscriber_fuzzer/BUILD.gn index 42efc4c2c..59d6a23d9 100644 --- a/services/distributeddataservice/service/test/fuzztest/datasharesubscriber_fuzzer/BUILD.gn +++ b/services/distributeddataservice/service/test/fuzztest/datasharesubscriber_fuzzer/BUILD.gn @@ -50,6 +50,7 @@ ohos_fuzztest("DataShareSubscriberFuzzTest") { ] sources = [ + "${data_service_path}/service/common/bundle_utils.cpp", "${data_service_path}/service/common/xcollie.cpp", "${data_service_path}/service/data_share/common/app_connect_manager.cpp", "${data_service_path}/service/data_share/common/bundle_mgr_proxy.cpp", -- Gitee From 6cb8c0392d10df0963cbf286292b450afd4d94f5 Mon Sep 17 00:00:00 2001 From: bigteer Date: Mon, 4 Aug 2025 10:35:18 +0800 Subject: [PATCH 2/5] ACL Signed-off-by: bigteer --- .../service/common/bundle_utils.cpp | 11 ++++------- .../service/common/bundle_utils.h | 6 +++--- .../service/data_share/data_share_service_impl.cpp | 2 +- .../service/rdb/rdb_service_impl.cpp | 8 ++++---- .../service/test/data_share_service_impl_test.cpp | 12 ++++++------ 5 files changed, 18 insertions(+), 21 deletions(-) diff --git a/services/distributeddataservice/service/common/bundle_utils.cpp b/services/distributeddataservice/service/common/bundle_utils.cpp index d0ae140bb..ad6ebee62 100644 --- a/services/distributeddataservice/service/common/bundle_utils.cpp +++ b/services/distributeddataservice/service/common/bundle_utils.cpp @@ -16,22 +16,19 @@ #include "bundle_utils.h" namespace OHOS::DistributedData { -std::shared_ptr Bundle_Utils::GetInstance() +BundleUtils &BundleUtils::GetInstance() { - static std::shared_ptr instance = nullptr; - if (instance == nullptr) { - instance = std::make_shared(); - } + static BundleUtils instance; return instance; } -void Bundle_Utils::SetBundleInfoCallback(Callback callback) +void BundleUtils::SetBundleInfoCallback(Callback callback) { std::lock_guard lock(lock_); bundleInfoCallback_ = callback; } -std::pair Bundle_Utils::CheckSilentConfig(const std::string &bundleName, int32_t userId) +std::pair BundleUtils::CheckSilentConfig(const std::string &bundleName, int32_t userId) { std::lock_guard lock(lock_); if (bundleInfoCallback_ == nullptr) { diff --git a/services/distributeddataservice/service/common/bundle_utils.h b/services/distributeddataservice/service/common/bundle_utils.h index fda93d197..de1daff46 100644 --- a/services/distributeddataservice/service/common/bundle_utils.h +++ b/services/distributeddataservice/service/common/bundle_utils.h @@ -24,10 +24,10 @@ namespace OHOS::DistributedData { using Callback = std::function(const std::string &bundleName, int32_t userId)>; -class Bundle_Utils { +class BundleUtils { public: - Bundle_Utils() = default; - static std::shared_ptr GetInstance(); + BundleUtils() = default; + BundleUtils &GetInstance(); std::pair CheckSilentConfig(const std::string &bundleName, int32_t userId); 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 969dd88bf..c9a1b00f7 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp @@ -673,7 +673,7 @@ int32_t DataShareServiceImpl::OnBind(const BindInfo &binderInfo) auto task = [](const std::string &bundleName, int32_t userId) { return BundleMgrProxy::GetInstance()->CheckSilentConfig(bundleName, userId); }; - Bundle_Utils::GetInstance()->SetBundleInfoCallback(task); + BundleUtils::GetInstance().SetBundleInfoCallback(task); ZLOGI("end"); return E_OK; } diff --git a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp index 29fa28924..f1502e68b 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp +++ b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp @@ -881,15 +881,15 @@ int32_t RdbServiceImpl::BeforeOpen(RdbSyncerParam ¶m) return RDB_NO_META; } SetReturnParam(meta, param); - if (param.isSilent_) { + if (param.isNeedSetAcl_) { return RDB_OK; } if (param.isSearchable_) { - param.isSilent_ = true; + param.isNeedSetAcl_ = true; return RDB_OK; } - auto [err, flag] = Bundle_Utils::GetInstance()->CheckSilentConfig(meta.bundleName, std::stoi(meta.user)); - param.isSilent_ = flag; + auto [err, flag] = BundleUtils::GetInstance().CheckSilentConfig(meta.bundleName, std::stoi(meta.user)); + param.isNeedSetAcl_ = flag; return RDB_OK; } diff --git a/services/distributeddataservice/service/test/data_share_service_impl_test.cpp b/services/distributeddataservice/service/test/data_share_service_impl_test.cpp index 7e3126442..32ec48458 100644 --- a/services/distributeddataservice/service/test/data_share_service_impl_test.cpp +++ b/services/distributeddataservice/service/test/data_share_service_impl_test.cpp @@ -136,8 +136,8 @@ HWTEST_F(DataShareServiceImplTest, DataShareServiceImpl001, TestSize.Level1) predicates.EqualTo("", ""); std::vector columns; - DataShareOption option; - auto [errVal, resQuery] = dataShareServiceImpl.Query(uri, "", predicates, columns, option); + DataShareOption option; + auto [errVal, resQuery] = dataShareServiceImpl.Query(uri, "", predicates, columns, option); int resultSet = 0; if (resQuery != nullptr) { resQuery->GetRowCount(resultSet); @@ -588,7 +588,7 @@ HWTEST_F(DataShareServiceImplTest, BundleMgrProxyTest001, TestSize.Level1) /** * @tc.name: BundleUtilsTest001 -* @tc.desc: Test the SetBundleInfoCallback and CheckSilentConfig methods of Bundle_Utils +* @tc.desc: Test the SetBundleInfoCallback and CheckSilentConfig methods of BundleUtils * @tc.type: FUNC * @tc.require: */ @@ -596,15 +596,15 @@ HWTEST_F(DataShareServiceImplTest, BundleUtilsTest001, TestSize.Level1) { ZLOGI("DataShareServiceImplTest BundleUtilsTest001 start"); - auto [err, ret] = Bundle_Utils::GetInstance()->CheckSilentConfig("", 0); + auto [err, ret] = BundleUtils::GetInstance().CheckSilentConfig("", 0); EXPECT_EQ(err, -1); EXPECT_EQ(ret, false); auto task = [](const std::string &bundleName, int32_t userId) { return std::make_pair(0, true); }; - Bundle_Utils::GetInstance()->SetBundleInfoCallback(task); - auto [err2, ret2] = Bundle_Utils::GetInstance()->CheckSilentConfig("", 0); + BundleUtils::GetInstance().SetBundleInfoCallback(task); + auto [err2, ret2] = BundleUtils::GetInstance().CheckSilentConfig("", 0); EXPECT_EQ(err2, 0); EXPECT_EQ(ret2, true); ZLOGI("DataShareServiceImplTest BundleUtilsTest001 end"); -- Gitee From 0d2435bc4c07d53604aca8ff72a9046fa06a43b4 Mon Sep 17 00:00:00 2001 From: bigteer Date: Mon, 4 Aug 2025 10:44:54 +0800 Subject: [PATCH 3/5] ACL Signed-off-by: bigteer --- .../distributeddataservice/service/common/bundle_utils.cpp | 1 - .../distributeddataservice/service/common/bundle_utils.h | 2 +- .../service/test/data_share_service_impl_test.cpp | 5 +++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/services/distributeddataservice/service/common/bundle_utils.cpp b/services/distributeddataservice/service/common/bundle_utils.cpp index ad6ebee62..08a96a16b 100644 --- a/services/distributeddataservice/service/common/bundle_utils.cpp +++ b/services/distributeddataservice/service/common/bundle_utils.cpp @@ -30,7 +30,6 @@ void BundleUtils::SetBundleInfoCallback(Callback callback) std::pair BundleUtils::CheckSilentConfig(const std::string &bundleName, int32_t userId) { - std::lock_guard lock(lock_); if (bundleInfoCallback_ == nullptr) { return std::make_pair(-1, false); } diff --git a/services/distributeddataservice/service/common/bundle_utils.h b/services/distributeddataservice/service/common/bundle_utils.h index de1daff46..98dad60ea 100644 --- a/services/distributeddataservice/service/common/bundle_utils.h +++ b/services/distributeddataservice/service/common/bundle_utils.h @@ -27,7 +27,7 @@ using Callback = std::function(const std::string &bundleNam class BundleUtils { public: BundleUtils() = default; - BundleUtils &GetInstance(); + static BundleUtils &GetInstance(); std::pair CheckSilentConfig(const std::string &bundleName, int32_t userId); diff --git a/services/distributeddataservice/service/test/data_share_service_impl_test.cpp b/services/distributeddataservice/service/test/data_share_service_impl_test.cpp index 32ec48458..076ec4bb3 100644 --- a/services/distributeddataservice/service/test/data_share_service_impl_test.cpp +++ b/services/distributeddataservice/service/test/data_share_service_impl_test.cpp @@ -570,13 +570,14 @@ HWTEST_F(DataShareServiceImplTest, UpdateLaunchInfo001, TestSize.Level1) * @tc.name: BundleMgrProxyTest001 * @tc.desc: Test the CheckSilentConfig method of BundleMgrProxy * @tc.type: FUNC -* @tc.require: +* @tc.require: */ HWTEST_F(DataShareServiceImplTest, BundleMgrProxyTest001, TestSize.Level1) { ZLOGI("DataShareServiceImplTest BundleMgrProxyTest001 start"); int32_t user = static_cast(USER_TEST); auto bundleMgr = BundleMgrProxy::GetInstance(); + ASSERT_NE(bundleMgr, nullptr); auto [err, ret] = bundleMgr->CheckSilentConfig(BUNDLE_NAME, user); EXPECT_EQ(err, OHOS::DataShare::E_SILENT_PROXY_DISABLE); EXPECT_EQ(ret, false); @@ -590,7 +591,7 @@ HWTEST_F(DataShareServiceImplTest, BundleMgrProxyTest001, TestSize.Level1) * @tc.name: BundleUtilsTest001 * @tc.desc: Test the SetBundleInfoCallback and CheckSilentConfig methods of BundleUtils * @tc.type: FUNC -* @tc.require: +* @tc.require: */ HWTEST_F(DataShareServiceImplTest, BundleUtilsTest001, TestSize.Level1) { -- Gitee From ba3308c7eea6f3807844127a4e61aaae74fc02ee Mon Sep 17 00:00:00 2001 From: bigteer Date: Tue, 5 Aug 2025 14:31:01 +0800 Subject: [PATCH 4/5] ACL Signed-off-by: bigteer --- .../service/common/bundle_utils.cpp | 11 ++++++++--- .../service/data_share/common/bundle_mgr_proxy.cpp | 3 ++- .../service/rdb/rdb_service_impl.cpp | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/services/distributeddataservice/service/common/bundle_utils.cpp b/services/distributeddataservice/service/common/bundle_utils.cpp index 08a96a16b..f722d9d85 100644 --- a/services/distributeddataservice/service/common/bundle_utils.cpp +++ b/services/distributeddataservice/service/common/bundle_utils.cpp @@ -25,14 +25,19 @@ BundleUtils &BundleUtils::GetInstance() void BundleUtils::SetBundleInfoCallback(Callback callback) { std::lock_guard lock(lock_); - bundleInfoCallback_ = callback; + bundleInfoCallback_ = std::move(callback); } std::pair BundleUtils::CheckSilentConfig(const std::string &bundleName, int32_t userId) { - if (bundleInfoCallback_ == nullptr) { + Callback callback; + { + std::lock_guard lock(lock_); + callback = bundleInfoCallback_; + } + if (callback == nullptr) { return std::make_pair(-1, false); } - return bundleInfoCallback_(bundleName, userId); + return callback(bundleName, userId); } } \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/common/bundle_mgr_proxy.cpp b/services/distributeddataservice/service/data_share/common/bundle_mgr_proxy.cpp index 34f5feb23..843b53d15 100644 --- a/services/distributeddataservice/service/data_share/common/bundle_mgr_proxy.cpp +++ b/services/distributeddataservice/service/data_share/common/bundle_mgr_proxy.cpp @@ -296,7 +296,8 @@ std::pair BundleMgrProxy::CheckSilentConfig(const std::string &bundle AppExecFwk::BundleInfo bundleInfo; auto bmsClient = GetBundleMgrProxy(); if (bmsClient == nullptr) { - ZLOGE("GetBundleMgrProxy is nullptr!"); + ZLOGE( + "GetBundleMgrProxy is nullptr! bundleName is %{public}s, userId is %{public}d", bundleName.c_str(), userId); return std::make_pair(E_BMS_NOT_READY, false); } diff --git a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp index f1502e68b..b15d17ed8 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp +++ b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp @@ -888,7 +888,7 @@ int32_t RdbServiceImpl::BeforeOpen(RdbSyncerParam ¶m) param.isNeedSetAcl_ = true; return RDB_OK; } - auto [err, flag] = BundleUtils::GetInstance().CheckSilentConfig(meta.bundleName, std::stoi(meta.user)); + auto [err, flag] = BundleUtils::GetInstance().CheckSilentConfig(meta.bundleName, std::atoi(meta.user.c_str())); param.isNeedSetAcl_ = flag; return RDB_OK; } -- Gitee From 7bc8a2f6290c51fa524e8946663c9a46ff653432 Mon Sep 17 00:00:00 2001 From: bigteer Date: Wed, 6 Aug 2025 11:50:19 +0800 Subject: [PATCH 5/5] ACL update Signed-off-by: bigteer --- services/distributeddataservice/service/rdb/rdb_service_impl.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp index b15d17ed8..228d33ab1 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp +++ b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp @@ -881,6 +881,7 @@ int32_t RdbServiceImpl::BeforeOpen(RdbSyncerParam ¶m) return RDB_NO_META; } SetReturnParam(meta, param); + // there is no need to set acl, path is has acl if (param.isNeedSetAcl_) { return RDB_OK; } -- Gitee