diff --git a/hisysevent.yaml b/hisysevent.yaml index 81e37c37c65e4c97195d0b7a00dafee30e10b546..ec35c0b7d9fbef4cbaa6a239b74da24f83e519d3 100644 --- a/hisysevent.yaml +++ b/hisysevent.yaml @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2024 Huawei Device Co., Ltd. +# Copyright (c) 2021-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 @@ -496,4 +496,12 @@ ATOMIC_SERVICE_DRAWN_COMPLETE: SHARE_UNPRIVILEGED_FILE_URI: __BASE: {type: BEHAVIOR, level: MINOR, desc: share unprivileged file uri} CALLER_BUNDLE_NAME: {type: STRING, desc: caller bundle name} - BUNDLE_NAME: {type: STRING, desc: bundle name} \ No newline at end of file + BUNDLE_NAME: {type: STRING, desc: bundle name} + +USER_DATA_SIZE: + __BASE: {type: STATISTIC, level: CRITICAL , desc: data partition management} + COMPONENT_NAME: {type: STRING, desc: name of component} + PARTITION_NAME: {type: STRING, desc: name of partition} + REMAIN_PARTITION_SIZE: {type: UINT64, desc: Remaining size of the partition} + FILE_OR_FOLDER_PATH: {type: STRING, arrsize: 100, desc: File or folder path} + FILE_OR_FOLDER_SIZE: {type: UINT64, arrsize: 100, desc: File or folder size} \ No newline at end of file diff --git a/services/abilitymgr/abilitymgr.gni b/services/abilitymgr/abilitymgr.gni index 3f646c121f6c11eb390b711b87e6bcc8b1721f33..19412dc8ace4f891a891f95cbc0030b70afcdf5a 100644 --- a/services/abilitymgr/abilitymgr.gni +++ b/services/abilitymgr/abilitymgr.gni @@ -141,6 +141,9 @@ abilityms_files = [ #sa interceptor "src/sa_interceptor_manager.cpp", + #report data + "src/report_data_partition_usage_manager.cpp", + # keep alive "src/keep_alive/ability_keep_alive_data_manager.cpp", "src/keep_alive/ability_keep_alive_service.cpp", diff --git a/services/abilitymgr/include/report_data_partition_usage_manager.h b/services/abilitymgr/include/report_data_partition_usage_manager.h new file mode 100644 index 0000000000000000000000000000000000000000..a6d7b2c4ef01e71aeb3295764d26944a2b0710ee --- /dev/null +++ b/services/abilitymgr/include/report_data_partition_usage_manager.h @@ -0,0 +1,37 @@ +/* + * 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_ABILITY_RUNTIME_REPORT_DATA_PARTITION_USAGE_MANAGER_H +#define OHOS_ABILITY_RUNTIME_REPORT_DATA_PARTITION_USAGE_MANAGER_H + +#include "event_report.h" + +namespace OHOS { +namespace AbilityRuntime { +using namespace OHOS::AAFwk; +class ReportDataPartitionUsageManager { +public: + static void SendReportDataPartitionUsageEvent(); + +private: + static void HandleSendReportDataPartitionUsageEvent(); + static void GenerateEventInfo(EventInfo &eventInfo); + static uint64_t GetFilePathSize(const std::string &filePath); + static uint64_t GetPartitionRemainSize(const std::string &filePath); + static bool IsExistPath(const std::string &filePath); +}; +} // namespace AbilityRuntime +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_REPORT_DATA_PARTITION_USAGE_MANAGER_H \ No newline at end of file diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index 016d2cdb4dc169fc82d9771b234430e1ec791b25..870dd6838d772c8c6cd92e36757567ed674da153 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -78,8 +78,9 @@ #include "os_account_manager_wrapper.h" #include "permission_constants.h" #include "process_options.h" -#include "recovery_param.h" #include "rate_limiter.h" +#include "recovery_param.h" +#include "report_data_partition_usage_manager.h" #include "res_sched_util.h" #include "restart_app_manager.h" #include "scene_board_judgement.h" @@ -433,6 +434,7 @@ bool AbilityManagerService::Init() insightIntentEventMgr_ = std::make_shared(); insightIntentEventMgr_->SubscribeSysEventReceiver(); abilityEventHelper_ = std::make_shared(taskHandler_); + ReportDataPartitionUsageManager::SendReportDataPartitionUsageEvent(); TAG_LOGI(AAFwkTag::ABILITYMGR, "init success"); return true; } diff --git a/services/abilitymgr/src/report_data_partition_usage_manager.cpp b/services/abilitymgr/src/report_data_partition_usage_manager.cpp new file mode 100644 index 0000000000000000000000000000000000000000..605125774dd62d8e9a98a39c8d3417d2361b5b8f --- /dev/null +++ b/services/abilitymgr/src/report_data_partition_usage_manager.cpp @@ -0,0 +1,110 @@ +/* + * 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 "report_data_partition_usage_manager.h" + +#include +#include + +#include "directory_ex.h" +#include "ffrt.h" +#include "global_constant.h" +#include "hilog_tag_wrapper.h" + +namespace OHOS { +namespace AbilityRuntime { +static const std::string COMPONENT_NAME = "ability_runtime"; +static const std::string USER_DATA_DIR = "/data"; +static const uint64_t UNITS = 1024; +static const uint64_t INVALID_SIZE = 0; +static const uint64_t SECONDS_PER_DAY = 24 * 60 * 60; +static const uint64_t ONE_DAY_US = SECONDS_PER_DAY * 1000 * 1000; +static std::vector pathList_ = { + "/data/service/el1/public/database/auto_startup_service", + "/data/service/el1/public/database/app_exit_reason", + "/data/service/el1/public/database/keep_alive_service", + "/data/service/el1/public/database/ability_manager_service", + "/data/service/el1/public/database/app_config_data" +}; + +void ReportDataPartitionUsageManager::SendReportDataPartitionUsageEvent() +{ + ffrt::submit(HandleSendReportDataPartitionUsageEvent, + ffrt::task_attr().delay(ONE_DAY_US).name("SendReportDataPartitionUsageTask") + .timeout(AbilityRuntime::GlobalConstant::DEFAULT_FFRT_TASK_TIMEOUT)); +} + +void ReportDataPartitionUsageManager::HandleSendReportDataPartitionUsageEvent() +{ + EventInfo eventInfo; + GenerateEventInfo(eventInfo); + EventReport::SendReportDataPartitionUsageEvent(EventName::USER_DATA_SIZE, + HiSysEventType::STATISTIC, eventInfo); + + ffrt::submit(HandleSendReportDataPartitionUsageEvent, + ffrt::task_attr().delay(ONE_DAY_US).name("SendReportDataPartitionUsageTask") + .timeout(AbilityRuntime::GlobalConstant::DEFAULT_FFRT_TASK_TIMEOUT)); +} + +void ReportDataPartitionUsageManager::GenerateEventInfo(EventInfo &eventInfo) +{ + std::vector fileOrFolderSize; + for (auto &path : pathList_) { + fileOrFolderSize.emplace_back(GetFilePathSize(path)); + } + + eventInfo.componentName = COMPONENT_NAME; + eventInfo.partitionName = USER_DATA_DIR; + eventInfo.remainPartitionSize = GetPartitionRemainSize(USER_DATA_DIR); + eventInfo.fileOfFolderPath = pathList_; + eventInfo.fileOfFolderSize = fileOrFolderSize; +} + +uint64_t ReportDataPartitionUsageManager::GetFilePathSize(const std::string &filePath) +{ + return OHOS::GetFolderSize(filePath); +} + +uint64_t ReportDataPartitionUsageManager::GetPartitionRemainSize(const std::string &filePath) +{ + if (!IsExistPath(filePath)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "file path not exist"); + return INVALID_SIZE; + } + + struct statvfs stst; + if (statvfs(filePath.c_str(), &stst) != 0) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "failed to get space info for path %{public}s", filePath.c_str()); + return INVALID_SIZE; + } + return (static_cast(stst.f_bfree) / UNITS) * (static_cast(stst.f_bsize) / UNITS); +} + +bool ReportDataPartitionUsageManager::IsExistPath(const std::string &filePath) +{ + if (filePath.empty()) { + return false; + } + + struct stat result = {}; + if (stat(filePath.c_str(), &result) != 0) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "fail stat error"); + return false; + } + + return true; +} +} // namespace AbilityRuntime +} // namespace OHOS \ No newline at end of file diff --git a/services/common/BUILD.gn b/services/common/BUILD.gn index 6a3961d796bd9f994c4189879256825ee93a2846..38e27c8bdebc38c082dfaa95ff731c0e00a28007 100644 --- a/services/common/BUILD.gn +++ b/services/common/BUILD.gn @@ -1,5 +1,5 @@ # -# Copyright (c) 2024 Huawei Device Co., Ltd. +# Copyright (c) 2024-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 @@ -88,6 +88,11 @@ ohos_shared_library("event_report") { public_configs = [ ":common_config" ] + defines = [] + if (current_cpu == "arm64") { + defines += [ "USE_EXTENSION_DATA" ] + } + sources = [ "src/event_report.cpp" ] external_deps = [ diff --git a/services/common/include/event_report.h b/services/common/include/event_report.h index d0b77a4366632794494330a8dd380e500798b10e..1a24eac424a0041f3c7d040f6e32c7c0bfa2be2f 100644 --- a/services/common/include/event_report.h +++ b/services/common/include/event_report.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-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 @@ -66,6 +66,11 @@ struct EventInfo { std::string lifeCycle; std::string intentName; std::string errMsg; + std::string componentName; + std::string partitionName; + uint64_t remainPartitionSize; + std::vector fileOfFolderPath; + std::vector fileOfFolderSize; }; enum class EventName { @@ -124,7 +129,10 @@ enum class EventName { ATOMIC_SERVICE_DRAWN_COMPLETE, // uri permission - SHARE_UNPRIVILEGED_FILE_URI + SHARE_UNPRIVILEGED_FILE_URI, + + // report data + USER_DATA_SIZE }; class EventReport { @@ -148,6 +156,8 @@ public: static void SendGrantUriPermissionEvent(const EventName &eventName, const EventInfo &eventInfo); static void SendExecuteIntentEvent(const EventName &eventName, HiSysEventType type, const EventInfo &eventInfo); static void SendLaunchFrameworkEvent(const EventName &eventName, HiSysEventType type, const EventInfo &eventInfo); + static void SendReportDataPartitionUsageEvent(const EventName &eventName, HiSysEventType type, + const EventInfo &eventInfo); private: static std::string ConvertEventName(const EventName &eventName); diff --git a/services/common/src/event_report.cpp b/services/common/src/event_report.cpp index 0d66f98814882bf09bce9232a724235c330af943..db9d3b6a5254b555066ee8b7972bcac21444acd8 100644 --- a/services/common/src/event_report.cpp +++ b/services/common/src/event_report.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-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 @@ -66,6 +66,11 @@ constexpr const char *EVENT_KEY_LIFE_CYCLE = "LIFE_CYCLE"; constexpr const char *EVENT_KEY_PERSISTENT_ID = "PERSISTENT_ID"; constexpr const char *EVENT_KEY_INTENT_NAME = "INTENT_NAME"; constexpr const char *EVENT_KEY_ERROR_MESSAGE = "ERROR_MESSAGE"; +constexpr const char *EVENT_FILE_OR_FOLDER_PATH = "FILE_OR_FOLDER_PATH"; +constexpr const char *EVENT_FILE_OR_FOLDER_SIZE = "FILE_OR_FOLDER_SIZE"; +constexpr const char *EVENT_COMPONENT_NAME_KEY = "COMPONENT_NAME"; +constexpr const char *EVENT_PARTITION_NAME_KEY = "PARTITION_NAME"; +constexpr const char *EVENT_REMAIN_PARTITION_SIZE_KEY = "REMAIN_PARTITION_SIZE"; constexpr const int32_t DEFAULT_EXTENSION_TYPE = -1; } @@ -803,6 +808,30 @@ void EventReport::SendLaunchFrameworkEvent(const EventName &eventName, HiSysEven EVENT_KEY_ERR_REASON, eventInfo.errReason); } +void EventReport::SendReportDataPartitionUsageEvent(const EventName &eventName, HiSysEventType type, + const EventInfo &eventInfo) +{ + std::string name = ConvertEventName(eventName); + if (name == INVALID_EVENT_NAME) { + TAG_LOGE(AAFwkTag::DEFAULT, "invalid eventName"); + return; + } + + HiSysEventWrite( +#ifdef USE_EXTENSION_DATA + OHOS::HiviewDFX::HiSysEvent::Domain::FILEMANAGEMENT, +#else + OHOS::HiviewDFX::HiSysEvent::Domain::AAFWK, +#endif + name, + type, + EVENT_COMPONENT_NAME_KEY, eventInfo.componentName, + EVENT_PARTITION_NAME_KEY, eventInfo.partitionName, + EVENT_REMAIN_PARTITION_SIZE_KEY, eventInfo.remainPartitionSize, + EVENT_FILE_OR_FOLDER_PATH, eventInfo.fileOfFolderPath, + EVENT_FILE_OR_FOLDER_SIZE, eventInfo.fileOfFolderSize); +} + std::string EventReport::ConvertEventName(const EventName &eventName) { const char* eventNames[] = { @@ -833,7 +862,10 @@ std::string EventReport::ConvertEventName(const EventName &eventName) "CREATE_ATOMIC_SERVICE_PROCESS", "ATOMIC_SERVICE_DRAWN_COMPLETE", // uri permission - "SHARE_UNPRIVILEGED_FILE_URI" + "SHARE_UNPRIVILEGED_FILE_URI", + + // report data + "USER_DATA_SIZE" }; uint32_t eventIndex = static_cast (eventName); if (eventIndex >= sizeof(eventNames) / sizeof(const char*)) { diff --git a/test/unittest/ability_manager_service_fourteenth_test/BUILD.gn b/test/unittest/ability_manager_service_fourteenth_test/BUILD.gn index 5728c0916d6161c32ec2cfef76beeb7fef631f5e..d8606c87fee9a046771d9638ead64e93a42bcde4 100644 --- a/test/unittest/ability_manager_service_fourteenth_test/BUILD.gn +++ b/test/unittest/ability_manager_service_fourteenth_test/BUILD.gn @@ -162,6 +162,7 @@ ohos_unittest("ability_manager_service_fourteenth_test") { "${ability_runtime_services_path}/abilitymgr/src/rdb/rdb_data_manager.cpp", "${ability_runtime_services_path}/abilitymgr/src/recovery_info_timer.cpp", "${ability_runtime_services_path}/abilitymgr/src/remote_mission_listener_proxy.cpp", + "${ability_runtime_services_path}/abilitymgr/src/report_data_partition_usage_manager.cpp", "${ability_runtime_services_path}/abilitymgr/src/resident_process/resident_process_manager.cpp", "${ability_runtime_services_path}/abilitymgr/src/restart_app_manager.cpp", "${ability_runtime_services_path}/abilitymgr/src/sa_interceptor_manager.cpp", diff --git a/test/unittest/ability_manager_service_second_test/BUILD.gn b/test/unittest/ability_manager_service_second_test/BUILD.gn index 66bf430e809f922e4ab733ed8e6ac92944330dc4..ae8fc18dad3a4773b1c083632831a98de7cace57 100644 --- a/test/unittest/ability_manager_service_second_test/BUILD.gn +++ b/test/unittest/ability_manager_service_second_test/BUILD.gn @@ -167,6 +167,7 @@ ohos_unittest("ability_manager_service_second_test") { "${ability_runtime_services_path}/abilitymgr/src/rdb/rdb_data_manager.cpp", "${ability_runtime_services_path}/abilitymgr/src/recovery_info_timer.cpp", "${ability_runtime_services_path}/abilitymgr/src/remote_mission_listener_proxy.cpp", + "${ability_runtime_services_path}/abilitymgr/src/report_data_partition_usage_manager.cpp", "${ability_runtime_services_path}/abilitymgr/src/resident_process/resident_process_manager.cpp", "${ability_runtime_services_path}/abilitymgr/src/restart_app_manager.cpp", "${ability_runtime_services_path}/abilitymgr/src/sa_interceptor_manager.cpp", diff --git a/test/unittest/ability_manager_service_third_test/BUILD.gn b/test/unittest/ability_manager_service_third_test/BUILD.gn index f309cd0d53ff497c6cd65cd1688ac4b1b3807f82..a12cdf3abf1b832a14a844903b4d5eca39a959a0 100644 --- a/test/unittest/ability_manager_service_third_test/BUILD.gn +++ b/test/unittest/ability_manager_service_third_test/BUILD.gn @@ -52,6 +52,7 @@ ohos_unittest("ability_manager_service_third_test") { "${ability_runtime_services_path}/common/src/queue_task_handler_wrap.cpp", "${ability_runtime_services_path}/common/src/task_handler_wrap.cpp", "${ability_runtime_services_path}/abilitymgr/src/ability_manager_service.cpp", + "${ability_runtime_services_path}/abilitymgr/src/report_data_partition_usage_manager.cpp", ] sources += abilityms_files diff --git a/test/unittest/ability_manager_service_thirteenth_test/BUILD.gn b/test/unittest/ability_manager_service_thirteenth_test/BUILD.gn index 1881b08121097918669079afce8c669c5c890f4f..036507ebda72d9e910b76f76ee4a2b27ab113b56 100644 --- a/test/unittest/ability_manager_service_thirteenth_test/BUILD.gn +++ b/test/unittest/ability_manager_service_thirteenth_test/BUILD.gn @@ -163,6 +163,7 @@ ohos_unittest("ability_manager_service_thirteenth_test") { "${ability_runtime_services_path}/abilitymgr/src/rdb/rdb_data_manager.cpp", "${ability_runtime_services_path}/abilitymgr/src/recovery_info_timer.cpp", "${ability_runtime_services_path}/abilitymgr/src/remote_mission_listener_proxy.cpp", + "${ability_runtime_services_path}/abilitymgr/src/report_data_partition_usage_manager.cpp", "${ability_runtime_services_path}/abilitymgr/src/resident_process/resident_process_manager.cpp", "${ability_runtime_services_path}/abilitymgr/src/restart_app_manager.cpp", "${ability_runtime_services_path}/abilitymgr/src/sa_interceptor_manager.cpp", diff --git a/test/unittest/event_report_test/event_report_test.cpp b/test/unittest/event_report_test/event_report_test.cpp index 32eb8b2f81f8ea06e12b6d3c281d59bb72820060..d18f26a4a5442c7dc3ff5e13f47dcea81d7658a4 100755 --- a/test/unittest/event_report_test/event_report_test.cpp +++ b/test/unittest/event_report_test/event_report_test.cpp @@ -97,6 +97,7 @@ HWTEST_F(EventReportTest, ConvertEventName_0100, TestSize.Level2) "ATOMIC_SERVICE_DRAWN_COMPLETE"); EXPECT_EQ(EventReport::ConvertEventName(EventName::SHARE_UNPRIVILEGED_FILE_URI), "SHARE_UNPRIVILEGED_FILE_URI"); + EXPECT_EQ(EventReport::ConvertEventName(EventName::USER_DATA_SIZE), "USER_DATA_SIZE"); } /** @@ -732,5 +733,21 @@ HWTEST_F(EventReportTest, SendAtomicServiceEvent_0100, TestSize.Level2) EXPECT_EQ(EventReport::ConvertEventName(eventName), "ATOMIC_SERVICE_DRAWN_COMPLETE"); EventReport::SendAtomicServiceEvent(eventName, type, eventInfo); } + +/** + * @tc.name: SendReportDataPartitionUsageEvent_0100 + * @tc.desc: Check SendReportDataPartitionUsageEvent Test + * @tc.type: FUNC + */ +HWTEST_F(EventReportTest, SendReportDataPartitionUsageEvent_0100, TestSize.Level1) +{ + EventName eventName = static_cast(-1); + EXPECT_EQ(EventReport::ConvertEventName(eventName), "INVALIDEVENTNAME"); + EventInfo eventInfo; + EventReport::SendReportDataPartitionUsageEvent(eventName, HiSysEventType::STATISTIC, eventInfo); + eventName = EventName::USER_DATA_SIZE; + EXPECT_EQ(EventReport::ConvertEventName(eventName), "USER_DATA_SIZE"); + EventReport::SendReportDataPartitionUsageEvent(eventName, HiSysEventType::STATISTIC, eventInfo); +} } // namespace AAFwk } // namespace OHOS diff --git a/test/unittest/report_data_partition_usage_manager_test/BUILD.gn b/test/unittest/report_data_partition_usage_manager_test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..02ab9750d35b449ed2aa9d86d568a5843dd40575 --- /dev/null +++ b/test/unittest/report_data_partition_usage_manager_test/BUILD.gn @@ -0,0 +1,77 @@ +# 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. + +import("//build/test.gni") +import("//foundation/ability/ability_runtime/ability_runtime.gni") + +module_output_path = "ability_runtime/ability_runtime/abilitymgr" + +ohos_unittest("report_data_partition_usage_manager_test") { + module_out_path = module_output_path + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + include_dirs = [ "${ability_runtime_services_path}/abilitymgr/include" ] + + sources = [ + "${ability_runtime_services_path}/abilitymgr/src/report_data_partition_usage_manager.cpp", + "report_data_partition_usage_manager_test.cpp", + ] + + configs = [ "${ability_runtime_services_path}/abilitymgr:abilityms_config" ] + + deps = [ + "${ability_runtime_innerkits_path}/ability_manager:ability_manager", + "${ability_runtime_innerkits_path}/ability_manager:ability_start_options", + "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_services_path}/abilitymgr:abilityms", + "${ability_runtime_services_path}/abilitymgr:wantagent_manager", + "${ability_runtime_services_path}/common:event_report", + "${ability_runtime_services_path}/common:perm_verification", + "${ability_runtime_services_path}/common:task_handler_wrap", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "ability_runtime:ability_manager", + "access_token:libaccesstoken_sdk", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "common_event_service:cesfwk_innerkits", + "eventhandler:libeventhandler", + "ffrt:libffrt", + "googletest:gmock_main", + "googletest:gtest_main", + "hilog:libhilog", + "hisysevent:libhisysevent", + "hitrace:hitrace_meter", + "ipc:ipc_core", + "napi:ace_napi", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] + + if (background_task_mgr_continuous_task_enable) { + external_deps += [ "background_task_mgr:bgtaskmgr_innerkits" ] + } +} + +group("unittest") { + testonly = true + + deps = [ ":report_data_partition_usage_manager_test" ] +} diff --git a/test/unittest/report_data_partition_usage_manager_test/report_data_partition_usage_manager_test.cpp b/test/unittest/report_data_partition_usage_manager_test/report_data_partition_usage_manager_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3402000b266230cb24b16930e862792460ac424a --- /dev/null +++ b/test/unittest/report_data_partition_usage_manager_test/report_data_partition_usage_manager_test.cpp @@ -0,0 +1,135 @@ +/* + * 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 + +#define private public +#include "ability_manager_service.h" +#include "report_data_partition_usage_manager.h" +#undef private +#include "event_report.h" + +using namespace testing; +using namespace testing::ext; +using namespace OHOS::AAFwk; +namespace OHOS { +namespace AbilityRuntime { +const std::string INVALID_PATH = "/gggggg"; +const std::string PATH = "/data"; +class ReportDataPartitionUsageManagerTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); +}; + +void ReportDataPartitionUsageManagerTest::SetUpTestCase() +{ +} + +void ReportDataPartitionUsageManagerTest::TearDownTestCase() +{ +} + +void ReportDataPartitionUsageManagerTest::SetUp() +{ +} + +void ReportDataPartitionUsageManagerTest::TearDown() +{ +} + +/* + * @tc.number: GenerateEventInfo_0100 + * @tc.name: GenerateEventInfo + * @tc.desc: + */ +HWTEST_F(ReportDataPartitionUsageManagerTest, GenerateEventInfo_0100, TestSize.Level1) +{ + EventInfo eventInfo; + ReportDataPartitionUsageManager::GenerateEventInfo(eventInfo); + EXPECT_EQ(eventInfo.componentName.empty(), false); + EXPECT_EQ(eventInfo.partitionName.empty(), false); +} + +/* + * @tc.number: GetFilePathSize_0100 + * @tc.name: GetFilePathSize + * @tc.desc: + */ +HWTEST_F(ReportDataPartitionUsageManagerTest, GetFilePathSize_0100, TestSize.Level1) +{ + uint64_t size = ReportDataPartitionUsageManager::GetFilePathSize(PATH); + EXPECT_NE(size, 0); +} + +/* + * @tc.number: GetFilePathSize_0200 + * @tc.name: GetFilePathSize + * @tc.desc: + */ +HWTEST_F(ReportDataPartitionUsageManagerTest, GetFilePathSize_0200, TestSize.Level1) +{ + uint64_t size = ReportDataPartitionUsageManager::GetFilePathSize(INVALID_PATH); + EXPECT_EQ(size, 0); +} + +/* + * @tc.number: GetPartitionRemainSize_0100 + * @tc.name: GetPartitionRemainSize + * @tc.desc: + */ +HWTEST_F(ReportDataPartitionUsageManagerTest, GetPartitionRemainSize_0100, TestSize.Level1) +{ + uint64_t size = ReportDataPartitionUsageManager::GetPartitionRemainSize( + "/data/service/el1/public/database/app_config_data"); + EXPECT_NE(size, 0); +} + +/* + * @tc.number: GetPartitionRemainSize_0200 + * @tc.name: GetPartitionRemainSize + * @tc.desc: + */ +HWTEST_F(ReportDataPartitionUsageManagerTest, GetPartitionRemainSize_0200, TestSize.Level1) +{ + uint64_t size = ReportDataPartitionUsageManager::GetPartitionRemainSize(INVALID_PATH); + EXPECT_EQ(size, 0); +} + +/* + * @tc.number: IsExistPath_0100 + * @tc.name: IsExistPath + * @tc.desc: + */ +HWTEST_F(ReportDataPartitionUsageManagerTest, IsExistPath_0100, TestSize.Level1) +{ + auto result = ReportDataPartitionUsageManager::IsExistPath("/data/service/el1/public/database/app_config_data"); + EXPECT_EQ(result, true); +} + +/* + * @tc.number: IsExistPath_0200 + * @tc.name: IsExistPath + * @tc.desc: + */ +HWTEST_F(ReportDataPartitionUsageManagerTest, IsExistPath_0200, TestSize.Level1) +{ + auto result = ReportDataPartitionUsageManager::IsExistPath(INVALID_PATH); + EXPECT_EQ(result, false); +} +} // namespace AbilityRuntime +} // namespace OHOS \ No newline at end of file