diff --git a/frameworks/native/backup_ext/src/ext_extension.cpp b/frameworks/native/backup_ext/src/ext_extension.cpp index 1119285af81d4ed82d7d34ba1f241f1681813c15..1126f7e275dd088581be6879cc0453e2cca70ef5 100644 --- a/frameworks/native/backup_ext/src/ext_extension.cpp +++ b/frameworks/native/backup_ext/src/ext_extension.cpp @@ -1234,7 +1234,6 @@ void BackupExtExtension::RestoreOneBigFile(const std::string &path, { radarRestoreInfo_.bigFileNum++; radarRestoreInfo_.bigFileSize += static_cast(item.sta.st_size); - string itemHashName = item.hashName; string itemFileName = item.fileName; // check if item.hasName and fileName need decode by report item attribute string reportPath = GetReportFileName(path + item.hashName); @@ -1242,15 +1241,14 @@ void BackupExtExtension::RestoreOneBigFile(const std::string &path, if (fd < 0) { HILOGE("Failed to open report file = %{public}s, err = %{public}d", reportPath.c_str(), errno); errFileInfos_[item.hashName].emplace_back(errno); - AuditLog auditLog = {false, "Open fd failed", "ADD", "", 1, "FAILED", "RestoreOneBigFile", - "RestoreOneBigFile", GetAnonyPath(reportPath)}; - HiAudit::GetInstance(false).Write(auditLog); + AppRadar::Info info (bundleName_, "", "Failed to open report file: " + GetAnonyPath(reportPath)); + AppRadar::GetInstance().RecordRestoreFuncRes(info, "BackupExtExtension::RestoreOneBigFile", + AppRadar::GetInstance().GetUserId(), BizStageRestore::BIZ_STAGE_DO_RESTORE, errno); throw BError(BError::Codes::EXT_INVAL_ARG, string("open report file failed")); } BReportEntity rp(move(fd)); rp.CheckAndUpdateIfReportLineEncoded(itemFileName); - - string fileName = path + itemHashName; + string fileName = path + item.hashName; string filePath = appendTargetPath ? (path + itemFileName) : itemFileName; if (BDir::CheckFilePathInvalid(filePath)) { HILOGE("Check big file path : %{public}s err, path is forbidden", GetAnonyPath(filePath).c_str()); @@ -1266,7 +1264,6 @@ void BackupExtExtension::RestoreOneBigFile(const std::string &path, if (isDebug_) { endFileInfos_[filePath] = item.sta.st_size; } - if (!RestoreBigFilePrecheck(fileName, path, item.hashName, filePath)) { return; } diff --git a/frameworks/native/backup_ext/src/sub_ext_extension.cpp b/frameworks/native/backup_ext/src/sub_ext_extension.cpp index 24e2a9c110254d418bf60209a9816489a1beb764..14812b6cf9e2cc5990f530662cce7e2e45390a70 100644 --- a/frameworks/native/backup_ext/src/sub_ext_extension.cpp +++ b/frameworks/native/backup_ext/src/sub_ext_extension.cpp @@ -59,6 +59,7 @@ namespace OHOS::FileManagement::Backup { const uint32_t MAX_FD_GROUP_USE_TIME = 1000; // 每组打开最大时间1000ms +const int INVALID_FD = -1; void BackupExtExtension::WaitToSendFd(std::chrono::system_clock::time_point &startTime, int &fdSendNum) { @@ -953,7 +954,7 @@ int BackupExtExtension::User0DoBackup(const BJsonEntityExtensionConfig &usrConfi /** * 获取增量的大文件的信息 */ -static TarMap GetIncrmentBigInfos(const vector &files) +static TarMap GetIncrmentBigInfos(const vector &files, sptr proxy) { auto getStringHash = [](const TarMap &tarMap, const string &str) -> string { ostringstream strHex; @@ -975,9 +976,20 @@ static TarMap GetIncrmentBigInfos(const vector &files) TarMap bigFiles; for (const auto &item : files) { struct stat sta = {}; + int32_t errCode = ERR_OK; + UniqueFd fd(INVALID_FD); + UniqueFd reportFd(INVALID_FD); if (stat(item.filePath.c_str(), &sta) != 0) { - HILOGE("Failed to stat file %{public}s, err = %{public}d", item.filePath.c_str(), errno); - throw errno; + HILOGE("Failed to stat file %{public}s, err = %{public}d", GetAnonyPath(item.filePath).c_str(), errno); + errCode = errno; + auto ret = proxy->AppIncrementalFileReady(item.filePath, std::move(fd), std::move(reportFd), errCode); + if (SUCCEEDED(ret)) { + HILOGI("IncrementalFileReady: The application is packaged successfully, package path is %{public}s", + GetAnonyPath(item.filePath).c_str()); + } else { + HILOGE("IncrementalFileReady fails to be invoked: %{public}d", ret); + } + continue; } string md5Name = getStringHash(bigFiles, item.filePath); if (!md5Name.empty()) { @@ -1190,7 +1202,7 @@ int BackupExtExtension::DoIncrementalBackup(const vector IncrementalPacket(smallFiles, tarMap, proxy); HILOGI("Do increment backup, IncrementalPacket end"); // 最后回传大文件 - TarMap bigMap = GetIncrmentBigInfos(bigFiles); + TarMap bigMap = GetIncrmentBigInfos(bigFiles, proxy); IncrementalBigFileReady(bigMap, bigFiles, proxy); HILOGI("Do increment backup, IncrementalBigFileReady end"); bigMap.insert(tarMap.begin(), tarMap.end()); diff --git a/services/backup_sa/include/module_ipc/service.h b/services/backup_sa/include/module_ipc/service.h index 34a0fb99ac72055cb70ac6c560c1ab64d04a4426..cd0bf2515bdac070c49eb59f8ffdcad46ba04012 100644 --- a/services/backup_sa/include/module_ipc/service.h +++ b/services/backup_sa/include/module_ipc/service.h @@ -569,7 +569,7 @@ private: const vector &restoreBundleNames); void BundleBeginRadarReport(const std::string &bundleName, const ErrCode errCode, - const IServiceReverse::Scenario scenario); + const IServiceReverse::Scenario scenario, const std::string &extraInfo = ""); void BundleEndRadarReport(const std::string &bundleName, ErrCode errCode, const IServiceReverse::Scenario scenario); diff --git a/services/backup_sa/src/module_external/bms_adapter.cpp b/services/backup_sa/src/module_external/bms_adapter.cpp index 12a70dd621a57bcf50a390f592dfa4f1eecfaf0d..d3578c91a0c48ed74aac1c594ff870319beaa804 100644 --- a/services/backup_sa/src/module_external/bms_adapter.cpp +++ b/services/backup_sa/src/module_external/bms_adapter.cpp @@ -24,6 +24,7 @@ #include "b_file_info.h" #include "b_jsonutil/b_jsonutil.h" #include "b_json/b_json_entity_extension_config.h" +#include "b_radar/b_radar.h" #include "b_resources/b_constants.h" #include "b_sa/b_sa_utils.h" #include "bundle_mgr_client.h" @@ -100,6 +101,9 @@ static int64_t GetBundleStats(const string &bundleName, int32_t userId) AppExecFwk::Constants::NoGetBundleStatsFlag::GET_BUNDLE_WITHOUT_CACHE_SIZE); if (!res || bundleStats.size() != dataDir.size()) { HILOGE("An error occurred in querying bundle stats. name:%{public}s", bundleName.c_str()); + AppRadar::Info info (bundleName, "", ""); + AppRadar::GetInstance().RecordDefaultFuncRes(info, "GetBundleStats", userId, + BizStageBackup::BIZ_STAGE_GET_BUNDLE_STATS, BConstants::INVALID_VALUE); return 0; } for (uint i = 0; i < bundleStats.size(); i++) { @@ -165,7 +169,7 @@ string BundleMgrAdapter::GetAppGalleryBundleName() } static bool GetBackupExtConfig(const vector &extensionInfos, - BJsonEntityCaps::BundleBackupConfigPara &backupPara) + BJsonEntityCaps::BundleBackupConfigPara &backupPara, int32_t userId) { for (auto &&ext : extensionInfos) { if (ext.type != AppExecFwk::ExtensionAbilityType::BACKUP) { @@ -175,6 +179,9 @@ static bool GetBackupExtConfig(const vector &e AppExecFwk::BundleMgrClient client; if (!client.GetResConfigFile(ext, "ohos.extension.backup", out) || out.size() == 0) { HILOGE("Failed to get resconfigfile of bundle, bundle name is:%{public}s", ext.bundleName.c_str()); + AppRadar::Info info (ext.bundleName, "", "Failed to get resconfigfile"); + AppRadar::GetInstance().RecordDefaultFuncRes(info, "GetBackupExtConfig", userId, + BizStageBackup::BIZ_STAGE_APPEND_BUNDLES_FAIL, BConstants::INVALID_VALUE); continue; } BJsonCachedEntity cachedEntity(out[0], ext.bundleName); @@ -213,6 +220,9 @@ static bool CreateIPCInteractionFiles(int32_t userId, const string &bundleName, if (err != 0 && errno != EEXIST) { HILOGE("Failed to create folder in backup_sa bundleName:%{public}s, sys err:%{public}d", bundleName.c_str(), errno); + AppRadar::Info info (bundleName, "", "errno = " + to_string(errno)); + AppRadar::GetInstance().RecordDefaultFuncRes(info, "CreateIPCInteractionFiles", userId, + BizStageBackup::BIZ_STAGE_APPEND_BUNDLES_FAIL, err); return false; } } @@ -302,7 +312,7 @@ vector BundleMgrAdapter::GetBundleInfosForIncrement continue; } struct BJsonEntityCaps::BundleBackupConfigPara backupPara; - if (!GetBackupExtConfig(extensionInfos, backupPara)) { + if (!GetBackupExtConfig(extensionInfos, backupPara, userId)) { HILOGE("No backup extension ability found, bundleName:%{public}s", bundleName.c_str()); continue; } @@ -517,6 +527,9 @@ bool BundleMgrAdapter::GetCurBundleExtenionInfo(AppExecFwk::BundleInfo &installe if (ret != ERR_OK) { HILOGE("bundleName:%{public}s, ret:%{public}d, current bundle info for backup/restore is empty", bundleName.c_str(), ret); + AppRadar::Info info (bundleName, "", ""); + AppRadar::GetInstance().RecordDefaultFuncRes(info, "BMS::GetCloneBundleInfo", userId, + BizStageBackup::BIZ_STAGE_APPEND_BUNDLES_FAIL, ret); return false; } if (installedBundle.applicationInfo.codePath == HMOS_HAP_CODE_PATH || @@ -546,6 +559,9 @@ bool BundleMgrAdapter::IsUser0BundleName(std::string bundleName, int32_t userId) installedBundle, userId); if (ret != ERR_OK) { HILOGE("bundleName:%{public}s, ret:%{public}d, GetBundle Failed from BMS", bundleName.c_str(), ret); + AppRadar::Info info (bundleName, "", "GetBundle Failed from BMS"); + AppRadar::GetInstance().RecordDefaultFuncRes(info, "BMS::GetCloneBundleInfo", userId, + BizStageBackup::BIZ_STAGE_APPEND_BUNDLES_FAIL, ret); return false; } if (installedBundle.applicationInfo.singleton == true) { @@ -669,7 +685,7 @@ void BundleMgrAdapter::CreatBackupEnv(const std::vector &bundl continue; } struct BJsonEntityCaps::BundleBackupConfigPara backupPara; - if (!GetBackupExtConfig(extensionInfos, backupPara)) { + if (!GetBackupExtConfig(extensionInfos, backupPara, userId)) { HILOGE("No backup extension ability found, bundleName:%{public}s", bundleName.c_str()); continue; } @@ -698,7 +714,7 @@ std::vector BundleMgrAdapter::GetBundleInfosForAppe continue; } struct BJsonEntityCaps::BundleBackupConfigPara backupPara; - if (!GetBackupExtConfig(extensionInfos, backupPara)) { + if (!GetBackupExtConfig(extensionInfos, backupPara, userId)) { HILOGE("No backup extension ability found, bundleName:%{public}s", bundleName.c_str()); continue; } diff --git a/services/backup_sa/src/module_ipc/service.cpp b/services/backup_sa/src/module_ipc/service.cpp index 65a225c97578a96a989a7910e511406afdceb6ae..97855199b4c5716db7a5bbfbc031d521ac044d3c 100644 --- a/services/backup_sa/src/module_ipc/service.cpp +++ b/services/backup_sa/src/module_ipc/service.cpp @@ -118,7 +118,7 @@ void Service::OnStartResRadarReport(const std::vector &bundleNameLi } void Service::BundleBeginRadarReport(const std::string &bundleName, const ErrCode errCode, - const IServiceReverse::Scenario scenario) + const IServiceReverse::Scenario scenario, const std::string &extraInfo) { if (errCode == ERR_OK || errCode == BError(BError::Codes::SA_BOOT_EXT_FAIL).GetCode()) { return; @@ -131,7 +131,7 @@ void Service::BundleBeginRadarReport(const std::string &bundleName, const ErrCod taskInfo.reportTime = TimeUtils::GetCurrentTime(); taskInfo.errCode = errCode; UpdateFailedBundles(bundleName, taskInfo); - AppRadar::Info info(bundleName, "", ""); + AppRadar::Info info(bundleName, "", extraInfo); if (scenario == IServiceReverse::Scenario::RESTORE) { AppRadar::GetInstance().RecordRestoreFuncRes(info, "Service::BundleBeginRadarReport", GetUserIdDefault(), BizStageRestore::BIZ_STAGE_APPEND_BUNDLES_FAIL, errCode); diff --git a/services/backup_sa/src/module_ipc/sub_service.cpp b/services/backup_sa/src/module_ipc/sub_service.cpp index b679afd82582ab8c7a2da39fe526d53eb67997bb..afa37ca5a5c7bfe1da53240f58e000dca7821c2f 100644 --- a/services/backup_sa/src/module_ipc/sub_service.cpp +++ b/services/backup_sa/src/module_ipc/sub_service.cpp @@ -480,6 +480,8 @@ void Service::HandleNotSupportBundleNames(const std::vector &srcBun session_->GetServiceReverseProxy()->BackupOnBundleStarted( BError(BError::Codes::SA_BUNDLE_INFO_EMPTY), bundleName); } + BundleBeginRadarReport(bundleName, BError(BError::Codes::SA_BUNDLE_INFO_EMPTY).GetCode(), + IServiceReverse::Scenario::BACKUP, isIncBackup ? "isIncBackup" : "notIncBackup"); } } diff --git a/services/backup_sa/src/module_ipc/svc_backup_connection.cpp b/services/backup_sa/src/module_ipc/svc_backup_connection.cpp index 7dc6d5eecb0f91ca6fd159f26b2c994270c13b0f..73a026a344504cce87792710a350b7ca7a634bfe 100644 --- a/services/backup_sa/src/module_ipc/svc_backup_connection.cpp +++ b/services/backup_sa/src/module_ipc/svc_backup_connection.cpp @@ -19,6 +19,8 @@ #include #include "ability_manager_client.h" +#include "b_radar/b_radar.h" +#include "b_resources/b_constants.h" #include "filemgmt_libhilog.h" #include "hisysevent.h" #include "module_ipc/svc_extension_proxy.h" @@ -97,6 +99,9 @@ void SvcBackupConnection::OnAbilityDisconnectDone(const AppExecFwk::ElementName bundleName.data()); callDied_(move(bundleName), false); } + AppRadar::Info info (bundleName, "", isCleanCalled_ ? "isCleanCalled_" : "notCleanCalled_"); + AppRadar::GetInstance().RecordDefaultFuncRes(info, "SvcBackupConnection::OnAbilityDisconnectDone", + BConstants::DEFAULT_USER_ID, BizStageBackup::BIZ_STAGE_EXTENSION_DIE, BConstants::INVALID_VALUE); } condition_.notify_all(); waitCondition_.notify_all(); diff --git a/tests/mock/module_ipc/service_mock.cpp b/tests/mock/module_ipc/service_mock.cpp index 547ce256218178fcce43f40f0b7fdfdee8e71f48..c4cdcea0470fe3daa1350dd26ccc60cee7a63b61 100644 --- a/tests/mock/module_ipc/service_mock.cpp +++ b/tests/mock/module_ipc/service_mock.cpp @@ -317,7 +317,7 @@ void Service::HandleExceptionOnAppendBundles(sptr session, const vector &appendBundleNames, const vector &restoreBundleNames) {} void Service::BundleBeginRadarReport(const std::string &bundleName, const ErrCode errCode, - const IServiceReverse::Scenario scenario) {} + const IServiceReverse::Scenario scenario, const std::string &extraInfo) {} void Service::BundleEndRadarReport(const std::string &bundleName, ErrCode errCode, const IServiceReverse::Scenario scenario) {} diff --git a/tests/unittests/backup_ext/ext_extension_test.cpp b/tests/unittests/backup_ext/ext_extension_test.cpp index f4d66f998fd3f47e0d18c3527cd4eb199c60d9ba..9c5f1b9f24f5f88c90da071ac41a5c8292cc70fe 100644 --- a/tests/unittests/backup_ext/ext_extension_test.cpp +++ b/tests/unittests/backup_ext/ext_extension_test.cpp @@ -27,6 +27,7 @@ #include "b_error/b_error.h" #include "b_error/b_excep_utils.h" #include "ext_extension.cpp" +#include "service_proxy.h" #include "sub_ext_extension.cpp" namespace OHOS::FileManagement::Backup { @@ -456,7 +457,8 @@ HWTEST_F(ExtExtensionTest, Ext_Extension_Test_0700, testing::ext::TestSize.Level GTEST_LOG_(INFO) << "ExtExtensionTest-begin Ext_Extension_Test_0700"; try { vector files; - TarMap result = GetIncrmentBigInfos(files); + auto proxy = ServiceProxy::GetInstance(); + TarMap result = GetIncrmentBigInfos(files, proxy); EXPECT_TRUE(result.empty()); } catch (...) { EXPECT_TRUE(false); @@ -489,7 +491,8 @@ HWTEST_F(ExtExtensionTest, Ext_Extension_Test_0701, testing::ext::TestSize.Level info.userTar = 1; info.encodeFlag = false; srcFiles.push_back(info); - TarMap result = GetIncrmentBigInfos(srcFiles); + auto proxy = ServiceProxy::GetInstance(); + TarMap result = GetIncrmentBigInfos(srcFiles, proxy); EXPECT_EQ(result.size(), 1); } catch (...) { EXPECT_TRUE(false); @@ -523,7 +526,8 @@ HWTEST_F(ExtExtensionTest, Ext_Extension_Test_0702, testing::ext::TestSize.Level info.encodeFlag = false; srcFiles.push_back(info); srcFiles.push_back(info); - TarMap result = GetIncrmentBigInfos(srcFiles); + auto proxy = ServiceProxy::GetInstance(); + TarMap result = GetIncrmentBigInfos(srcFiles, proxy); EXPECT_EQ(result.size(), 2); } catch (...) { EXPECT_TRUE(false); diff --git a/tests/unittests/backup_sa/module_ipc/service_incremental_test.cpp b/tests/unittests/backup_sa/module_ipc/service_incremental_test.cpp index 2cd98147cf29c7c44aba7ad1a4379a599712e10e..45203bec9a3fff288742e9e7c6a93a6e1559c332 100644 --- a/tests/unittests/backup_sa/module_ipc/service_incremental_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_incremental_test.cpp @@ -355,7 +355,8 @@ void Service::OnBundleStarted(BError, sptr, const BundleName& void Service::HandleExceptionOnAppendBundles(sptr, const vector&, const vector&) {} -void Service::BundleBeginRadarReport(const std::string&, const ErrCode, const IServiceReverse::Scenario) {} +void Service::BundleBeginRadarReport(const std::string &, const ErrCode, + const IServiceReverse::Scenario, const std::string &) {} void Service::BundleEndRadarReport(const std::string&, const ErrCode, const IServiceReverse::Scenario) {} diff --git a/utils/include/b_radar/b_radar.h b/utils/include/b_radar/b_radar.h index 16d4a17f41050da933bcff018e2195b0e582dc18..e0c39b00f3cf4a427c4402d10c5c2e5efd8b9581 100644 --- a/utils/include/b_radar/b_radar.h +++ b/utils/include/b_radar/b_radar.h @@ -41,6 +41,8 @@ enum class BizStageBackup : int32_t { BIZ_STAGE_RELEASE, BIZ_STAGE_ONSTART_DISPOSE, BIZ_STAGE_ONSTART_RESIDUAL, + BIZ_STAGE_EXTENSION_DIE, + BIZ_STAGE_GET_BUNDLE_STATS, }; enum class BizStageRestore : int32_t { @@ -64,6 +66,7 @@ enum class BizStageRestore : int32_t { BIZ_STAGE_RELEASE, BIZ_STAGE_ONSTART_DISPOSE, BIZ_STAGE_ONSTART_RESIDUAL, + BIZ_STAGE_EXTENSION_DIE, }; class AppRadar { diff --git a/utils/include/b_resources/b_constants.h b/utils/include/b_resources/b_constants.h index 0c93f1f19b5b597a622842222db34d19ee78c4f0..8dc018647d5f9e788b9efb6db4a75a6a2fa3c38d 100644 --- a/utils/include/b_resources/b_constants.h +++ b/utils/include/b_resources/b_constants.h @@ -239,7 +239,7 @@ constexpr int32_t MS_1000 = 1000; constexpr int32_t MAX_TIME_COST = 900000; constexpr int32_t MAX_INEXCLUDE_SIZE = 25; constexpr uint8_t INDEX = 3; -constexpr int INVALID_TIMEOUT_VALUE = -1; +constexpr int INVALID_VALUE = -1; static inline std::string FILE_BACKUP_RESTORE_EVENTS = "FILE_BACKUP_RESTORE_EVENTS"; static inline std::string FILE_BACKUP_RESTORE_STATISTIC = "FILE_BACKUP_RESTORE_STATISTIC"; } // namespace OHOS::FileManagement::Backup::BConstants