diff --git a/bundle.json b/bundle.json index 662e9d1e19f2289fa4265542db14a4fa901a0cae..bfe2cd94dee5c7b421283b899b85b1387cdde261 100644 --- a/bundle.json +++ b/bundle.json @@ -44,6 +44,9 @@ ], "rom": "", "ram": "", + "hisysevent_config": [ + "//base/global/font_manager/frameworks/fontmgr/hisysevent.yaml" + ], "deps": { "components": [ "ability_base", @@ -54,6 +57,7 @@ "cJSON", "eventhandler", "hilog", + "hisysevent", "hitrace", "ipc", "napi", diff --git a/frameworks/fontmgr/fontmgr.gni b/frameworks/fontmgr/fontmgr.gni index 25194f6ea2023486ce1359780d354b3c1621552d..3bad24b03f5e9d7d94f6069845f70ad30d63073d 100644 --- a/frameworks/fontmgr/fontmgr.gni +++ b/frameworks/fontmgr/fontmgr.gni @@ -24,6 +24,7 @@ fontmgr_src = [ "$root_path/src/font_config.cpp", "$root_path/src/font_manager.cpp", "$root_path/src/font_event_publish.cpp", + "$root_path/src/hisysevent_adapter.cpp" ] fontmgr_external_deps = [ diff --git a/frameworks/fontmgr/hisysevent.yaml b/frameworks/fontmgr/hisysevent.yaml new file mode 100644 index 0000000000000000000000000000000000000000..b1f9ac9a949f0e26db90c0c92b8fc614c540235d --- /dev/null +++ b/frameworks/fontmgr/hisysevent.yaml @@ -0,0 +1,23 @@ +# 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. + +dommain: FILEMANAGEMENT + +# user data size +USER_DATA_SIZE: + __BASE: {type: STATISTIC, level: CRITICAL, desc: user data size} + COMPONENT_NAME: {type: STRING, desc: component name} + PARTITION_NAME: {type: STRING, desc: partition name} + REMAIN_PARTITION_SIZE: {type: UINT64, desc: remain partition size} + FILE_OR_FOLDER_PATH: {type: STRING, desc: file or folder path} + FILE_OR_FOLDER_SIZE: {type: STRING, desc: file or folder size} \ No newline at end of file diff --git a/frameworks/fontmgr/include/hisysevent_adapter.h b/frameworks/fontmgr/include/hisysevent_adapter.h new file mode 100644 index 0000000000000000000000000000000000000000..2bfd202b3ba4612cf7a76a1ca40ba54fbc9e903e --- /dev/null +++ b/frameworks/fontmgr/include/hisysevent_adapter.h @@ -0,0 +1,40 @@ +/* + * 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 GLOBAL_FONT_MANAGER_HISYSEVENT_ADAPTER_H +#define GLOBAL_FONT_MANAGER_HISYSEVENT_ADAPTER_H + +#include +#include + +#include "singleton.h" + +namespace OHOS { +namespace Global { +namespace FontManager { +class HisyseventAdapter : public DelayedSingleton { + DECLARE_DELAYED_SINGLETON(HisyseventAdapter); + +public: + int CollectUserDataSize(); + uint64_t GetDataPartitionRemainSize(); + std::vector GetFileOrFolderPath(); + std::vector GetFileOrFolderSize(); +}; +} // namespace FontManager +} // namespace Global +} // namespace OHOS + +#endif // GLOBAL_FONT_MANAGER_HISYSEVENT_ADAPTER_H \ No newline at end of file diff --git a/frameworks/fontmgr/src/font_manager.cpp b/frameworks/fontmgr/src/font_manager.cpp index b86f9e1ecd52874798c19bcb35cd57f601541f51..b943bc87705b7d9337b1a7814c893183a8c18c3a 100644 --- a/frameworks/fontmgr/src/font_manager.cpp +++ b/frameworks/fontmgr/src/font_manager.cpp @@ -19,6 +19,7 @@ #include "font_event_publish.h" #include "font_config.h" #include "file_utils.h" +#include "hisysevent_adpter.h" #include "SkFontMgr.h" namespace OHOS { @@ -93,6 +94,7 @@ int32_t FontManager::InstallFont(const int32_t &fd) } if (fontConfig.InsertFontRecord(destPath, fullNameVector)) { FontEventPublish::PublishFontUpdate(FontEventType::INSTALL, GetFormatFullName(fullNameVector)); + HisyseventAdapter::GetInstance()->CollectUserDataSize(); return SUCCESS; } return ERR_INSTALL_FAIL; @@ -180,6 +182,7 @@ int32_t FontManager::UninstallFont(const std::string &fontFullName) return ERR_UNINSTALL_FAIL; } FontEventPublish::PublishFontUpdate(FontEventType::UNINSTALL, fontFullName); + HisyseventAdapter::GetInstance()->CollectUserDataSize(); return SUCCESS; } } // namespace FontManager diff --git a/frameworks/fontmgr/src/hisysevent_adapter.cpp b/frameworks/fontmgr/src/hisysevent_adapter.cpp new file mode 100644 index 0000000000000000000000000000000000000000..75b8ecbbc5143fa4da9f8b6c20a8e042aeff27e7 --- /dev/null +++ b/frameworks/fontmgr/src/hisysevent_adapter.cpp @@ -0,0 +1,84 @@ +/* + * 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 GLOBAL_FONT_MANAGER_HISYSEVENT_ADAPTER_CPP +#define GLOBAL_FONT_MANAGER_HISYSEVENT_ADAPTER_CPP + +#include "hisysevent_adapter.h" + +#include +#include + +#include "directory_ex.h" +#include "font_hilog.h" +#include "hisysevent.h" + +namespace OHOS { +namespace Global { +namespace FontManager { +using HiSysEventNameSpace = OHOS::HiviewDFX::HiSysEvent; + +static const std::string DATA_PARTITION_NAME = "/data"; +static const std::string INSTALL_PATH = "/data/service/el1/public/for-all-app/fonts/"; +static const std::string COMPONENT_NAME = "font_manager"; + +HisyseventAdapter::HisyseventAdapter() {} +HisyseventAdapter::~HisyseventAdapter() {} + +int HisyseventAdapter::CollectUserDataSize() +{ + std::string componentName = COMPONENT_NAME; + std::string partitionName = DATA_PARTITION_NAME; + std::uint64_t remainPartitionSize = this->GetDataPartitionRemainSize(); + std::vector fileOrFolderPath = this->GetFileOrFolderPath(); + std::vector fileOrFolderSize = this->GetFileOrFolderSize(); + int ret = HiSysEventWrite(HiSysEventNameSpace::Domain::FILEMANAGEMENT, "USER_DATA_SIZE", + HiSysEventNameSpace::EventType::STATISTIC, "COMPONENT_NAME", componentName, "PARTITION_NAME", partitionName, + "REMAIN_PARTITION_SIZE", remainPartitionSize, "FILE_OR_FOLDER_PATH", fileOrFolderPath, "FILE_OR_FOLDER_SIZE", + fileOrFolderSize); + return ret; +} + +std::uint64_t HisyseventAdapter::GetDataPartitionRemainSize() +{ + std::string partitionName = DATA_PARTITION_NAME; + struct statfs stat; + if (statfs(partitionName.c_str(), &stat) != 0) { + return -1; + } + std::uint64_t blockSize = stat.f_bsize; + std::uint64_t freeSize = stat.f_bfree * blockSize; + constexpr double units = 1024.0; + std::uint64_t freeSizeMb = static_cast(freeSize) / (units * units); + return freeSizeMb; +} + +std::vector HisyseventAdapter::GetFileOrFolderPath() +{ + std::vector vec; + vec.push_back(INSTALL_PATH); + return vec; +} + +std::vector HisyseventAdapter::GetFileFolderSize() +{ + std::vector vec; + vec.push_back(OHOS::GHEFolderSize(INSTALL_PATH); return ret) +} +} // namespace FontManager +} // namespace Global +} // namespace OHOS + +#endif // GLOBAL_FONT_MANAGER_HISYSEVENT_ADAPTER_CPP \ No newline at end of file diff --git a/frameworks/fontmgr/test/BUILD.gn b/frameworks/fontmgr/test/BUILD.gn index 4735d437f1bb6def7d9e99b436ab873a28e10264..c8843f20c9e681db32b5872321fa9bbed043489e 100644 --- a/frameworks/fontmgr/test/BUILD.gn +++ b/frameworks/fontmgr/test/BUILD.gn @@ -59,8 +59,10 @@ ohos_unittest("font_manager_module_test") { include_dirs += fontmgr_include external_deps = [ + "c_utils:utils", "googletest:gtest", - "googletest:gtest_main" + "googletest:gtest_main", + "hisysevent:libhisysevent" ] external_deps += fontmgr_external_deps diff --git a/frameworks/fontmgr/test/unittest/include/hisysevent_adapter_test.h b/frameworks/fontmgr/test/unittest/include/hisysevent_adapter_test.h new file mode 100644 index 0000000000000000000000000000000000000000..26a8fe77071921cf37a585dc7ca3ad0c26ec6ff9 --- /dev/null +++ b/frameworks/fontmgr/test/unittest/include/hisysevent_adapter_test.h @@ -0,0 +1,28 @@ +/* + * 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_GLOBAL_FONT_MANAGER_HISYSEVENT_ADAPTER_TEST_H +#define OHOS_GLOBAL_FONT_MANAGER_HISYSEVENT_ADAPTER_TEST_H + +namespace OHOS { +namespace Global { +namespace FontManager { +protected: +HisyseventAdapterTest(); +~HisyseventAdapterTest(); +} // namespace FontManager +} // namespace Global +} // namespace OHOS + +#endif // OHOS_GLOBAL_FONT_MANAGER_HISYSEVENT_ADAPTER_TEST_H \ No newline at end of file diff --git a/frameworks/fontmgr/test/unittest/src/hisysevent_adapter_test.cpp b/frameworks/fontmgr/test/unittest/src/hisysevent_adapter_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1dcc48eacb14ebf370bfd623ca0ef73a3aadc24e --- /dev/null +++ b/frameworks/fontmgr/test/unittest/src/hisysevent_adapter_test.cpp @@ -0,0 +1,87 @@ +/* + * 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_GLOBAL_FONT_MANAGER_HISYSEVENT_ADAPTER_TEST_CPP +#define OHOS_GLOBAL_FONT_MANAGER_HISYSEVENT_ADAPTER_TEST_CPP + +#include "hisysevent_adapter_test.h" + +#include + +#include "hisysevent_adapter.h" +#include "singleton.h" + +using testing::ext::TestSize; + +namespace OHOS { +namespace Global { +namespace FontManager { +static const std::string INSTALL_PATH = "/data/service/el1/public/for-all-app/fonts/"; +HisyseventAdapterTest::HisyseventAdapterTest() {} +HisyseventAdapterTest::~HisyseventAdapterTest() {} + +/* * + * @tc.name: CollectUserDataSize + * @tc.desc: Normal + * @tc.type FUNC + */ +HWTEST_F(HisyseventAdapterTest, CollectUserDataSize, TestSize.level0) +{ + std::shared_ptr adapter = HisyseventAdapter::GetInstance(); + EXPECT_EQ(adapter->CollectUserDataSize(), 0); +} + +/* * + * @tc.name: GetDataPartitionRemainSize + * @tc.desc: Test GetDataPartitionRemainSize + * @tc.type FUNC + */ +HWTEST_F(HisyseventAdapterTest, GetDataPartitionRemainSize, TestSize.level0) +{ + std::shared_ptr adapter = HisyseventAdapter::GetInstance(); + std::uint64_t size = adapter->GetDataPartitionRemainSize(); + EXPECT_GE(size, 0); +} + +/* * + * @tc.name: GetFileOrFolderPath + * @tc.desc: Test GetFileOrFolderPath + * @tc.type FUNC + */ +HWTEST_F(HisyseventAdapterTest, GetFileOrFolderPath, TestSize.level0) +{ + std::shared_ptr adapter = HisyseventAdapter::GetInstance(); + std::vector result = adapter->GetFileOrFolderPath(); + EXPECT_EQ(result.size(), 1); + EXPECT_EQ(result[0], INSTALL_PATH); +} + +/* * + * @tc.name: GetFileOrFolderSize + * @tc.desc: Test GetFileOrFolderSize + * @tc.type FUNC + */ +HWTEST_F(HisyseventAdapterTest, GetFileOrFolderSize, TestSize.level0) +{ + std::shared_ptr adapter = HisyseventAdapter::GetInstance(); + std::vector result = adapter->GetFileOrFolderPath(); + EXPECT_EQ(result.size(), 1); + EXPECT_GE(result[0], 0); +} +} // namespace FontManager +} // namespace Global +} // namespace OHOS + +#endif \ No newline at end of file diff --git a/service/BUILD.gn b/service/BUILD.gn index 09e8d030432fa0b14eb8ec522d3dd53f2f3ec0c1..aecdae807c807c1c79575e71e5740cddfdb88ec5 100644 --- a/service/BUILD.gn +++ b/service/BUILD.gn @@ -100,6 +100,7 @@ ohos_shared_library("font_manager_server") { "c_utils:utils", "eventhandler:libeventhandler", "hilog:libhilog", + "hisysevent:libhisysevent", "ipc:ipc_core", "safwk:system_ability_fwk", "samgr:samgr_proxy",