From 44daf92094bf43a783d3ac9f0e91506a455239a9 Mon Sep 17 00:00:00 2001 From: linan24 Date: Thu, 24 Jul 2025 15:32:13 +0800 Subject: [PATCH] afs rom optimization Signed-off-by: linan24 --- frameworks/native/backup_ext/BUILD.gn | 3 +- .../native/backup_kit_inner/BUILD.gn | 4 +- interfaces/kits/js/BUILD.gn | 1 - services/backup_sa/BUILD.gn | 98 +++++++++++++++++-- .../include/svc_extension_proxy_mock.h | 8 +- .../module_ipc/service_reverse_proxy_mock.cpp | 24 +++++ tests/unittests/backup_sa/module_ipc/BUILD.gn | 2 +- utils/BUILD.gn | 1 - utils/include/b_radar/radar_app_statistic.h | 10 -- utils/include/b_radar/radar_const.h | 56 ----------- utils/include/b_radar/radar_const_inner.h | 80 +++++++++++++++ utils/src/b_radar/radar_app_statistic.cpp | 11 +++ utils/src/b_radar/radar_total_statistic.cpp | 1 + 13 files changed, 215 insertions(+), 84 deletions(-) create mode 100644 utils/include/b_radar/radar_const_inner.h diff --git a/frameworks/native/backup_ext/BUILD.gn b/frameworks/native/backup_ext/BUILD.gn index 85d6d2369..14208017d 100644 --- a/frameworks/native/backup_ext/BUILD.gn +++ b/frameworks/native/backup_ext/BUILD.gn @@ -52,7 +52,7 @@ ohos_shared_library("backup_extension_ability_native") { deps = [ "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner", "${path_backup}/interfaces/innerkits/native:sandbox_helper_native", - "${path_backup}/services/backup_sa:backup_sa_ipc_stub", + "${path_backup}/services/backup_sa:backup_extension_stub_idl", "${path_backup}/utils:backup_utils", ] @@ -85,6 +85,7 @@ ohos_shared_library("backup_extension_ability_native") { "-fno-unwind-tables", "-fno-asynchronous-unwind-tables", "-Os", + "-fvisibility=hidden", ] use_exceptions = true diff --git a/interfaces/inner_api/native/backup_kit_inner/BUILD.gn b/interfaces/inner_api/native/backup_kit_inner/BUILD.gn index 70593df50..94bc2549c 100644 --- a/interfaces/inner_api/native/backup_kit_inner/BUILD.gn +++ b/interfaces/inner_api/native/backup_kit_inner/BUILD.gn @@ -78,7 +78,9 @@ ohos_shared_library("backup_kit_inner") { ] deps = [ - "${path_backup}/services/backup_sa:backup_sa_ipc", + "${path_backup}/services/backup_sa:backup_extension_stub_idl", + "${path_backup}/services/backup_sa:backup_reverse_stub_idl", + "${path_backup}/services/backup_sa:backup_service_proxy_idl", "${path_backup}/utils:backup_utils", ] diff --git a/interfaces/kits/js/BUILD.gn b/interfaces/kits/js/BUILD.gn index 3a96c145c..c0c812f55 100644 --- a/interfaces/kits/js/BUILD.gn +++ b/interfaces/kits/js/BUILD.gn @@ -157,7 +157,6 @@ ohos_shared_library("backup") { deps = [ "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner", - "${path_backup}/services/backup_sa:backup_sa_ipc", "${path_backup}/utils:backup_utils", ] diff --git a/services/backup_sa/BUILD.gn b/services/backup_sa/BUILD.gn index 4f0cab5c4..a8e928cbf 100644 --- a/services/backup_sa/BUILD.gn +++ b/services/backup_sa/BUILD.gn @@ -68,27 +68,31 @@ ohos_source_set("backup_sa_ipc") { "${target_gen_dir}/", ] + cflags_cc = [ + "-fdata-sections", + "-ffunction-sections", + "-fno-unwind-tables", + "-fno-asynchronous-unwind-tables", + "-Os", + "-fvisibility=hidden", + ] + part_name = "app_file_service" subsystem_name = "filemanagement" } -ohos_source_set("backup_sa_ipc_type") { +ohos_source_set("backup_extension_stub_idl") { sanitize = { cfi = true cfi_cross_dso = true debug = false } - output_values = get_target_outputs(":backup_idl") - - sources = [] - - sources += filter_include(output_values, [ "*_type.cpp" ]) - + sources = [ + "${target_gen_dir}/extension_stub.cpp" + ] public_configs = [ ":public_idl_config" ] - deps = [ ":backup_idl" ] - external_deps = [ "c_utils:utils", "hilog:libhilog", @@ -97,14 +101,88 @@ ohos_source_set("backup_sa_ipc_type") { "safwk:system_ability_fwk", "samgr:samgr_proxy", ] - include_dirs = [ ".", "${target_gen_dir}/", ] + cflags_cc = [ + "-fdata-sections", + "-ffunction-sections", + "-fno-unwind-tables", + "-fno-asynchronous-unwind-tables", + "-Os", + ] + part_name = "app_file_service" + subsystem_name = "filemanagement" +} +ohos_source_set("backup_reverse_stub_idl") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + sources = [ + "${target_gen_dir}/service_reverse_stub.cpp" + ] + public_configs = [ ":public_idl_config" ] + deps = [ ":backup_idl" ] + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + "hitrace:hitrace_meter", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] + include_dirs = [ + ".", + "${path_backup}/interfaces/inner_api/native/backup_kit_inner/impl", + "${target_gen_dir}/", + ] + cflags_cc = [ + "-fdata-sections", + "-ffunction-sections", + "-fno-unwind-tables", + "-fno-asynchronous-unwind-tables", + "-Os", + ] part_name = "app_file_service" + subsystem_name = "filemanagement" +} +ohos_source_set("backup_service_proxy_idl") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + sources = [ + "${target_gen_dir}/service_proxy.cpp" + ] + public_configs = [ ":public_idl_config" ] + deps = [ ":backup_idl" ] + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + "hitrace:hitrace_meter", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] + include_dirs = [ + ".", + "${path_backup}/interfaces/inner_api/native/backup_kit_inner/impl", + "${target_gen_dir}/", + ] + cflags_cc = [ + "-fdata-sections", + "-ffunction-sections", + "-fno-unwind-tables", + "-fno-asynchronous-unwind-tables", + "-Os", + ] + part_name = "app_file_service" subsystem_name = "filemanagement" } diff --git a/tests/mock/module_ipc/include/svc_extension_proxy_mock.h b/tests/mock/module_ipc/include/svc_extension_proxy_mock.h index ed98bfdd3..22a484e0e 100644 --- a/tests/mock/module_ipc/include/svc_extension_proxy_mock.h +++ b/tests/mock/module_ipc/include/svc_extension_proxy_mock.h @@ -18,12 +18,14 @@ #include -#include "extension_proxy.h" +#include +#include "iextension.h" namespace OHOS::FileManagement::Backup { -class SvcExtensionProxyMock : public ExtensionProxy { +class SvcExtensionProxyMock : public IRemoteProxy { public: - SvcExtensionProxyMock() : ExtensionProxy(nullptr) {}; + SvcExtensionProxyMock() : IRemoteProxy(nullptr) {}; + virtual ~SvcExtensionProxyMock() = default; public: MOCK_METHOD(ErrCode, GetFileHandleWithUniqueFd, (const std::string &, int32_t &, int32_t &)); MOCK_METHOD(ErrCode, HandleClear, ()); diff --git a/tests/mock/module_ipc/service_reverse_proxy_mock.cpp b/tests/mock/module_ipc/service_reverse_proxy_mock.cpp index 800d74399..7e03f557d 100644 --- a/tests/mock/module_ipc/service_reverse_proxy_mock.cpp +++ b/tests/mock/module_ipc/service_reverse_proxy_mock.cpp @@ -175,4 +175,28 @@ ErrCode ServiceReverseProxy::IncrementalRestoreOnProcessInfo(const std::string & { return BError(BError::Codes::OK); } + +ErrCode ServiceReverseProxy::IncrementalSaBackupOnFileReady(const std::string &bundleName, const std::string &fileName, + int fd, int32_t errCode) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::IncrementalBackupOnFileReadyWithoutFd(const std::string &bundleName, + const std::string &fileName, int32_t errCode) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::BackupOnFileReadyWithoutFd(const std::string &bundleName, const std::string &fileName, + int32_t errCode) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceReverseProxy::RestoreOnFileReadyWithoutFd(const std::string &bundleName, const std::string &fileName, + int32_t errCode) +{ + return BError(BError::Codes::OK); +} } // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/tests/unittests/backup_sa/module_ipc/BUILD.gn b/tests/unittests/backup_sa/module_ipc/BUILD.gn index 3c8a43658..46f62e8b6 100644 --- a/tests/unittests/backup_sa/module_ipc/BUILD.gn +++ b/tests/unittests/backup_sa/module_ipc/BUILD.gn @@ -39,7 +39,7 @@ ohos_unittest("module_ipc_test") { deps = [ "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner", - "${path_backup}/services/backup_sa:backup_sa_ipc_stub", + "${path_backup}/services/backup_sa:backup_sa_ipc", "${path_backup}/tests/utils:backup_test_utils", "${path_backup}/utils:backup_utils", ] diff --git a/utils/BUILD.gn b/utils/BUILD.gn index 90f31d3e6..f154e214b 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -116,7 +116,6 @@ ohos_shared_library("backup_utils") { deps = [ ":backup_cxx_cppdeps", "${path_backup}/interfaces/innerkits/native:sandbox_helper_native", - "${path_backup}/services/backup_sa:backup_sa_ipc_type", ] cflags_cc = [ diff --git a/utils/include/b_radar/radar_app_statistic.h b/utils/include/b_radar/radar_app_statistic.h index 9a84969ff..ca81a26be 100644 --- a/utils/include/b_radar/radar_app_statistic.h +++ b/utils/include/b_radar/radar_app_statistic.h @@ -42,16 +42,6 @@ enum FileType : uint8_t { OTHER, }; -const std::unordered_map FileTypeDef = { - {"txt", TXT}, {"log", TXT}, {"json", TXT}, {"xml", TXT}, {"db", TXT}, {"db-compare", TXT}, - {"jpg", PIC}, {"jpeg", PIC}, {"png", PIC}, {"bmp", PIC}, {"gif", PIC}, {"svg", PIC}, {"webp", PIC}, {"tif", PIC}, - {"raw", PIC}, - {"wav", AUDIO}, {"flac", AUDIO}, {"wma", AUDIO}, {"acc", AUDIO}, {"mp3", AUDIO}, {"ogg", AUDIO}, {"opus", AUDIO}, - {"mov", VEDIO}, {"wmv", VEDIO}, {"rm", VEDIO}, {"rmvb", VEDIO}, {"3gp", VEDIO}, {"m4v", VEDIO}, {"mkv", VEDIO}, - {"rar", COMPRESS}, {"zip", COMPRESS}, {"7z", COMPRESS}, {"gz", COMPRESS}, {"iso", COMPRESS}, {"tar", COMPRESS}, - {"exe", BIN}, {"doc", BIN}, {"docx", BIN}, {"xls", BIN}, {"xlsx", BIN}, {"ppt", BIN}, {"pdf", BIN} -}; - constexpr uint64_t ONE_MB = 1024 * 1024; constexpr uint64_t TWO_MB = 2 * ONE_MB; constexpr uint64_t TEN_MB = 10 * ONE_MB; diff --git a/utils/include/b_radar/radar_const.h b/utils/include/b_radar/radar_const.h index f4c730c44..6ebf347da 100644 --- a/utils/include/b_radar/radar_const.h +++ b/utils/include/b_radar/radar_const.h @@ -127,61 +127,5 @@ struct RadarError { std::string errMsg_ = ""; }; -constexpr int32_t DEFAULT_STAGE = 1; -constexpr int32_t STAGE_RES_IDLE = 0; -constexpr int32_t STAGE_RES_SUCCESS = 1; -constexpr int32_t STAGE_RES_FAIL = 2; -constexpr int32_t STAGE_RES_CANCEL = 3; - -constexpr char DOMAIN[] = "APP_FILE_SVC"; -const std::string DOMAIN_NAME = "APP_FILE_SVC"; -const std::string BACKUP_RESTORE_APP_STATISTIC = "BACKUP_RESTORE_APP_STATISTIC"; -const std::string BACKUP_RESTORE_STATISTIC = "BACKUP_RESTORE_STATISTIC"; - -const std::string ORG_PKG = "ORG_PKG"; -const std::string FUNC = "FUNC"; -const std::string BIZ_SCENE = "BIZ_SCENE"; -const std::string BIZ_STAGE = "BIZ_STAGE"; -const std::string STAGE_RES = "STAGE_RES"; -const std::string CONCURRENT_ID = "CONCURRENT_ID"; -const std::string ERROR_CODE = "ERROR_CODE"; -const std::string ERROR_MSG = "ERROR_MSG"; - -const std::string HOST_PKG = "HOST_PKG"; -const std::string APP_CALLER = "APP_CALLER"; -const std::string MODE = "MODE"; -const std::string FILE_SIZE_DIST = "FILE_SIZE_DIST"; -const std::string FILE_TYPE_DIST = "FILE_TYPE_DIST"; -const std::string SMALL_FILE_COUNT = "SMALL_FILE_COUNT"; -const std::string SMALL_FILE_SIZE = "SMALL_FILE_SIZE"; -const std::string BIG_FILE_COUNT = "BIG_FILE_COUNT"; -const std::string BIG_FILE_SIZE = "BIG_FILE_SIZE"; -const std::string TAR_FILE_COUNT = "TAR_FILE_COUNT"; -const std::string TAR_FILE_SIZE = "TAR_FILE_SIZE"; -const std::string TAR_BOUND_SIZE = "TAR_BOUND_SIZE"; -const std::string DIR_DEPTH = "DIR_DEPTH"; -const std::string MANAGE_JSON_SIZE = "MANAGE_JSON_SIZE"; -const std::string EXTENSION_CONNECT_SPEND = "EXTENSION_CONNECT_SPEND"; -const std::string GET_EXT_INFO_SPEND = "GET_EXT_INFO_SPEND"; - -const std::string ON_BACKUP_SPEND = "ON_BACKUP_SPEND"; -const std::string ON_BACKUPEX_SPEND = "ON_BACKUPEX_SPEND"; -const std::string DO_BACKUP_SPEND = "DO_BACKUP_SPEND"; -const std::string TAR_SPEND = "TAR_SPEND"; -const std::string HASH_SPEND = "HASH_SPEND"; -const std::string SCAN_FILE_SPEND = "SCAN_FILE_SPEND"; -const std::string SEND_RATE_ZERO_SPAN = "SEND_RATE_ZERO_SPAN"; - -const std::string ON_RESTORE_SPEND = "ON_RESTORE_SPEND"; -const std::string ON_RESTOREEX_SPEND = "ON_RESTOREEX_SPEND"; -const std::string DO_RESTORE_SPEND = "DO_RESTORE_SPEND"; -const std::string UNTAR_SPEND = "UNTAR_SPEND"; -const std::string BIG_FILE_SPEND = "BIG_FILE_SPEND"; - -const std::string GET_BUNDLE_INFO_SPEND = "GET_BUNDLE_INFO_SPEND"; -const std::string TOTAL_SPEND = "TOTAL_SPEND"; -const std::string SUCC_BUNDLE_CNT = "SUCC_BUNDLE_CNT"; -const std::string FAIL_BUNDLE_CNT = "FAIL_BUNDLE_CNT"; - } // namespace OHOS::FileManagement::Backup #endif // OHOS_FILEMGMT_BACKUP_RADAR_CONST_H diff --git a/utils/include/b_radar/radar_const_inner.h b/utils/include/b_radar/radar_const_inner.h new file mode 100644 index 000000000..6e19570c5 --- /dev/null +++ b/utils/include/b_radar/radar_const_inner.h @@ -0,0 +1,80 @@ +/* + * 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_FILEMGMT_BACKUP_RADAR_CONST_INNER_H +#define OHOS_FILEMGMT_BACKUP_RADAR_CONST_INNER_H + +#include + +namespace OHOS::FileManagement::Backup { + +constexpr int32_t DEFAULT_STAGE = 1; +constexpr int32_t STAGE_RES_IDLE = 0; +constexpr int32_t STAGE_RES_SUCCESS = 1; +constexpr int32_t STAGE_RES_FAIL = 2; +constexpr int32_t STAGE_RES_CANCEL = 3; + +constexpr char DOMAIN[] = "APP_FILE_SVC"; +const std::string DOMAIN_NAME = "APP_FILE_SVC"; +const std::string BACKUP_RESTORE_APP_STATISTIC = "BACKUP_RESTORE_APP_STATISTIC"; +const std::string BACKUP_RESTORE_STATISTIC = "BACKUP_RESTORE_STATISTIC"; + +const std::string ORG_PKG = "ORG_PKG"; +const std::string FUNC = "FUNC"; +const std::string BIZ_SCENE = "BIZ_SCENE"; +const std::string BIZ_STAGE = "BIZ_STAGE"; +const std::string STAGE_RES = "STAGE_RES"; +const std::string CONCURRENT_ID = "CONCURRENT_ID"; +const std::string ERROR_CODE = "ERROR_CODE"; +const std::string ERROR_MSG = "ERROR_MSG"; + +const std::string HOST_PKG = "HOST_PKG"; +const std::string APP_CALLER = "APP_CALLER"; +const std::string MODE = "MODE"; +const std::string FILE_SIZE_DIST = "FILE_SIZE_DIST"; +const std::string FILE_TYPE_DIST = "FILE_TYPE_DIST"; +const std::string SMALL_FILE_COUNT = "SMALL_FILE_COUNT"; +const std::string SMALL_FILE_SIZE = "SMALL_FILE_SIZE"; +const std::string BIG_FILE_COUNT = "BIG_FILE_COUNT"; +const std::string BIG_FILE_SIZE = "BIG_FILE_SIZE"; +const std::string TAR_FILE_COUNT = "TAR_FILE_COUNT"; +const std::string TAR_FILE_SIZE = "TAR_FILE_SIZE"; +const std::string TAR_BOUND_SIZE = "TAR_BOUND_SIZE"; +const std::string DIR_DEPTH = "DIR_DEPTH"; +const std::string MANAGE_JSON_SIZE = "MANAGE_JSON_SIZE"; +const std::string EXTENSION_CONNECT_SPEND = "EXTENSION_CONNECT_SPEND"; +const std::string GET_EXT_INFO_SPEND = "GET_EXT_INFO_SPEND"; + +const std::string ON_BACKUP_SPEND = "ON_BACKUP_SPEND"; +const std::string ON_BACKUPEX_SPEND = "ON_BACKUPEX_SPEND"; +const std::string DO_BACKUP_SPEND = "DO_BACKUP_SPEND"; +const std::string TAR_SPEND = "TAR_SPEND"; +const std::string HASH_SPEND = "HASH_SPEND"; +const std::string SCAN_FILE_SPEND = "SCAN_FILE_SPEND"; +const std::string SEND_RATE_ZERO_SPAN = "SEND_RATE_ZERO_SPAN"; + +const std::string ON_RESTORE_SPEND = "ON_RESTORE_SPEND"; +const std::string ON_RESTOREEX_SPEND = "ON_RESTOREEX_SPEND"; +const std::string DO_RESTORE_SPEND = "DO_RESTORE_SPEND"; +const std::string UNTAR_SPEND = "UNTAR_SPEND"; +const std::string BIG_FILE_SPEND = "BIG_FILE_SPEND"; + +const std::string GET_BUNDLE_INFO_SPEND = "GET_BUNDLE_INFO_SPEND"; +const std::string TOTAL_SPEND = "TOTAL_SPEND"; +const std::string SUCC_BUNDLE_CNT = "SUCC_BUNDLE_CNT"; +const std::string FAIL_BUNDLE_CNT = "FAIL_BUNDLE_CNT"; + +} // namespace OHOS::FileManagement::Backup +#endif // OHOS_FILEMGMT_BACKUP_RADAR_CONST_INNER_H diff --git a/utils/src/b_radar/radar_app_statistic.cpp b/utils/src/b_radar/radar_app_statistic.cpp index 9d37a82db..804b0682f 100644 --- a/utils/src/b_radar/radar_app_statistic.cpp +++ b/utils/src/b_radar/radar_app_statistic.cpp @@ -14,11 +14,22 @@ */ #include "b_radar/radar_app_statistic.h" +#include "b_radar/radar_const_inner.h" #include "filemgmt_libhilog.h" #include "hisysevent.h" namespace OHOS::FileManagement::Backup { +const std::unordered_map FileTypeDef = { + {"txt", TXT}, {"log", TXT}, {"json", TXT}, {"xml", TXT}, {"db", TXT}, {"db-compare", TXT}, + {"jpg", PIC}, {"jpeg", PIC}, {"png", PIC}, {"bmp", PIC}, {"gif", PIC}, {"svg", PIC}, {"webp", PIC}, {"tif", PIC}, + {"raw", PIC}, + {"wav", AUDIO}, {"flac", AUDIO}, {"wma", AUDIO}, {"acc", AUDIO}, {"mp3", AUDIO}, {"ogg", AUDIO}, {"opus", AUDIO}, + {"mov", VEDIO}, {"wmv", VEDIO}, {"rm", VEDIO}, {"rmvb", VEDIO}, {"3gp", VEDIO}, {"m4v", VEDIO}, {"mkv", VEDIO}, + {"rar", COMPRESS}, {"zip", COMPRESS}, {"7z", COMPRESS}, {"gz", COMPRESS}, {"iso", COMPRESS}, {"tar", COMPRESS}, + {"exe", BIN}, {"doc", BIN}, {"docx", BIN}, {"xls", BIN}, {"xlsx", BIN}, {"ppt", BIN}, {"pdf", BIN} +}; + std::string FileStatList::ToJsonString() { std::string result = "["; diff --git a/utils/src/b_radar/radar_total_statistic.cpp b/utils/src/b_radar/radar_total_statistic.cpp index ca143af9a..87035f4a5 100644 --- a/utils/src/b_radar/radar_total_statistic.cpp +++ b/utils/src/b_radar/radar_total_statistic.cpp @@ -14,6 +14,7 @@ */ #include "b_radar/radar_total_statistic.h" +#include "b_radar/radar_const_inner.h" #include "b_utils/b_time.h" #include "filemgmt_libhilog.h" #include "hisysevent.h" -- Gitee