From db9d99e415db25b12c1ebe315dfba53063e0c332 Mon Sep 17 00:00:00 2001 From: AXYChen Date: Wed, 21 May 2025 15:06:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=89=E5=85=A8=E6=8E=A7=E4=BB=B6=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0data=E6=89=93=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: AXYChen Change-Id: I3d4640a1c0dd3457711313763617753c76941856 --- .../sa/sa_main/first_use_dialog.cpp | 29 +++++++++++++++++++ .../sa/sa_main/first_use_dialog.h | 2 ++ .../unittest/src/first_use_dialog_test.cpp | 13 +++++++++ 3 files changed, 44 insertions(+) diff --git a/services/security_component_service/sa/sa_main/first_use_dialog.cpp b/services/security_component_service/sa/sa_main/first_use_dialog.cpp index c92cd6c..71a4918 100644 --- a/services/security_component_service/sa/sa_main/first_use_dialog.cpp +++ b/services/security_component_service/sa/sa_main/first_use_dialog.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include "ability_manager_client.h" @@ -37,11 +38,13 @@ namespace Security { namespace SecurityComponent { namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_SECURITY_COMPONENT, "FirstUseDialog"}; +static const std::string SECURITY_COMPONENT_MANAGER = "security_component_manager"; static const std::string SEC_COMP_SRV_CFG_PATH = "/data/service/el1/public/security_component_service"; static const std::string FIRST_USE_RECORD_JSON = SEC_COMP_SRV_CFG_PATH + "/first_use_record.json"; static const std::string FIRST_USE_RECORD_TAG = "FirstUseRecord"; static const std::string TOKEN_ID_TAG = "TokenId"; static const std::string COMP_TYPE_TAG = "CompType"; +static const char* DATA_FOLDER = "/data"; const std::string GRANT_ABILITY_BUNDLE_NAME = "com.ohos.permissionmanager"; const std::string GRANT_ABILITY_ABILITY_NAME = "com.ohos.permissionmanager.SecurityExtAbility"; @@ -61,6 +64,29 @@ constexpr uint64_t SAVE_BUTTON_FIRST_USE = 1 << 1; static std::mutex g_instanceMutex; } +bool ReportUserData(const std::string filePath) +{ + struct stat fileInfo; + if (stat(filePath.c_str(), &fileInfo) != 0) { + SC_LOG_ERROR(LABEL, "Failed to get file stat, path = %{public}s.", filePath.c_str()); + return false; + } + uint64_t fileSize = fileInfo.st_size; + + struct statfs stat; + if (statfs(DATA_FOLDER, &stat) != 0) { + SC_LOG_ERROR(LABEL, "Failed to get data remain size."); + return false; + } + uint64_t remainSize = static_cast(stat.f_bfree) * stat.f_bsize; + + HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::FILEMANAGEMENT, "USER_DATA_SIZE", + HiviewDFX::HiSysEvent::EventType::STATISTIC, "COMPONENT_NAME", SECURITY_COMPONENT_MANAGER, + "PARTITION_NAME", DATA_FOLDER, "REMAIN_PARTITION_SIZE", remainSize, + "FILE_OR_FOLDER_PATH", filePath, "FILE_OR_FOLDER_SIZE", fileSize); + return true; +} + void SecCompDialogSrvCallback::OnDialogClosed(int32_t result) { SC_LOG_INFO(LABEL, "Call dialog close callback scId_ %{public}d", scId_); @@ -255,6 +281,9 @@ void FirstUseDialog::SaveFirstUseRecord(void) jsonRes[FIRST_USE_RECORD_TAG] = recordsJson; } + if (!ReportUserData(FIRST_USE_RECORD_JSON)) { + SC_LOG_ERROR(LABEL, "report user data failed."); + } WriteCfgContent(jsonRes.dump()); } diff --git a/services/security_component_service/sa/sa_main/first_use_dialog.h b/services/security_component_service/sa/sa_main/first_use_dialog.h index a705d60..df0b630 100644 --- a/services/security_component_service/sa/sa_main/first_use_dialog.h +++ b/services/security_component_service/sa/sa_main/first_use_dialog.h @@ -33,6 +33,8 @@ namespace OHOS { namespace Security { namespace SecurityComponent { +bool ReportUserData(const std::string filePath); + class SecCompDialogSrvCallback : public SecCompDialogCallbackStub { public: explicit SecCompDialogSrvCallback(int32_t scId, std::shared_ptr sc, diff --git a/services/security_component_service/sa/test/unittest/src/first_use_dialog_test.cpp b/services/security_component_service/sa/test/unittest/src/first_use_dialog_test.cpp index cada115..7a417f7 100644 --- a/services/security_component_service/sa/test/unittest/src/first_use_dialog_test.cpp +++ b/services/security_component_service/sa/test/unittest/src/first_use_dialog_test.cpp @@ -33,6 +33,7 @@ static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { static const std::string SEC_COMP_SRV_CFG_PATH = "/data/service/el1/public/security_component_service"; static const std::string SEC_COMP_SRV_CFG_FILE = SEC_COMP_SRV_CFG_PATH + "/" + "first_use_record.json"; static const std::string SEC_COMP_SRV_CFG_BACK_FILE = SEC_COMP_SRV_CFG_PATH + "/" + "first_use_record.json.bak"; +static const std::string INVALID_PATH = "/invalid_path"; constexpr uint64_t LOCATION_BUTTON_FIRST_USE = 1 << 0; constexpr uint64_t SAVE_BUTTON_FIRST_USE = 1 << 1; } @@ -83,6 +84,18 @@ void FirstUseDialogTest::TearDown() system(cmdline.c_str()); } +/** + * @tc.name: LoadFirstUseRecord001 + * @tc.desc: Test cfg file not exist + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(FirstUseDialogTest, ReportUserData001, TestSize.Level0) +{ + ASSERT_EQ(false, ReportUserData(SEC_COMP_SRV_CFG_FILE)); + ASSERT_EQ(false, ReportUserData(INVALID_PATH)); +} + /** * @tc.name: LoadFirstUseRecord001 * @tc.desc: Test cfg file not exist -- Gitee