From ca13fc5d18e10f7c84a6311ef058d8ab52daf084 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=A8=E5=AD=90=E6=9D=8E?= Date: Tue, 1 Jul 2025 21:21:11 +0800 Subject: [PATCH] fix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 木子李 --- .../service/test/BUILD.gn | 6 ++++ .../service/test/udmf_run_time_store_test.cpp | 31 +++++++++++++++++++ .../udmf/store/store_account_observer.cpp | 4 +++ .../udmf/store/store_account_observer.h | 1 + 4 files changed, 42 insertions(+) diff --git a/services/distributeddataservice/service/test/BUILD.gn b/services/distributeddataservice/service/test/BUILD.gn index e7d978476..6eef966b7 100644 --- a/services/distributeddataservice/service/test/BUILD.gn +++ b/services/distributeddataservice/service/test/BUILD.gn @@ -960,10 +960,16 @@ ohos_unittest("UdmfRunTimeStoreTest") { "${data_service_path}/service/udmf", "${data_service_path}/service/udmf/store", "${data_service_path}/service/udmf/preprocess", + "${data_service_path}/framework/include/directory", ] configs = [ ":module_private_config" ] + cflags = [ + "-Dprivate=public", + "-Dprotected=public", + ] + external_deps = [ "ability_base:base", "ability_base:want", diff --git a/services/distributeddataservice/service/test/udmf_run_time_store_test.cpp b/services/distributeddataservice/service/test/udmf_run_time_store_test.cpp index 71b8d5c25..01795f4b1 100644 --- a/services/distributeddataservice/service/test/udmf_run_time_store_test.cpp +++ b/services/distributeddataservice/service/test/udmf_run_time_store_test.cpp @@ -29,6 +29,8 @@ #include "runtime_store.h" #include "text.h" #include "token_setproc.h" +#include "store_account_observer.h" +#include "directory_manager.h" using namespace testing::ext; using namespace OHOS::DistributedData; @@ -706,5 +708,34 @@ HWTEST_F(UdmfRunTimeStoreTest, GetRuntime002, TestSize.Level1) auto status = store->GetRuntime(key, outRuntime); EXPECT_EQ(status, E_NOT_FOUND); } + +/** +* @tc.name: OnAccountChanged001 +* @tc.desc: Abnormal testcase of OnAccountChanged +* @tc.type: FUNC +* @tc.require: +*/ +HWTEST_F(UdmfRunTimeStoreTest, OnAccountChanged001, TestSize.Level1) +{ + RuntimeStoreAccountObserver observer; + const AccountEventInfo eventInfo = { + .status = AccountStatus::DEVICE_ACCOUNT_DELETE + }; + DistributedData::StoreMetaData metaData; + uint32_t token = IPCSkeleton::GetSelfTokenID(); + metaData.bundleName = DistributedData::Bootstrap::GetInstance().GetProcessLabel(); + metaData.appId = DistributedData::Bootstrap::GetInstance().GetProcessLabel(); + metaData.user = eventInfo.userId; + metaData.tokenId = token; + metaData.securityLevel = DistributedKv::SecurityLevel::S1; + metaData.area = DistributedKv::Area::EL1; + metaData.storeType = DistributedKv::KvStoreType::SINGLE_VERSION; + metaData.dataDir = DistributedData::DirectoryManager::GetInstance().GetStorePath(metaData); + std::string userPath = metaData.dataDir.append("/").append(eventInfo.userId); + observer.OnAccountChanged(eventInfo, 0); + EXPECT_EQ(access(userPath.c_str(), F_OK), -1); + SetSelfTokenID(0); + observer.OnAccountChanged(eventInfo, 0); +} }; // namespace DistributedDataTest }; // namespace OHOS::Test \ No newline at end of file diff --git a/services/distributeddataservice/service/udmf/store/store_account_observer.cpp b/services/distributeddataservice/service/udmf/store/store_account_observer.cpp index 9085a9b5a..dd3369a99 100644 --- a/services/distributeddataservice/service/udmf/store/store_account_observer.cpp +++ b/services/distributeddataservice/service/udmf/store/store_account_observer.cpp @@ -30,6 +30,10 @@ void RuntimeStoreAccountObserver::OnAccountChanged(const AccountEventInfo &event if (eventInfo.status == AccountStatus::DEVICE_ACCOUNT_DELETE) { DistributedData::StoreMetaData metaData; uint32_t token = IPCSkeleton::GetSelfTokenID(); + if (token == 0) { + ZLOGW("invalid token."); + return; + } metaData.bundleName = DistributedData::Bootstrap::GetInstance().GetProcessLabel(); metaData.appId = DistributedData::Bootstrap::GetInstance().GetProcessLabel(); metaData.user = eventInfo.userId; diff --git a/services/distributeddataservice/service/udmf/store/store_account_observer.h b/services/distributeddataservice/service/udmf/store/store_account_observer.h index 3d50570b9..78876da4b 100644 --- a/services/distributeddataservice/service/udmf/store/store_account_observer.h +++ b/services/distributeddataservice/service/udmf/store/store_account_observer.h @@ -19,6 +19,7 @@ namespace OHOS { namespace UDMF { class RuntimeStoreAccountObserver : public DistributedData::AccountDelegate::Observer { +private: void OnAccountChanged(const DistributedData::AccountEventInfo &eventInfo, int32_t timeout) override; // must specify unique name for observer std::string Name() override -- Gitee