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 c92cd6cb7e4b0c375edbac1eb04a0b5ebed754b8..71a491827fa4c12128e039d954e26e5d2a72e7d2 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 a705d6057e264d75adbca39c1c5bcea925ec7f9f..df0b630711166d9537461848422b9f3427c77fc7 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 cada115572ba23af21b9e469b705d73b440987ce..7a417f7a86eb1d91ceb44025bdeaa1537f4217b2 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