From e253b9f03c7b42137156f95d91c1d097556abe8d Mon Sep 17 00:00:00 2001 From: Cuiziyuan Date: Sat, 7 Jun 2025 22:50:59 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9B=E5=BB=BAhelper=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E9=9D=99=E9=BB=98=E4=BD=BF=E8=83=BD=E5=BC=80=E5=85=B3=E6=97=B6?= =?UTF-8?q?=E6=97=A0=E9=9C=80=E6=9F=A5=E8=AF=A2=E5=85=83=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Cuiziyuan --- .../data_share/data_provider_config.cpp | 6 ++++ .../data_share/data_share_service_impl.cpp | 15 ---------- .../test/data_share_service_impl_test.cpp | 30 +++++++++++++++++-- 3 files changed, 34 insertions(+), 17 deletions(-) diff --git a/services/distributeddataservice/service/data_share/data_provider_config.cpp b/services/distributeddataservice/service/data_share/data_provider_config.cpp index 74a7630fb..11c5328cf 100644 --- a/services/distributeddataservice/service/data_share/data_provider_config.cpp +++ b/services/distributeddataservice/service/data_share/data_provider_config.cpp @@ -42,6 +42,12 @@ DataProviderConfig::DataProviderConfig(const std::string &uri, uint32_t callerTo LoadConfigCommonStrategy::GetInfoFromProxyURI(providerInfo_.uri, providerInfo_.visitedUserId, callerTokenId, providerInfo_.bundleName); URIUtils::FormatUri(providerInfo_.uri); + // if visitedUserId is 0, set current foreground userId as visitedUserId + if (providerInfo_.visitedUserId == 0) { + if (!(AccountDelegate::GetInstance()->QueryForegroundUserId(providerInfo_.visitedUserId))) { + ZLOGE("Get foreground userId failed"); + } + } } else { auto [success, data] = URIUtils::GetUserFromProxyURI(providerInfo_.uri); if (success) { 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 36a7c21f0..6c30e699c 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp @@ -1092,21 +1092,6 @@ int32_t DataShareServiceImpl::GetBMSAndMetaDataStatus(const std::string &uri, co errCode, URIUtils::Anonymous(calledInfo.uri).c_str()); return errCode; } - DataShareDbConfig dbConfig; - DataShareDbConfig::DbConfig dbArg; - dbArg.uri = calledInfo.uri; - dbArg.bundleName = calledInfo.bundleName; - dbArg.storeName = calledInfo.storeName; - dbArg.userId = calledInfo.singleton ? 0 : calledInfo.visitedUserId; - dbArg.hasExtension = calledInfo.hasExtension; - dbArg.appIndex = calledInfo.appIndex; - auto [code, metaData] = dbConfig.GetMetaData(dbArg); - if (code != E_OK) { - ZLOGE("Get metaData fail,bundleName:%{public}s,tableName:%{public}s,tokenId:0x%{public}x, uri:%{public}s", - calledInfo.bundleName.c_str(), calledInfo.tableName.c_str(), tokenId, - URIUtils::Anonymous(calledInfo.uri).c_str()); - return E_METADATA_NOT_EXISTS; - } return E_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 65f79e4d5..a4c51e60c 100644 --- a/services/distributeddataservice/service/test/data_share_service_impl_test.cpp +++ b/services/distributeddataservice/service/test/data_share_service_impl_test.cpp @@ -44,16 +44,18 @@ public: static constexpr int64_t USER_TEST = 100; static constexpr int64_t TEST_SUB_ID = 100; static constexpr uint32_t CUREEENT_USER_ID = 123; + static constexpr uint32_t NATIVE_USER_ID = 0; static void SetUpTestCase(void){}; static void TearDownTestCase(void){}; + void SetSelfTokenInfo(int32_t user); void SetUp(); void TearDown(); }; -void DataShareServiceImplTest::SetUp(void) +void DataShareServiceImplTest::SetSelfTokenInfo(int32_t user) { HapInfoParams info = { - .userID = USER_TEST, + .userID = user, .bundleName = "ohos.datasharetest.demo", .instIndex = 0, .appIDDesc = "ohos.datasharetest.demo" @@ -88,6 +90,10 @@ void DataShareServiceImplTest::SetUp(void) info.userID, info.bundleName, info.instIndex); SetSelfTokenID(testTokenId); } +void DataShareServiceImplTest::SetUp(void) +{ + SetSelfTokenInfo(USER_TEST); +} void DataShareServiceImplTest::TearDown(void) { @@ -491,4 +497,24 @@ HWTEST_F(DataShareServiceImplTest, GetCallerInfo002, TestSize.Level1) EXPECT_EQ(result.first, false); ZLOGI("DataShareServiceImplTest GetCallerInfo002 end"); } + +/** +* @tc.name: GetSilentProxyStatus001 +* @tc.desc: test GetSilentProxyStatus001 function while creating helper +* @tc.type: FUNC +* @tc.require: +*/ +HWTEST_F(DataShareServiceImplTest, GetSilentProxyStatus001, TestSize.Level1) +{ + ZLOGI("DataShareServiceImplTest GetSilentProxyStatus001 start"); + SetSelfTokenInfo(NATIVE_USER_ID); + DataShareServiceImpl dataShareServiceImpl; + auto result = dataShareServiceImpl.GetSilentProxyStatus(SLIENT_ACCESS_URI, true); + EXPECT_EQ(result, OHOS::DataShare::E_OK); + + result = dataShareServiceImpl.GetSilentProxyStatus(SLIENT_ACCESS_URI + "?user=100", true); + EXPECT_EQ(result, OHOS::DataShare::E_OK); + SetSelfTokenInfo(USER_TEST); + ZLOGI("DataShareServiceImplTest GetSilentProxyStatus001 end"); +} } // namespace OHOS::Test \ No newline at end of file -- Gitee