From eaa53d5fd09d232cb5f13ff961153e3d3a84fdf0 Mon Sep 17 00:00:00 2001 From: "Zhangyao(Maggie)" Date: Thu, 31 Oct 2024 11:40:07 +0800 Subject: [PATCH] radar without statistic & dobackup change & dodispose4 & release Signed-off-by: Zhangyao(Maggie) --- .../native/backup_ext/src/ext_extension.cpp | 19 +- .../backup_ext/src/sub_ext_extension.cpp | 123 +++++++----- .../src/b_incremental_backup_session.cpp | 14 +- .../src/b_incremental_restore_session.cpp | 20 +- .../b_incremental_session_restore_async.cpp | 20 +- .../backup_kit_inner/src/b_session_backup.cpp | 12 +- .../src/b_session_restore.cpp | 20 +- .../src/b_session_restore_async.cpp | 19 +- .../src/service_incremental_reverse.cpp | 1 + .../backup_kit_inner/src/service_proxy.cpp | 16 +- .../backup_sa/include/module_ipc/service.h | 30 ++- .../app_gallery_dispose_proxy.cpp | 8 +- services/backup_sa/src/module_ipc/service.cpp | 187 +++++++++++++++--- .../src/module_ipc/service_incremental.cpp | 30 ++- .../backup_sa/src/module_ipc/sub_service.cpp | 3 + .../src/module_ipc/svc_session_manager.cpp | 21 +- .../src/module_sched/sched_scheduler.cpp | 20 +- tests/mock/module_ipc/service_mock.cpp | 24 ++- .../module_ipc/service_incremental_test.cpp | 21 ++ .../module_ipc/service_other_test.cpp | 12 +- .../backup_sa/module_ipc/service_test.cpp | 10 +- utils/include/b_error/b_error.h | 1 + utils/include/b_radar/b_radar.h | 39 +++- utils/include/b_resources/b_constants.h | 3 + utils/src/b_radar/b_radar.cpp | 6 +- 25 files changed, 492 insertions(+), 187 deletions(-) diff --git a/frameworks/native/backup_ext/src/ext_extension.cpp b/frameworks/native/backup_ext/src/ext_extension.cpp index b5fcb349f..2f11c39b1 100644 --- a/frameworks/native/backup_ext/src/ext_extension.cpp +++ b/frameworks/native/backup_ext/src/ext_extension.cpp @@ -75,15 +75,15 @@ static void RecordDoRestoreRes(const std::string &bundleName, const std::string AppRadar::DoRestoreInfo &restoreInfo) { std::stringstream ss; - ss << "\"bigFileNums\": " << restoreInfo.bigFileNum << ", "; - ss << "\"bigFileSize\": " << restoreInfo.bigFileSize << ", "; - ss << "\"RestoreBigFileTime\": " << restoreInfo.bigFileSpendTime << ", "; - ss << "\"unTarFileNums\": " << restoreInfo.tarFileNum << ", "; - ss << "\"unTarFileSize\": " << restoreInfo.tarFileSize << ", "; - ss << "\"unTarTime\": " << restoreInfo.tarFileSpendTime << ", "; - ss << "\"totalFileNum\": " << restoreInfo.bigFileNum + restoreInfo.tarFileNum << ", "; - ss << "\"totalFileSize\": " << restoreInfo.bigFileSize + restoreInfo.tarFileSize << ", "; - ss << "\"restoreAllFileTime\": " << restoreInfo.totalFileSpendTime; + ss << R"("bigFileNums": )" << restoreInfo.bigFileNum << ", "; + ss << R"("bigFileSize": )" << restoreInfo.bigFileSize << ", "; + ss << R"("RestoreBigFileTime": )" << restoreInfo.bigFileSpendTime << ", "; + ss << R"("unTarFileNums": )" << restoreInfo.tarFileNum << ", "; + ss << R"("unTarFileSize": )" << restoreInfo.tarFileSize << ", "; + ss << R"("unTarTime": )" << restoreInfo.tarFileSpendTime << ", "; + ss << R"("totalFileNum": )" << restoreInfo.bigFileNum + restoreInfo.tarFileNum << ", "; + ss << R"("totalFileSize": )" << restoreInfo.bigFileSize + restoreInfo.tarFileSize << ", "; + ss << R"("restoreAllFileTime": )" << restoreInfo.totalFileSpendTime; int32_t err = static_cast(BError::Codes::OK); AppRadar::Info info (bundleName, "", ss.str()); AppRadar::GetInstance().RecordRestoreFuncRes(info, func, AppRadar::GetInstance().GetUserId(), @@ -745,7 +745,6 @@ int BackupExtExtension::DoBackup(const BJsonEntityExtensionConfig &usrConfig) vector includes = usrConfig.GetIncludes(); vector excludes = usrConfig.GetExcludes(); - auto proxy = ServiceProxy::GetInstance(); if (proxy == nullptr) { throw BError(BError::Codes::EXT_BROKEN_BACKUP_SA, std::generic_category().message(errno)); diff --git a/frameworks/native/backup_ext/src/sub_ext_extension.cpp b/frameworks/native/backup_ext/src/sub_ext_extension.cpp index 6038f48b4..0fed7a314 100644 --- a/frameworks/native/backup_ext/src/sub_ext_extension.cpp +++ b/frameworks/native/backup_ext/src/sub_ext_extension.cpp @@ -150,8 +150,8 @@ void BackupExtExtension::CheckTmpDirFileInfos(bool isSpecialVersion) if (!errFiles.empty()) { HILOGE("(Debug) The received file and idx is not same"); std::stringstream ss; - ss << "\"total_file\": \"" << idxFileInfos.size() << "\", \"restore_file\": \"" - << idxFileInfos.size() - errFiles.size() << "\"" << "\"info\": \"different received file and idx\""; + ss << R"("totalFile": )" << idxFileInfos.size() << R"(, "restoreFile": )" + << idxFileInfos.size() - errFiles.size() << R"(, "info": "different received file and idx")"; AppRadar::Info info (bundleName_, "", ss.str()); AppRadar::GetInstance().RecordRestoreFuncRes(info, "BackupExtExtension::CheckTmpDirFileInfos", AppRadar::GetInstance().GetUserId(), BizStageRestore::BIZ_STAGE_CHECK_DATA_FAIL, @@ -186,8 +186,8 @@ tuple> BackupExtExtension::CheckRestoreFileInfos() errFileInfos_.size()); if (errFiles.size()) { std::stringstream ss; - ss << "\"total_file\": \"" << endFileInfos_.size() << "\", \"restore_file\": \"" - << endFileInfos_.size() - errFileInfos_.size() << "\""; + ss << R"("totalFile": )" << endFileInfos_.size() << R"(, "restoreFile": )" + << endFileInfos_.size() - errFileInfos_.size(); AppRadar::Info info (bundleName_, "", ss.str()); AppRadar::GetInstance().RecordRestoreFuncRes(info, "BackupExtExtension::CheckRestoreFileInfos", AppRadar::GetInstance().GetUserId(), BizStageRestore::BIZ_STAGE_CHECK_DATA_FAIL, @@ -276,11 +276,13 @@ std::function BackupExtExtension::OnRestoreCallback( HILOGI("Current bundle will execute app done"); if (errCode == ERR_OK) { auto spendTime = extensionPtr->GetOnStartTimeCost(); - std::stringstream ss; - ss << "\"spend_time\": \"" << spendTime << "ms\""; - AppRadar::Info info (extensionPtr->bundleName_, "", ss.str()); - AppRadar::GetInstance().RecordRestoreFuncRes(info, "BackupExtExtension::OnRestoreCallback", - AppRadar::GetInstance().GetUserId(), BizStageRestore::BIZ_STAGE_ON_RESTORE, ERR_OK); + if (spendTime >= BConstants::MAX_TIME_COST) { + std::stringstream ss; + ss << R"("spendTime": )"<< spendTime << "ms"; + AppRadar::Info info (extensionPtr->bundleName_, "", ss.str()); + AppRadar::GetInstance().RecordRestoreFuncRes(info, "BackupExtExtension::OnRestoreCallback", + AppRadar::GetInstance().GetUserId(), BizStageRestore::BIZ_STAGE_ON_RESTORE, ERR_OK); + } } extensionPtr->FinishOnProcessTask(); if (errMsg.empty()) { @@ -309,11 +311,13 @@ std::function BackupExtExtension::OnRestoreExCallbac } if (errCode == ERR_OK && !restoreRetInfo.empty()) { auto spendTime = extensionPtr->GetOnStartTimeCost(); - std::stringstream ss; - ss << "\"spend_time\": \"" << spendTime << "ms\""; - AppRadar::Info info (extensionPtr->bundleName_, "", ss.str()); - AppRadar::GetInstance().RecordRestoreFuncRes(info, "BackupExtExtension::OnRestoreExCallback", - AppRadar::GetInstance().GetUserId(), BizStageRestore::BIZ_STAGE_ON_RESTORE, ERR_OK); + if (spendTime >= BConstants::MAX_TIME_COST) { + std::stringstream ss; + ss << R"("spendTime": )"<< spendTime << "ms"; + AppRadar::Info info (extensionPtr->bundleName_, "", ss.str()); + AppRadar::GetInstance().RecordRestoreFuncRes(info, "BackupExtExtension::OnRestoreExCallback", + AppRadar::GetInstance().GetUserId(), BizStageRestore::BIZ_STAGE_ON_RESTORE, ERR_OK); + } } extensionPtr->FinishOnProcessTask(); extensionPtr->extension_->InvokeAppExtMethod(errCode, restoreRetInfo); @@ -367,12 +371,14 @@ std::function BackupExtExtension::IncreOnRestoreExCa } if (errCode == ERR_OK && !restoreRetInfo.empty()) { auto spendTime = extensionPtr->GetOnStartTimeCost(); - std::stringstream ss; - ss << "\"spend_time\": \"" << spendTime << "ms\""; - AppRadar::Info info (extensionPtr->bundleName_, "", ss.str()); - AppRadar::GetInstance().RecordRestoreFuncRes(info, "BackupExtExtension::IncreOnRestoreExCallback", - AppRadar::GetInstance().GetUserId(), - BizStageRestore::BIZ_STAGE_ON_RESTORE, ERR_OK); + if (spendTime >= BConstants::MAX_TIME_COST) { + std::stringstream ss; + ss << R"("spendTime": )"<< spendTime << "ms"; + AppRadar::Info info (extensionPtr->bundleName_, "", ss.str()); + AppRadar::GetInstance().RecordRestoreFuncRes(info, "BackupExtExtension::IncreOnRestoreExCallback", + AppRadar::GetInstance().GetUserId(), + BizStageRestore::BIZ_STAGE_ON_RESTORE, ERR_OK); + } } extensionPtr->FinishOnProcessTask(); extensionPtr->extension_->InvokeAppExtMethod(errCode, restoreRetInfo); @@ -405,11 +411,13 @@ std::function BackupExtExtension::IncreOnRestoreCall HILOGI("Current bundle will execute app done"); if (errCode == ERR_OK) { auto spendTime = extensionPtr->GetOnStartTimeCost(); - std::stringstream ss; - ss << "\"spend_time\": \"" << spendTime << "ms\""; - AppRadar::Info info (extensionPtr->bundleName_, "", ss.str()); - AppRadar::GetInstance().RecordRestoreFuncRes(info, "BackupExtExtension::IncreOnRestoreCallback", - AppRadar::GetInstance().GetUserId(), BizStageRestore::BIZ_STAGE_ON_RESTORE, ERR_OK); + if (spendTime >= BConstants::MAX_TIME_COST) { + std::stringstream ss; + ss << R"("spendTime": )"<< spendTime << "ms"; + AppRadar::Info info (extensionPtr->bundleName_, "", ss.str()); + AppRadar::GetInstance().RecordRestoreFuncRes(info, "BackupExtExtension::IncreOnRestoreCallback", + AppRadar::GetInstance().GetUserId(), BizStageRestore::BIZ_STAGE_ON_RESTORE, ERR_OK); + } } extensionPtr->FinishOnProcessTask(); if (errMsg.empty()) { @@ -448,11 +456,13 @@ std::function BackupExtExtension::OnBackupCall extensionPtr->FinishOnProcessTask(); if (errCode == ERR_OK) { auto spendTime = extensionPtr->GetOnStartTimeCost(); - AppRadar::Info info(extensionPtr->bundleName_, "", string("\"spend_time\":\" "). - append(to_string(spendTime)).append(string("ms\""))); - AppRadar::GetInstance().RecordBackupFuncRes(info, "BackupExtExtension::OnBackupCallback", - AppRadar::GetInstance().GetUserId(), BizStageBackup::BIZ_STAGE_ON_BACKUP, - static_cast(ERR_OK)); + if (spendTime >= BConstants::MAX_TIME_COST) { + AppRadar::Info info(extensionPtr->bundleName_, "", string("\"spend_time\":\" "). + append(to_string(spendTime)).append(string("ms\""))); + AppRadar::GetInstance().RecordBackupFuncRes(info, "BackupExtExtension::OnBackupCallback", + AppRadar::GetInstance().GetUserId(), BizStageBackup::BIZ_STAGE_ON_BACKUP, + static_cast(ERR_OK)); + } extensionPtr->AsyncTaskBackup(extensionPtr->extension_->GetUsrConfig()); return; } @@ -485,11 +495,13 @@ std::function BackupExtExtension::OnBackupExCa if (errCode == ERR_OK) { if (backupExRetInfo.size()) { auto spendTime = extensionPtr->GetOnStartTimeCost(); - AppRadar::Info info(extensionPtr->bundleName_, "", string("\"spend_time\":\" "). - append(to_string(spendTime)).append(string("ms\""))); - AppRadar::GetInstance().RecordBackupFuncRes(info, "BackupExtExtension::OnBackupExCallback", - AppRadar::GetInstance().GetUserId(), BizStageBackup::BIZ_STAGE_ON_BACKUP, - static_cast(ERR_OK)); + if (spendTime >= BConstants::MAX_TIME_COST) { + AppRadar::Info info(extensionPtr->bundleName_, "", string("\"spend_time\":\" "). + append(to_string(spendTime)).append(string("ms\""))); + AppRadar::GetInstance().RecordBackupFuncRes(info, "BackupExtExtension::OnBackupExCallback", + AppRadar::GetInstance().GetUserId(), BizStageBackup::BIZ_STAGE_ON_BACKUP, + static_cast(ERR_OK)); + } HILOGI("Will notify backup result report"); extensionPtr->FinishOnProcessTask(); extensionPtr->AsyncTaskBackup(extensionPtr->extension_->GetUsrConfig()); @@ -527,11 +539,13 @@ std::function BackupExtExtension::IncOnBackupC extPtr->FinishOnProcessTask(); if (errCode == ERR_OK) { auto spendTime = extPtr->GetOnStartTimeCost(); - AppRadar::Info info(extPtr->bundleName_, "", string("\"spend_time\":\" "). - append(to_string(spendTime)).append(string("ms\""))); - AppRadar::GetInstance().RecordBackupFuncRes(info, "BackupExtExtension::IncOnBackupCallback", - AppRadar::GetInstance().GetUserId(), BizStageBackup::BIZ_STAGE_ON_BACKUP, - static_cast(ERR_OK)); + if (spendTime >= BConstants::MAX_TIME_COST) { + AppRadar::Info info(extPtr->bundleName_, "", string("\"spend_time\":\" "). + append(to_string(spendTime)).append(string("ms\""))); + AppRadar::GetInstance().RecordBackupFuncRes(info, "BackupExtExtension::IncOnBackupCallback", + AppRadar::GetInstance().GetUserId(), BizStageBackup::BIZ_STAGE_ON_BACKUP, + static_cast(ERR_OK)); + } proxy->GetAppLocalListAndDoIncrementalBackup(); return; } @@ -567,11 +581,13 @@ std::function BackupExtExtension::IncOnBackupE if (errCode == ERR_OK) { if (backupExRetInfo.size()) { auto spendTime = extensionPtr->GetOnStartTimeCost(); - AppRadar::Info info(extensionPtr->bundleName_, "", string("\"spend_time\":\" "). - append(to_string(spendTime)).append(string("ms\""))); - AppRadar::GetInstance().RecordBackupFuncRes(info, "BackupExtExtension::IncOnBackupExCallback", - AppRadar::GetInstance().GetUserId(), BizStageBackup::BIZ_STAGE_ON_BACKUP, - static_cast(ERR_OK)); + if (spendTime >= BConstants::MAX_TIME_COST) { + AppRadar::Info info(extensionPtr->bundleName_, "", string("\"spend_time\":\" "). + append(to_string(spendTime)).append(string("ms\""))); + AppRadar::GetInstance().RecordBackupFuncRes(info, "BackupExtExtension::IncOnBackupExCallback", + AppRadar::GetInstance().GetUserId(), BizStageBackup::BIZ_STAGE_ON_BACKUP, + static_cast(ERR_OK)); + } HILOGI("Start GetAppLocalListAndDoIncrementalBackup"); extensionPtr->FinishOnProcessTask(); proxy->GetAppLocalListAndDoIncrementalBackup(); @@ -976,11 +992,18 @@ int BackupExtExtension::DoIncrementalBackupTask(UniqueFd incrementalFd, UniqueFd vector bigFiles; CompareFiles(move(incrementalFd), move(manifestFd), allFiles, smallFiles, bigFiles); auto ret = DoIncrementalBackup(allFiles, smallFiles, bigFiles); - auto end = std::chrono::system_clock::now(); - auto cost = to_string(std::chrono::duration_cast(end - start).count()); - AppRadar::Info info(bundleName_, "", string("\"spend_time\":").append(cost).append(string("ms\""))); - AppRadar::GetInstance().RecordBackupFuncRes(info, "BackupExtExtension::AsyncTaskDoIncrementalBackup", - AppRadar::GetInstance().GetUserId(), BizStageBackup::BIZ_STAGE_DO_BACKUP, static_cast(ret)); + if (ret == ERR_OK) { + auto end = std::chrono::system_clock::now(); + auto cost = std::chrono::duration_cast(end - start).count(); + if (cost >= BConstants::MAX_TIME_COST) { + std::stringstream ss; + ss << R"("spendTime": )"<< cost << R"(ms, "totalFiles": )" << allFiles.size() << R"(, "smallFiles": )" + << smallFiles.size() << R"(, "bigFiles": )" << bigFiles.size(); + AppRadar::Info info(bundleName_, "", ss.str()); + AppRadar::GetInstance().RecordBackupFuncRes(info, "BackupExtExtension::DoIncrementalBackupTask", + AppRadar::GetInstance().GetUserId(), BizStageBackup::BIZ_STAGE_DO_BACKUP, static_cast(ret)); + } + } return ret; } diff --git a/frameworks/native/backup_kit_inner/src/b_incremental_backup_session.cpp b/frameworks/native/backup_kit_inner/src/b_incremental_backup_session.cpp index cfaaf5ef5..b35f4549b 100644 --- a/frameworks/native/backup_kit_inner/src/b_incremental_backup_session.cpp +++ b/frameworks/native/backup_kit_inner/src/b_incremental_backup_session.cpp @@ -97,13 +97,9 @@ ErrCode BIncrementalBackupSession::AppendBundles(vector bundle return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } - int32_t res = proxy->AppendBundlesIncrementalBackupSession(bundlesToBackup); + ErrCode res = proxy->AppendBundlesIncrementalBackupSession(bundlesToBackup); if (res != 0) { - std::string ss; - for (const auto &bundle : bundlesToBackup) { - ss += bundle.bundleName + ", "; - } - AppRadar::Info info(ss.c_str(), "", ""); + AppRadar::Info info("", "", ""); AppRadar::GetInstance().RecordBackupFuncRes(info, "BIncrementalBackupSession::AppendBundles", AppRadar::GetInstance().GetUserId(), BizStageBackup::BIZ_STAGE_APPEND_BUNDLES_FAIL, res); } @@ -120,11 +116,7 @@ ErrCode BIncrementalBackupSession::AppendBundles(vector bundle int32_t res = proxy->AppendBundlesIncrementalBackupSession(bundlesToBackup, infos); if (res != 0) { - std::string ss; - for (const auto &bundle : bundlesToBackup) { - ss += bundle.bundleName + ", "; - } - AppRadar::Info info(ss.c_str(), "", "AppendBundles with infos"); + AppRadar::Info info("", "", "AppendBundles with infos"); AppRadar::GetInstance().RecordBackupFuncRes(info, "BIncrementalBackupSession::AppendBundles", AppRadar::GetInstance().GetUserId(), BizStageBackup::BIZ_STAGE_APPEND_BUNDLES_FAIL, res); } diff --git a/frameworks/native/backup_kit_inner/src/b_incremental_restore_session.cpp b/frameworks/native/backup_kit_inner/src/b_incremental_restore_session.cpp index ed51e8cb9..1198414a5 100644 --- a/frameworks/native/backup_kit_inner/src/b_incremental_restore_session.cpp +++ b/frameworks/native/backup_kit_inner/src/b_incremental_restore_session.cpp @@ -57,8 +57,7 @@ unique_ptr BIncrementalRestoreSession::Init(Callback HILOGE("Failed to Restore because of %{public}d", res); AppRadar::Info info ("", "", "create restore session failed"); AppRadar::GetInstance().RecordRestoreFuncRes(info, "BIncrementalRestoreSession::Init", - AppRadar::GetInstance().GetUserId(), - BizStageRestore::BIZ_STAGE_CREATE_RESTORE_SESSION_FAIL, res); + AppRadar::GetInstance().GetUserId(), BizStageRestore::BIZ_STAGE_CREATE_RESTORE_SESSION_FAIL, res); return nullptr; } @@ -104,7 +103,13 @@ ErrCode BIncrementalRestoreSession::AppendBundles(UniqueFd remoteCap, vectorAppendBundlesRestoreSession(move(remoteCap), bundlesToRestore); + ErrCode res = proxy->AppendBundlesRestoreSession(move(remoteCap), bundlesToRestore); + if (res != 0) { + AppRadar::Info info("", "", ""); + AppRadar::GetInstance().RecordRestoreFuncRes(info, "BIncrementalRestoreSession::AppendBundles", + AppRadar::GetInstance().GetUserId(), BizStageRestore::BIZ_STAGE_APPEND_BUNDLES_FAIL, res); + } + return res; } ErrCode BIncrementalRestoreSession::AppendBundles(UniqueFd remoteCap, vector bundlesToRestore, @@ -114,8 +119,13 @@ ErrCode BIncrementalRestoreSession::AppendBundles(UniqueFd remoteCap, vectorAppendBundlesRestoreSession(move(remoteCap), bundlesToRestore, detailInfos); + ErrCode res = proxy->AppendBundlesRestoreSession(move(remoteCap), bundlesToRestore, detailInfos); + if (res != 0) { + AppRadar::Info info("", "", ""); + AppRadar::GetInstance().RecordRestoreFuncRes(info, "BIncrementalRestoreSession::AppendBundles", + AppRadar::GetInstance().GetUserId(), BizStageRestore::BIZ_STAGE_APPEND_BUNDLES_FAIL, res); + } + return res; } ErrCode BIncrementalRestoreSession::Release() diff --git a/frameworks/native/backup_kit_inner/src/b_incremental_session_restore_async.cpp b/frameworks/native/backup_kit_inner/src/b_incremental_session_restore_async.cpp index 75c7e3cbc..adda12462 100644 --- a/frameworks/native/backup_kit_inner/src/b_incremental_session_restore_async.cpp +++ b/frameworks/native/backup_kit_inner/src/b_incremental_session_restore_async.cpp @@ -65,8 +65,7 @@ shared_ptr BIncrementalSessionRestoreAsync::Ini HILOGE("Failed to Restore because of %{public}d", res); AppRadar::Info info ("", "", "create restore session failed"); AppRadar::GetInstance().RecordRestoreFuncRes(info, "BIncrementalSessionRestoreAsync::Init", - AppRadar::GetInstance().GetUserId(), - BizStageRestore::BIZ_STAGE_CREATE_RESTORE_SESSION_FAIL, res); + AppRadar::GetInstance().GetUserId(), BizStageRestore::BIZ_STAGE_CREATE_RESTORE_SESSION_FAIL, res); return nullptr; } @@ -107,8 +106,14 @@ ErrCode BIncrementalSessionRestoreAsync::AppendBundles(UniqueFd remoteCap, if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } - return proxy->AppendBundlesRestoreSession(move(remoteCap), bundlesToRestore, detailInfos, restoreType, + ErrCode res = proxy->AppendBundlesRestoreSession(move(remoteCap), bundlesToRestore, detailInfos, restoreType, userId); + if (res != 0) { + AppRadar::Info info("", "", ""); + AppRadar::GetInstance().RecordRestoreFuncRes(info, "BIncrementalSessionRestoreAsync::AppendBundles", + AppRadar::GetInstance().GetUserId(), BizStageRestore::BIZ_STAGE_APPEND_BUNDLES_FAIL, res); + } + return res; } ErrCode BIncrementalSessionRestoreAsync::AppendBundles(UniqueFd remoteCap, @@ -120,8 +125,13 @@ ErrCode BIncrementalSessionRestoreAsync::AppendBundles(UniqueFd remoteCap, if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } - - return proxy->AppendBundlesRestoreSession(move(remoteCap), bundlesToRestore, restoreType, userId); + ErrCode res = proxy->AppendBundlesRestoreSession(move(remoteCap), bundlesToRestore, restoreType, userId); + if (res != 0) { + AppRadar::Info info("", "", ""); + AppRadar::GetInstance().RecordRestoreFuncRes(info, "BIncrementalSessionRestoreAsync::AppendBundles", + AppRadar::GetInstance().GetUserId(), BizStageRestore::BIZ_STAGE_APPEND_BUNDLES_FAIL, res); + } + return res; } ErrCode BIncrementalSessionRestoreAsync::Release() diff --git a/frameworks/native/backup_kit_inner/src/b_session_backup.cpp b/frameworks/native/backup_kit_inner/src/b_session_backup.cpp index f20285515..724477634 100644 --- a/frameworks/native/backup_kit_inner/src/b_session_backup.cpp +++ b/frameworks/native/backup_kit_inner/src/b_session_backup.cpp @@ -109,11 +109,7 @@ ErrCode BSessionBackup::AppendBundles(vector bundlesToBackup) int32_t res = proxy->AppendBundlesBackupSession(bundlesToBackup); if (res != 0) { - std::string ss; - for (const auto &bundleName:bundlesToBackup) { - ss += bundleName + ", "; - } - AppRadar::Info info(ss.c_str(), "", ""); + AppRadar::Info info("", "", ""); AppRadar::GetInstance().RecordBackupFuncRes(info, "BSessionBackup::AppendBundles", AppRadar::GetInstance().GetUserId(), BizStageBackup::BIZ_STAGE_APPEND_BUNDLES_FAIL, res); } @@ -129,11 +125,7 @@ ErrCode BSessionBackup::AppendBundles(vector bundlesToBackup, vector int32_t res = proxy->AppendBundlesDetailsBackupSession(bundlesToBackup, detailInfos); if (res != 0) { - std::string ss; - for (const auto &bundleName:bundlesToBackup) { - ss += bundleName + ", "; - } - AppRadar::Info info(ss.c_str(), "", ""); + AppRadar::Info info("", "", ""); AppRadar::GetInstance().RecordBackupFuncRes(info, "BSessionBackup::AppendBundles", AppRadar::GetInstance().GetUserId(), BizStageBackup::BIZ_STAGE_APPEND_BUNDLES_FAIL, res); } diff --git a/frameworks/native/backup_kit_inner/src/b_session_restore.cpp b/frameworks/native/backup_kit_inner/src/b_session_restore.cpp index 0c37d2603..c3a94d0e5 100644 --- a/frameworks/native/backup_kit_inner/src/b_session_restore.cpp +++ b/frameworks/native/backup_kit_inner/src/b_session_restore.cpp @@ -57,8 +57,7 @@ unique_ptr BSessionRestore::Init(Callbacks callbacks) HILOGE("Failed to Restore because of %{public}d", res); AppRadar::Info info ("", "", "create restore session failed"); AppRadar::GetInstance().RecordRestoreFuncRes(info, "BSessionRestore::Init", - AppRadar::GetInstance().GetUserId(), - BizStageRestore::BIZ_STAGE_CREATE_RESTORE_SESSION_FAIL, res); + AppRadar::GetInstance().GetUserId(), BizStageRestore::BIZ_STAGE_CREATE_RESTORE_SESSION_FAIL, res); return nullptr; } @@ -106,7 +105,13 @@ ErrCode BSessionRestore::AppendBundles(UniqueFd remoteCap, vector bu if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } - return proxy->AppendBundlesRestoreSession(move(remoteCap), bundlesToRestore, detailInfos); + ErrCode res = proxy->AppendBundlesRestoreSession(move(remoteCap), bundlesToRestore, detailInfos); + if (res != 0) { + AppRadar::Info info("", "", ""); + AppRadar::GetInstance().RecordRestoreFuncRes(info, "BSessionRestore::AppendBundles", + AppRadar::GetInstance().GetUserId(), BizStageRestore::BIZ_STAGE_APPEND_BUNDLES_FAIL, res); + } + return res; } ErrCode BSessionRestore::AppendBundles(UniqueFd remoteCap, vector bundlesToRestore) @@ -115,8 +120,13 @@ ErrCode BSessionRestore::AppendBundles(UniqueFd remoteCap, vector bu if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } - - return proxy->AppendBundlesRestoreSession(move(remoteCap), bundlesToRestore); + ErrCode res = proxy->AppendBundlesRestoreSession(move(remoteCap), bundlesToRestore); + if (res != 0) { + AppRadar::Info info("", "", ""); + AppRadar::GetInstance().RecordRestoreFuncRes(info, "BSessionRestore::AppendBundles", + AppRadar::GetInstance().GetUserId(), BizStageRestore::BIZ_STAGE_APPEND_BUNDLES_FAIL, res); + } + return res; } ErrCode BSessionRestore::Finish() diff --git a/frameworks/native/backup_kit_inner/src/b_session_restore_async.cpp b/frameworks/native/backup_kit_inner/src/b_session_restore_async.cpp index b3cea05e1..c797d1d9f 100644 --- a/frameworks/native/backup_kit_inner/src/b_session_restore_async.cpp +++ b/frameworks/native/backup_kit_inner/src/b_session_restore_async.cpp @@ -66,8 +66,7 @@ shared_ptr BSessionRestoreAsync::Init(Callbacks callbacks) HILOGE("Failed to Restore because of %{public}d", res); AppRadar::Info info ("", "", "create restore session failed"); AppRadar::GetInstance().RecordRestoreFuncRes(info, "BSessionRestoreAsync::Init", - AppRadar::GetInstance().GetUserId(), - BizStageRestore::BIZ_STAGE_CREATE_RESTORE_SESSION_FAIL, res); + AppRadar::GetInstance().GetUserId(), BizStageRestore::BIZ_STAGE_CREATE_RESTORE_SESSION_FAIL, res); return nullptr; } @@ -108,8 +107,14 @@ ErrCode BSessionRestoreAsync::AppendBundles(UniqueFd remoteCap, if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } - return proxy->AppendBundlesRestoreSession(move(remoteCap), bundlesToRestore, detailInfos, restoreType, + ErrCode res = proxy->AppendBundlesRestoreSession(move(remoteCap), bundlesToRestore, detailInfos, restoreType, userId); + if (res != 0) { + AppRadar::Info info("", "", ""); + AppRadar::GetInstance().RecordRestoreFuncRes(info, "BSessionRestoreAsync::AppendBundles", + AppRadar::GetInstance().GetUserId(), BizStageRestore::BIZ_STAGE_APPEND_BUNDLES_FAIL, res); + } + return res; } ErrCode BSessionRestoreAsync::AppendBundles(UniqueFd remoteCap, @@ -122,7 +127,13 @@ ErrCode BSessionRestoreAsync::AppendBundles(UniqueFd remoteCap, return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } - return proxy->AppendBundlesRestoreSession(move(remoteCap), bundlesToRestore, restoreType, userId); + ErrCode res = proxy->AppendBundlesRestoreSession(move(remoteCap), bundlesToRestore, restoreType, userId); + if (res != 0) { + AppRadar::Info info("", "", ""); + AppRadar::GetInstance().RecordRestoreFuncRes(info, "BSessionRestoreAsync::AppendBundles", + AppRadar::GetInstance().GetUserId(), BizStageRestore::BIZ_STAGE_APPEND_BUNDLES_FAIL, res); + } + return res; } ErrCode BSessionRestoreAsync::Release() diff --git a/frameworks/native/backup_kit_inner/src/service_incremental_reverse.cpp b/frameworks/native/backup_kit_inner/src/service_incremental_reverse.cpp index ec842c432..ba1e761c5 100644 --- a/frameworks/native/backup_kit_inner/src/service_incremental_reverse.cpp +++ b/frameworks/native/backup_kit_inner/src/service_incremental_reverse.cpp @@ -16,6 +16,7 @@ #include "service_reverse.h" #include "b_error/b_error.h" +#include "b_radar/b_radar.h" #include "filemgmt_libhilog.h" namespace OHOS::FileManagement::Backup { diff --git a/frameworks/native/backup_kit_inner/src/service_proxy.cpp b/frameworks/native/backup_kit_inner/src/service_proxy.cpp index f3e1854ba..e05fb5138 100644 --- a/frameworks/native/backup_kit_inner/src/service_proxy.cpp +++ b/frameworks/native/backup_kit_inner/src/service_proxy.cpp @@ -301,13 +301,6 @@ ErrCode ServiceProxy::AppendBundlesRestoreSession(UniqueFd fd, const vector(IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_RESTORE_SESSION), data, reply, option); if (ret != NO_ERROR) { string str = "Failed to send out the request because of " + to_string(ret); - std::string ss; - for (const auto &bundleName : bundleNames) { - ss += bundleName + ", "; - } - AppRadar::Info info(ss.c_str(), "", str); - AppRadar::GetInstance().RecordRestoreFuncRes(info, "ServiceProxy::AppendBundlesRestoreSession", userId, - BizStageRestore::BIZ_STAGE_APPEND_BUNDLES_FAIL, ret); return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); } return reply.ReadInt32(); @@ -473,7 +459,7 @@ sptr ServiceProxy::GetInstance() AppRadar::Info info("", "", "\"reason\":\"Load backup sa timeout\""); AppRadar::GetInstance().RecordBackupFuncRes(info, "ServiceProxy::GetInstance", AppRadar::GetInstance().GetUserId(), BizStageBackup::BIZ_STAGE_BOOT_BACKUP_SA_FAIL, - static_cast(BError::Codes::SA_INVAL_ARG)); + BError(BError::Codes::SA_INVAL_ARG).GetCode()); return nullptr; } return serviceProxy_; diff --git a/services/backup_sa/include/module_ipc/service.h b/services/backup_sa/include/module_ipc/service.h index 828c311bc..a093d680c 100644 --- a/services/backup_sa/include/module_ipc/service.h +++ b/services/backup_sa/include/module_ipc/service.h @@ -38,6 +38,11 @@ struct ExtensionMutexInfo { ExtensionMutexInfo(std::string bundleName_) : bundleName(bundleName_) {}; }; +struct BundleTaskInfo { + std::string reportTime; + ErrCode errCode; +}; + class Service : public SystemAbility, public ServiceStub, protected NoCopyable { DECLARE_SYSTEM_ABILITY(Service); @@ -262,7 +267,7 @@ public: * @param bundleName 应用名称 * */ - void ClearResidualBundleData(const std::string &bundleName); + ErrCode ClearResidualBundleData(const std::string &bundleName); /** * @brief 添加清理记录 @@ -517,6 +522,26 @@ private: void TimeoutRadarReport(IServiceReverse::Scenario scenario, std::string &bundleName); + void OnBundleStarted(BError error, sptr session, const BundleName &bundleName); + + void HandleExceptionOnAppendBundles(sptr session, const vector &appendBundleNames, + const vector &restoreBundleNames); + + void BundleBeginRadarReport(const std::string &bundleName, const ErrCode errCode, + const IServiceReverse::Scenario scenario); + + void BundleEndRadarReport(const std::string &bundleName, const ErrCode errCode, + const IServiceReverse::Scenario scenario); + + void FileReadyRadarReport(const std::string &bundleName, const std::string &fileName, const ErrCode errCode, + const IServiceReverse::Scenario scenario); + + void ExtensionConnectFailRadarReport(const std::string &bundleName, const ErrCode errCode, + const IServiceReverse::Scenario scenario); + + void UpdateFailedBundles(const std::string &bundleName, BundleTaskInfo taskInfo); + + void ClearFailedBundles(); void CreateDirIfNotExist(const std::string &path); private: static sptr instance_; @@ -538,8 +563,11 @@ private: OHOS::ThreadPool threadPool_; std::mutex extensionMutexLock_; + std::mutex failedBundlesLock_; public: std::map> backupExtMutexMap_; + std::map failedBundles_; + std::atomic successBundlesNum_ {0}; }; } // namespace OHOS::FileManagement::Backup diff --git a/services/backup_sa/src/module_app_gallery/app_gallery_dispose_proxy.cpp b/services/backup_sa/src/module_app_gallery/app_gallery_dispose_proxy.cpp index 5818f7061..2cfb5b10e 100644 --- a/services/backup_sa/src/module_app_gallery/app_gallery_dispose_proxy.cpp +++ b/services/backup_sa/src/module_app_gallery/app_gallery_dispose_proxy.cpp @@ -114,11 +114,8 @@ void RecordDoDisposeRes(const std::string &bundleName, break; case AppGalleryDisposeProxy::DisposeOperation::END_RESTORE: AppRadar::GetInstance().RecordRestoreFuncRes(info, "EndRestore", AppRadar::GetInstance().GetUserId(), - BizStageRestore::BIZ_STAGE_END_DISPOSE_FAIL, err); - break; - default: - break; - } + BizStageRestore::BIZ_STAGE_END_DISPOSE, static_cast(res)); + return res; } DisposeErr AppGalleryDisposeProxy::DoDispose(const std::string &bundleName, DisposeOperation disposeOperation) @@ -152,7 +149,6 @@ DisposeErr AppGalleryDisposeProxy::DoDispose(const std::string &bundleName, Disp if (ret != ERR_NONE) { HILOGI("SendRequest error, code=%{public}d, bundleName=%{public}s , appindex =%{public}d", ret, bundleDetailInfo.bundleName.c_str(), bundleDetailInfo.bundleIndex); - RecordDoDisposeRes(bundleName, disposeOperation, ret); return DisposeErr::REQUEST_FAIL; } diff --git a/services/backup_sa/src/module_ipc/service.cpp b/services/backup_sa/src/module_ipc/service.cpp index c2af171df..5ac1aa771 100644 --- a/services/backup_sa/src/module_ipc/service.cpp +++ b/services/backup_sa/src/module_ipc/service.cpp @@ -51,6 +51,7 @@ #include "b_radar/b_radar.h" #include "b_resources/b_constants.h" #include "b_sa/b_sa_utils.h" +#include "b_utils/b_time.h" #include "bundle_mgr_client.h" #include "filemgmt_libhilog.h" #include "hisysevent.h" @@ -103,6 +104,112 @@ static inline int32_t GetUserIdDefault() return multiuser.userId; } +void OnStartResRadarReport(const IServiceReverse::Scenario scenario, + const std::vector &bundleNameList, int32_t stage) +{ + std::stringstream ss; + ss << "failedBundles:{"; + for (auto &bundleName : bundleNameList) { + ss << bundleName << ", "; + } + ss << "}"; + AppRadar::Info info("", "", ss.str()); + if (scenario == IServiceReverse::Scenario::RESTORE) { + AppRadar::GetInstance().RecordRestoreFuncRes(info, "Service::OnStart", GetUserIdDefault(), + static_cast(stage), ERR_OK); + } else if (scenario == IServiceReverse::Scenario::BACKUP) { + AppRadar::GetInstance().RecordBackupFuncRes(info, "Service::OnStart", GetUserIdDefault(), + static_cast(stage), ERR_OK); + } +} + +void Service::ClearFailedBundles() +{ + std::lock_guard lock(failedBundlesLock_); + failedBundles_.clear(); +} + +void Service::UpdateFailedBundles(const std::string &bundleName, BundleTaskInfo taskInfo) +{ + std::lock_guard lock(failedBundlesLock_); + failedBundles_[bundleName] = taskInfo; +} + +void Service::BundleBeginRadarReport(const std::string &bundleName, const ErrCode errCode, + const IServiceReverse::Scenario scenario) +{ + if (errCode == ERR_OK || errCode == BError(BError::Codes::SA_BOOT_EXT_FAIL).GetCode()) { + return; + } + BundleTaskInfo taskInfo; + taskInfo.reportTime = TimeUtils::GetCurrentTime(); + taskInfo.errCode = errCode; + UpdateFailedBundles(bundleName, taskInfo); + AppRadar::Info info(bundleName, "", ""); + if (scenario == IServiceReverse::Scenario::RESTORE) { + AppRadar::GetInstance().RecordRestoreFuncRes(info, "Service::BundleBeginRadarReport", + GetUserIdDefault(), BizStageRestore::BIZ_STAGE_APPEND_BUNDLES_FAIL, errCode); + } else if (scenario == IServiceReverse::Scenario::BACKUP) { + AppRadar::GetInstance().RecordBackupFuncRes(info, "Service::BundleBeginRadarReport", + GetUserIdDefault(), BizStageBackup::BIZ_STAGE_APPEND_BUNDLES_FAIL, errCode); + } +} + +void Service::BundleEndRadarReport(const std::string &bundleName, const ErrCode errCode, + const IServiceReverse::Scenario scenario) +{ + if (errCode == ERR_OK) { + successBundlesNum_++; + return; + } + BundleTaskInfo taskInfo; + taskInfo.reportTime = TimeUtils::GetCurrentTime(); + taskInfo.errCode = errCode; + UpdateFailedBundles(bundleName, taskInfo); + AppRadar::Info info(bundleName, "", ""); + if (scenario == IServiceReverse::Scenario::RESTORE) { + AppRadar::GetInstance().RecordRestoreFuncRes(info, "Service::BundleEndRadarReport", + GetUserIdDefault(), BizStageRestore::BIZ_STAGE_EXECU_FAIL, errCode); + } else if (scenario == IServiceReverse::Scenario::BACKUP) { + AppRadar::GetInstance().RecordBackupFuncRes(info, "Service::BundleEndRadarReport", + GetUserIdDefault(), BizStageBackup::BIZ_STAGE_EXECU_FAIL, errCode); + } +} + +void Service::FileReadyRadarReport(const std::string &bundleName, const std::string &fileName, const ErrCode errCode, + const IServiceReverse::Scenario scenario) +{ + if (errCode == ERR_OK) { + return; + } + std::string fileNameReport = std::string("fileName:\"") + GetAnonyPath(fileName) + "\""; + AppRadar::Info info(bundleName, "", fileNameReport); + if (scenario == IServiceReverse::Scenario::RESTORE) { + AppRadar::GetInstance().RecordRestoreFuncRes(info, "Service::FileReadyRadarReport", + GetUserIdDefault(), BizStageRestore::BIZ_STAGE_GET_FILE_HANDLE_FAIL, errCode); + } else if (scenario == IServiceReverse::Scenario::BACKUP) { + AppRadar::GetInstance().RecordBackupFuncRes(info, "Service::FileReadyRadarReport", + GetUserIdDefault(), BizStageBackup::BIZ_STAGE_DO_BACKUP, errCode); + } +} + +void Service::ExtensionConnectFailRadarReport(const std::string &bundleName, const ErrCode errCode, + const IServiceReverse::Scenario scenario) +{ + std::stringstream ss; + ss << "errCode:" << errCode; + AppRadar::Info info(bundleName, "", ss.str()); + if (scenario == IServiceReverse::Scenario::RESTORE) { + AppRadar::GetInstance().RecordRestoreFuncRes(info, "Service::ExtensionConnectFailRadarReport", + GetUserIdDefault(), BizStageRestore::BIZ_STAGE_CONNECT_EXTENSION_FAIL, + BError(BError::Codes::SA_BOOT_EXT_FAIL).GetCode()); + } else if (scenario == IServiceReverse::Scenario::BACKUP) { + AppRadar::GetInstance().RecordBackupFuncRes(info, "Service::ExtensionConnectFailRadarReport", + GetUserIdDefault(), BizStageBackup::BIZ_STAGE_CONNECT_EXTENSION_FAIL, + BError(BError::Codes::SA_BOOT_EXT_FAIL).GetCode()); + } +} + void Service::OnStart() { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); @@ -116,6 +223,15 @@ void Service::OnStart() residualBundleNameList = clearRecorder_->GetAllClearBundleRecords(); } if (!bundleNameList.empty() || !residualBundleNameList.empty()) { + IServiceReverse::Scenario scenario = session_->GetScenario(); + if (!bundleNameList.empty()) { + OnStartResRadarReport(scenario, bundleNameList, + static_cast(BizStageBackup::BIZ_STAGE_ONSTART_DISPOSE)); + } + if (!residualBundleNameList.empty()) { + OnStartResRadarReport(scenario, residualBundleNameList, + static_cast(BizStageBackup::BIZ_STAGE_ONSTART_RESIDUAL)); + } SetOccupySession(true); session_->Active( { @@ -211,6 +327,9 @@ UniqueFd Service::GetLocalCapabilities() void Service::StopAll(const wptr &obj, bool force) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + std::lock_guard lock(failedBundlesLock_); + failedBundles_.clear(); + successBundlesNum_ = 0; session_->Deactive(obj, force); } @@ -307,12 +426,17 @@ ErrCode Service::InitRestoreSession(sptr remote) HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); try { VerifyCaller(); - return session_->Active({ + ErrCode errCode = session_->Active({ .clientToken = IPCSkeleton::GetCallingTokenID(), .scenario = IServiceReverse::Scenario::RESTORE, .clientProxy = remote, .userId = GetUserIdDefault(), }); + if (errCode == 0) { + ClearFailedBundles(); + successBundlesNum_ = 0; + } + return errCode; } catch (const BError &e) { StopAll(nullptr, true); return e.GetCode(); @@ -333,12 +457,17 @@ ErrCode Service::InitBackupSession(sptr remote) int32_t oldSize = StorageMgrAdapter::UpdateMemPara(BConstants::BACKUP_VFS_CACHE_PRESSURE); HILOGE("InitBackupSession oldSize %{public}d", oldSize); session_->SetMemParaCurSize(oldSize); - return session_->Active({ + ErrCode errCode = session_->Active({ .clientToken = IPCSkeleton::GetCallingTokenID(), .scenario = IServiceReverse::Scenario::BACKUP, .clientProxy = remote, .userId = GetUserIdDefault(), }); + if (errCode == 0) { + ClearFailedBundles(); + successBundlesNum_ = 0; + } + return errCode; } catch (const BError &e) { StopAll(nullptr, true); return e.GetCode(); @@ -376,7 +505,7 @@ static bool SpecialVersion(const string &versionName) return false; } -static void OnBundleStarted(BError error, sptr session, const BundleName &bundleName) +void Service::OnBundleStarted(BError error, sptr session, const BundleName &bundleName) { IServiceReverse::Scenario scenario = session->GetScenario(); if (scenario == IServiceReverse::Scenario::RESTORE && BackupPara().GetBackupOverrideIncrementalRestore() && @@ -385,6 +514,7 @@ static void OnBundleStarted(BError error, sptr session, const } else if (scenario == IServiceReverse::Scenario::RESTORE) { session->GetServiceReverseProxy()->RestoreOnBundleStarted(error, bundleName); } + BundleBeginRadarReport(bundleName, error.GetCode(), scenario); } static vector GetRestoreBundleNames(UniqueFd fd, @@ -438,7 +568,7 @@ static vector GetRestoreBundleNames(UniqueFd fd, return restoreBundleInfos; } -static void HandleExceptionOnAppendBundles(sptr session, +void Service::HandleExceptionOnAppendBundles(sptr session, const vector &appendBundleNames, const vector &restoreBundleNames) { if (appendBundleNames.size() != restoreBundleNames.size()) { @@ -674,6 +804,8 @@ ErrCode Service::AppendBundlesBackupSession(const vector &bundleName if (info.allToBackup == false) { session_->GetServiceReverseProxy()->BackupOnBundleStarted( BError(BError::Codes::SA_FORBID_BACKUP_RESTORE), bundleNameIndexInfo); + BundleBeginRadarReport(bundleNameIndexInfo, BError(BError::Codes::SA_FORBID_BACKUP_RESTORE).GetCode(), + IServiceReverse::Scenario::BACKUP); session_->RemoveExtInfo(bundleNameIndexInfo); } } @@ -747,6 +879,8 @@ void Service::HandleCurGroupBackupInfos(std::vector if (info.allToBackup == false) { session_->GetServiceReverseProxy()->BackupOnBundleStarted( BError(BError::Codes::SA_FORBID_BACKUP_RESTORE), bundleNameIndexInfo); + BundleBeginRadarReport(bundleNameIndexInfo, BError(BError::Codes::SA_FORBID_BACKUP_RESTORE).GetCode(), + IServiceReverse::Scenario::BACKUP); session_->RemoveExtInfo(bundleNameIndexInfo); } BJsonUtil::BundleDetailInfo uniCastInfo; @@ -804,6 +938,12 @@ ErrCode Service::SAResultReport(const std::string bundleName, const std::string } else if (sennario == BackupRestoreScenario::INCREMENTAL_BACKUP) { session_->GetServiceReverseProxy()->IncrementalBackupOnResultReport(restoreRetInfo, bundleName); } + if (sennario == BackupRestoreScenario::FULL_RESTORE || sennario == BackupRestoreScenario::INCREMENTAL_RESTORE) { + BundleEndRadarReport(bundleName, errCode, IServiceReverse::Scenario::RESTORE); + } else if (sennario == BackupRestoreScenario::FULL_BACKUP || + sennario == BackupRestoreScenario::INCREMENTAL_BACKUP) { + BundleEndRadarReport(bundleName, errCode, IServiceReverse::Scenario::BACKUP); + } return SADone(errCode, bundleName); } @@ -894,6 +1034,7 @@ ErrCode Service::GetFileHandle(const string &bundleName, const string &fileName) BizStageRestore::BIZ_STAGE_GET_FILE_HANDLE_FAIL, errCode); } session_->GetServiceReverseProxy()->RestoreOnFileReady(bundleName, fileName, move(fd), errCode); + FileReadyRadarReport(bundleName, fileName, errCode, IServiceReverse::Scenario::RESTORE); } else { session_->SetExtFileNameRequest(bundleName, fileName); } @@ -918,15 +1059,6 @@ void Service::OnBackupExtensionDied(const string &&bundleName, bool isSecondCall OnAllBundlesFinished(BError(BError::Codes::OK)); return; } - int32_t errCode = BError(BError::Codes::EXT_ABILITY_DIED).GetCode(); - AppRadar::Info info (bundleName, "", ""); - if (session_->GetScenario() == IServiceReverse::Scenario::BACKUP) { - AppRadar::GetInstance().RecordBackupFuncRes(info, "Service::OnBackupExtensionDied", GetUserIdDefault(), - BizStageBackup::BIZ_STAGE_EXTENSION_ABNORMAL_EXIT, errCode); - } else if (session_->GetScenario() == IServiceReverse::Scenario::RESTORE) { - AppRadar::GetInstance().RecordRestoreFuncRes(info, "Service::OnBackupExtensionDied", GetUserIdDefault(), - BizStageRestore::BIZ_STAGE_EXTENSION_ABNORMAL_EXIT, errCode); - } try { string callName = move(bundleName); HILOGE("Backup <%{public}s> Extension Process Died", callName.c_str()); @@ -999,6 +1131,7 @@ void Service::ExtStart(const string &bundleName) if (scenario == IServiceReverse::Scenario::BACKUP) { auto ret = proxy->HandleBackup(session_->GetClearDataFlag(bundleName)); session_->GetServiceReverseProxy()->BackupOnBundleStarted(ret, bundleName); + BundleBeginRadarReport(bundleName, ret, scenario); if (ret) { ClearSessionAndSchedInfo(bundleName); NoticeClientFinish(bundleName, BError(BError::Codes::SA_INVAL_ARG)); @@ -1010,18 +1143,18 @@ void Service::ExtStart(const string &bundleName) } auto ret = proxy->HandleRestore(session_->GetClearDataFlag(bundleName)); session_->GetServiceReverseProxy()->RestoreOnBundleStarted(ret, bundleName); + BundleBeginRadarReport(bundleName, ret, scenario); auto fileNameVec = session_->GetExtFileNameRequest(bundleName); for (auto &fileName : fileNameVec) { int32_t errCode = 0; UniqueFd fd = proxy->GetFileHandle(fileName, errCode); session_->GetServiceReverseProxy()->RestoreOnFileReady(bundleName, fileName, move(fd), errCode); + FileReadyRadarReport(bundleName, fileName, errCode, scenario); } - return; } catch (...) { HILOGI("Unexpected exception, bundleName: %{public}s", bundleName.c_str()); ClearSessionAndSchedInfo(bundleName); NoticeClientFinish(bundleName, BError(BError::Codes::SA_INVAL_ARG)); - return; } } @@ -1046,18 +1179,21 @@ void Service::ReportOnExtConnectFailed(const IServiceReverse::Scenario scenario, } if (scenario == IServiceReverse::Scenario::BACKUP && session_->GetIsIncrementalBackup()) { session_->GetServiceReverseProxy()->IncrementalBackupOnBundleStarted(ret, bundleName); + BundleBeginRadarReport(bundleName, ret, scenario); } else if (scenario == IServiceReverse::Scenario::RESTORE && BackupPara().GetBackupOverrideIncrementalRestore() && session_->ValidRestoreDataType(RestoreTypeEnum::RESTORE_DATA_WAIT_SEND)) { session_->GetServiceReverseProxy()->IncrementalRestoreOnBundleStarted(ret, bundleName); - + BundleBeginRadarReport(bundleName, ret, scenario); DisposeErr disposeErr = AppGalleryDisposeProxy::GetInstance()->EndRestore(bundleName); HILOGI("ExtConnectFailed EndRestore, code=%{public}d, bundleName=%{public}s", disposeErr, bundleName.c_str()); } else if (scenario == IServiceReverse::Scenario::BACKUP) { session_->GetServiceReverseProxy()->BackupOnBundleStarted(ret, bundleName); + BundleBeginRadarReport(bundleName, ret, scenario); } else if (scenario == IServiceReverse::Scenario::RESTORE) { session_->GetServiceReverseProxy()->RestoreOnBundleStarted(ret, bundleName); + BundleBeginRadarReport(bundleName, ret, scenario); DisposeErr disposeErr = AppGalleryDisposeProxy::GetInstance()->EndRestore(bundleName); HILOGI("ExtConnectFailed EndRestore, code=%{public}d, bundleName=%{public}s", disposeErr, bundleName.c_str()); @@ -1074,14 +1210,6 @@ void Service::ExtConnectFailed(const string &bundleName, ErrCode ret) try { HILOGE("begin %{public}s", bundleName.data()); scenario = session_->GetScenario(); - AppRadar::Info info (bundleName, "", ""); - if (scenario == IServiceReverse::Scenario::BACKUP) { - AppRadar::GetInstance().RecordBackupFuncRes(info, "Service::ExtConnectFailed", GetUserIdDefault(), - BizStageBackup::BIZ_STAGE_CONNECT_EXTENSION_FAIL, ret); - } else if (scenario == IServiceReverse::Scenario::RESTORE) { - AppRadar::GetInstance().RecordRestoreFuncRes(info, "Service::ExtConnectFailed", GetUserIdDefault(), - BizStageRestore::BIZ_STAGE_CONNECT_EXTENSION_FAIL, ret); - } ReportOnExtConnectFailed(scenario, bundleName, ret); ClearSessionAndSchedInfo(bundleName); NoticeClientFinish(bundleName, BError(BError::Codes::EXT_ABILITY_DIED)); @@ -1114,6 +1242,7 @@ void Service::NoticeClientFinish(const string &bundleName, ErrCode errCode) } else if (scenario == IServiceReverse::Scenario::RESTORE) { session_->GetServiceReverseProxy()->RestoreOnBundleFinished(errCode, bundleName); }; + BundleEndRadarReport(bundleName, errCode, scenario); /* If all bundle ext process finish, notice client. */ OnAllBundlesFinished(BError(BError::Codes::OK)); } catch(const BError &e) { @@ -1458,10 +1587,10 @@ std::function Service::GetBackupInfoConnectDie }; } -void Service::ClearResidualBundleData(const std::string &bundleName) +ErrCode Service::ClearResidualBundleData(const std::string &bundleName) { if (session_ == nullptr) { - return; + return BError(BError::Codes::SA_INVAL_ARG); } auto backUpConnection = session_->GetExtConnection(bundleName); if (backUpConnection == nullptr) { @@ -1472,7 +1601,7 @@ void Service::ClearResidualBundleData(const std::string &bundleName) throw BError(BError::Codes::SA_INVAL_ARG, "Extension backup Proxy is empty"); } // 通知ext清理 - proxy->HandleClear(); + ErrCode res = proxy->HandleClear(); if (backUpConnection->IsExtAbilityConnected()) { backUpConnection->DisconnectBackupExtAbility(); } @@ -1481,6 +1610,7 @@ void Service::ClearResidualBundleData(const std::string &bundleName) if (session_->GetScenario() != IServiceReverse::Scenario::CLEAN) { OnAllBundlesFinished(BError(BError::Codes::OK)); } + return res; } ErrCode Service::GetBackupInfoCmdHandle(BundleName &bundleName, std::string &result) @@ -1723,6 +1853,7 @@ ErrCode Service::BackupSA(std::string bundleName) if (scenario == IServiceReverse::Scenario::BACKUP) { auto ret = saConnection->CallBackupSA(); session_->GetServiceReverseProxy()->BackupOnBundleStarted(ret, bundleName); + BundleBeginRadarReport(bundleName, ret, scenario); if (ret) { HILOGI("BackupSA ret is %{public}d", ret); ClearSessionAndSchedInfo(bundleName); @@ -1742,6 +1873,7 @@ void Service::OnSABackup(const std::string &bundleName, const int &fd, const std HILOGI("OnSABackup bundleName: %{public}s, fd: %{public}d, result: %{public}s, err: %{public}d", bundleName.c_str(), fd, result.c_str(), errCode); session_->GetServiceReverseProxy()->BackupOnFileReady(bundleName, "", move(fd), errCode); + FileReadyRadarReport(bundleName, "", errCode, IServiceReverse::Scenario::BACKUP); SAResultReport(bundleName, result, errCode, BackupRestoreScenario::FULL_BACKUP); }; threadPool_.AddTask([task]() { @@ -1826,6 +1958,7 @@ void Service::NotifyCallerCurAppDone(ErrCode errCode, const std::string &callerN HILOGI("will notify clone data, scenario is Restore"); session_->GetServiceReverseProxy()->RestoreOnBundleFinished(errCode, callerName); } + BundleEndRadarReport(callerName, errCode, scenario); } ErrCode Service::ReportAppProcessInfo(const std::string processInfo, BackupRestoreScenario sennario) diff --git a/services/backup_sa/src/module_ipc/service_incremental.cpp b/services/backup_sa/src/module_ipc/service_incremental.cpp index 0d643218c..20f832155 100644 --- a/services/backup_sa/src/module_ipc/service_incremental.cpp +++ b/services/backup_sa/src/module_ipc/service_incremental.cpp @@ -275,11 +275,16 @@ ErrCode Service::InitIncrementalBackupSession(sptr remote) HILOGE("Init Incremental backup session error, session is empty"); return BError(BError::Codes::SA_INVAL_ARG); } - return session_->Active({.clientToken = IPCSkeleton::GetCallingTokenID(), - .scenario = IServiceReverse::Scenario::BACKUP, - .clientProxy = remote, - .userId = GetUserIdDefault(), - .isIncrementalBackup = true}); + ErrCode errCode = session_->Active({.clientToken = IPCSkeleton::GetCallingTokenID(), + .scenario = IServiceReverse::Scenario::BACKUP, + .clientProxy = remote, + .userId = GetUserIdDefault(), + .isIncrementalBackup = true}); + if (errCode == 0) { + ClearFailedBundles(); + successBundlesNum_ = 0; + } + return errCode; } catch (const BError &e) { StopAll(nullptr, true); return e.GetCode(); @@ -318,6 +323,8 @@ ErrCode Service::AppendBundlesIncrementalBackupSession(const std::vectorGetServiceReverseProxy()->IncrementalBackupOnBundleStarted( BError(BError::Codes::SA_FORBID_BACKUP_RESTORE), bundleNameIndexInfo); + BundleBeginRadarReport(bundleNameIndexInfo, BError(BError::Codes::SA_FORBID_BACKUP_RESTORE).GetCode(), + IServiceReverse::Scenario::BACKUP); session_->RemoveExtInfo(bundleNameIndexInfo); } } @@ -390,6 +397,8 @@ void Service::HandleCurGroupIncBackupInfos(vector & if (info.allToBackup == false) { session_->GetServiceReverseProxy()->IncrementalBackupOnBundleStarted( BError(BError::Codes::SA_FORBID_BACKUP_RESTORE), bundleNameIndexInfo); + BundleBeginRadarReport(bundleNameIndexInfo, BError(BError::Codes::SA_FORBID_BACKUP_RESTORE).GetCode(), + IServiceReverse::Scenario::BACKUP); session_->RemoveExtInfo(bundleNameIndexInfo); } BJsonUtil::BundleDetailInfo uniCastInfo; @@ -465,6 +474,7 @@ ErrCode Service::AppIncrementalFileReady(const std::string &fileName, UniqueFd f if (session_->GetScenario() == IServiceReverse::Scenario::RESTORE) { session_->GetServiceReverseProxy()->IncrementalRestoreOnFileReady(callerName, fileName, move(fd), move(manifestFd), errCode); + FileReadyRadarReport(callerName, fileName, errCode, IServiceReverse::Scenario::RESTORE); return BError(BError::Codes::OK); } if (fileName == BConstants::EXT_BACKUP_MANAGE) { @@ -473,6 +483,7 @@ ErrCode Service::AppIncrementalFileReady(const std::string &fileName, UniqueFd f HILOGD("reverse: Will notify IncrementalBackupOnFileReady"); session_->GetServiceReverseProxy()->IncrementalBackupOnFileReady(callerName, fileName, move(fd), move(manifestFd), errCode); + FileReadyRadarReport(callerName, fileName, errCode, IServiceReverse::Scenario::BACKUP); AuditLog auditLog = { false, "Backup File Ready", "ADD", "", 1, "SUCCESS", "AppIncrementalFileReady", callerName, GetAnonyPath(fileName) }; HiAudit::GetInstance(true).Write(auditLog); @@ -491,6 +502,7 @@ ErrCode Service::AppIncrementalFileReady(const std::string &fileName, UniqueFd f HILOGI("reverse: Will notify IncrementalBackupOnBundleFinished"); session_->GetServiceReverseProxy()->IncrementalBackupOnBundleFinished(BError(BError::Codes::OK), callerName); + BundleEndRadarReport(callerName, BError(BError::Codes::OK), IServiceReverse::Scenario::BACKUP); // 断开extension backUpConnection->DisconnectBackupExtAbility(); ClearSessionAndSchedInfo(callerName); @@ -573,8 +585,8 @@ ErrCode Service::GetIncrementalFileHandle(const std::string &bundleName, const s HILOGE("GetIncrementalFileHandle error, Extension backup Proxy is empty"); return BError(BError::Codes::SA_INVAL_ARG); } - int res = proxy->GetIncrementalFileHandle(fileName); - if (res) { + ErrCode res = proxy->GetIncrementalFileHandle(fileName); + if (res != ERR_OK) { HILOGE("Failed to extension file handle"); AppRadar::Info info (bundleName, "", ""); AppRadar::GetInstance().RecordRestoreFuncRes(info, "Service::GetIncrementalFileHandle", @@ -611,6 +623,7 @@ bool Service::IncrementalBackup(const string &bundleName) if (scenario == IServiceReverse::Scenario::BACKUP && session_->GetIsIncrementalBackup()) { auto ret = proxy->IncrementalOnBackup(session_->GetClearDataFlag(bundleName)); session_->GetServiceReverseProxy()->IncrementalBackupOnBundleStarted(ret, bundleName); + BundleBeginRadarReport(bundleName, ret, IServiceReverse::Scenario::BACKUP); if (ret) { ClearSessionAndSchedInfo(bundleName); NoticeClientFinish(bundleName, BError(BError::Codes::EXT_ABILITY_DIED)); @@ -620,6 +633,7 @@ bool Service::IncrementalBackup(const string &bundleName) session_->ValidRestoreDataType(RestoreTypeEnum::RESTORE_DATA_WAIT_SEND)) { auto ret = proxy->HandleRestore(session_->GetClearDataFlag(bundleName)); session_->GetServiceReverseProxy()->IncrementalRestoreOnBundleStarted(ret, bundleName); + BundleBeginRadarReport(bundleName, ret, IServiceReverse::Scenario::RESTORE); auto fileNameVec = session_->GetExtFileNameRequest(bundleName); for (auto &fileName : fileNameVec) { ret = proxy->GetIncrementalFileHandle(fileName); @@ -638,6 +652,7 @@ void Service::NotifyCallerCurAppIncrementDone(ErrCode errCode, const std::string if (scenario == IServiceReverse::Scenario::BACKUP) { HILOGI("will notify clone data, scenario is incremental backup"); session_->GetServiceReverseProxy()->IncrementalBackupOnBundleFinished(errCode, callerName); + BundleEndRadarReport(callerName, errCode, scenario); auto now = std::chrono::system_clock::now(); auto time = std::chrono::system_clock::to_time_t(now); auto ms = std::chrono::duration_cast(now.time_since_epoch()); @@ -655,6 +670,7 @@ void Service::NotifyCallerCurAppIncrementDone(ErrCode errCode, const std::string HILOGI("will notify clone data, scenario is Restore"); SendEndAppGalleryNotify(callerName); session_->GetServiceReverseProxy()->IncrementalRestoreOnBundleFinished(errCode, callerName); + BundleEndRadarReport(callerName, errCode, scenario); } } diff --git a/services/backup_sa/src/module_ipc/sub_service.cpp b/services/backup_sa/src/module_ipc/sub_service.cpp index 2e8535889..a21953179 100644 --- a/services/backup_sa/src/module_ipc/sub_service.cpp +++ b/services/backup_sa/src/module_ipc/sub_service.cpp @@ -136,6 +136,7 @@ ErrCode Service::AppFileReady(const string &fileName, UniqueFd fd, int32_t errCo fd = session_->OnBundleExtManageInfo(callerName, move(fd)); } session_->GetServiceReverseProxy()->BackupOnFileReady(callerName, fileName, move(fd), errCode); + FileReadyRadarReport(callerName, fileName, errCode, session_->GetScenario()); AuditLog auditLog = { false, "Backup File Ready", "ADD", "", 1, "SUCCESS", "AppFileReady", callerName, GetAnonyPath(fileName) }; HiAudit::GetInstance(true).Write(auditLog); @@ -157,6 +158,7 @@ ErrCode Service::AppFileReady(const string &fileName, UniqueFd fd, int32_t errCo session_->StopExtTimer(callerName); // 通知TOOL 备份完成 session_->GetServiceReverseProxy()->BackupOnBundleFinished(BError(BError::Codes::OK), callerName); + BundleEndRadarReport(callerName, BError(BError::Codes::OK), session_->GetScenario()); // 断开extension backUpConnection->DisconnectBackupExtAbility(); ClearSessionAndSchedInfo(callerName); @@ -255,6 +257,7 @@ ErrCode Service::LaunchBackupExtension(const BundleName &bundleName) ErrCode ret = backUpConnection->ConnectBackupExtAbility(want, session_->GetSessionUserId()); if (ret) { HILOGE("ConnectBackupExtAbility faild, bundleName:%{public}s, ret:%{public}d", bundleName.c_str(), ret); + ExtensionConnectFailRadarReport(bundleName, ret, session_->GetScenario()); return BError(BError::Codes::SA_BOOT_EXT_FAIL); } return BError(BError::Codes::OK); diff --git a/services/backup_sa/src/module_ipc/svc_session_manager.cpp b/services/backup_sa/src/module_ipc/svc_session_manager.cpp index a809082f0..f84668de1 100644 --- a/services/backup_sa/src/module_ipc/svc_session_manager.cpp +++ b/services/backup_sa/src/module_ipc/svc_session_manager.cpp @@ -109,6 +109,14 @@ void SvcSessionManager::Deactive(const wptr &remoteInAction, bool } deathRecipient_ = nullptr; + AppRadar::Info info("", "", "deactive session success"); + if (impl_.scenario == IServiceReverse::Scenario::RESTORE) { + AppRadar::GetInstance().RecordRestoreFuncRes(info, "SvcSessionManager::Deactive", impl_.userId, + BizStageRestore::BIZ_STAGE_DEACTIVE_SESSION, ERR_OK); + } else if (impl_.scenario == IServiceReverse::Scenario::BACKUP) { + AppRadar::GetInstance().RecordBackupFuncRes(info, "SvcSessionManager::Deactive", impl_.userId, + BizStageBackup::BIZ_STAGE_DEACTIVE_SESSION, ERR_OK); + } HILOGI("Succeed to deactive a session"); impl_ = {}; extConnectNum_ = 0; @@ -368,15 +376,18 @@ void SvcSessionManager::InitClient(Impl &newImpl) HILOGW("It's curious that the backup sa dies before the backup client"); return; } - AppRadar::Info info ("", "", "client died"); - AppRadar::GetInstance().RecordDefaultFuncRes(info, "SvcSessionManager::InitClient", - AppRadar::GetInstance().GetUserId(), - BizStageBackup::BIZ_STAGE_CLIENT_ABNORMAL_EXIT, - BError(BError::Codes::SA_BROKEN_IPC).GetCode()); (void)revPtrStrong->SessionDeactive(); }; deathRecipient_ = sptr(new SvcDeathRecipient(callback)); remoteObj->AddDeathRecipient(deathRecipient_); + AppRadar::Info info("", "", "active session success"); + if (newImpl.scenario == IServiceReverse::Scenario::RESTORE) { + AppRadar::GetInstance().RecordRestoreFuncRes(info, "SvcSessionManager::InitClient", newImpl.userId, + BizStageRestore::BIZ_STAGE_ACTIVE_SESSION, ERR_OK); + } else if (newImpl.scenario == IServiceReverse::Scenario::BACKUP) { + AppRadar::GetInstance().RecordBackupFuncRes(info, "SvcSessionManager::InitClient", newImpl.userId, + BizStageBackup::BIZ_STAGE_ACTIVE_SESSION, ERR_OK); + } HILOGI("Succeed to active a session"); } diff --git a/services/backup_sa/src/module_sched/sched_scheduler.cpp b/services/backup_sa/src/module_sched/sched_scheduler.cpp index 8d85731b3..ca7e528f8 100644 --- a/services/backup_sa/src/module_sched/sched_scheduler.cpp +++ b/services/backup_sa/src/module_sched/sched_scheduler.cpp @@ -29,6 +29,7 @@ #include "b_error/b_error.h" #include "b_ohos/startup/backup_para.h" +#include "b_radar/b_radar.h" #include "filemgmt_libhilog.h" #include "iservice_registry.h" #include "module_external/bms_adapter.h" @@ -39,6 +40,21 @@ namespace OHOS::FileManagement::Backup { using namespace std; +void ExtDiedClearFailRadarReport(const string& bundleName, IServiceReverse::Scenario scenario, ErrCode res) +{ + if (res == ERR_OK) { + return; + } + AppRadar::Info info(bundleName, "", ""); + if (scenario == IServiceReverse::Scenario::RESTORE) { + AppRadar::GetInstance().RecordRestoreFuncRes(info, "SchedScheduler::ExecutingQueueTasks", + AppRadar::GetInstance().GetUserId(), BizStageRestore::BIZ_STAGE_EXTENSION_ABNORMAL_EXIT_CLEAR_FAIL, res); + } else if (scenario == IServiceReverse::Scenario::BACKUP) { + AppRadar::GetInstance().RecordBackupFuncRes(info, "SchedScheduler::ExecutingQueueTasks", + AppRadar::GetInstance().GetUserId(), BizStageBackup::BIZ_STAGE_EXTENSION_ABNORMAL_EXIT_CLEAR_FAIL, res); + } +} + void SchedScheduler::Sched(string bundleName) { if (bundleName == "") { @@ -118,7 +134,9 @@ void SchedScheduler::ExecutingQueueTasks(const string &bundleName) } } else if (action == BConstants::ServiceSchedAction::CLEAN) { HILOGI("Current bundle %{public}s process is cleaning", bundleName.data()); - reversePtr_->ClearResidualBundleData(bundleName); + ErrCode res = reversePtr_->ClearResidualBundleData(bundleName); + IServiceReverse::Scenario scenario = sessionPtr_->GetScenario(); + ExtDiedClearFailRadarReport(bundleName, scenario, res); } } diff --git a/tests/mock/module_ipc/service_mock.cpp b/tests/mock/module_ipc/service_mock.cpp index d2cc3ba15..9c1fc72f2 100644 --- a/tests/mock/module_ipc/service_mock.cpp +++ b/tests/mock/module_ipc/service_mock.cpp @@ -250,8 +250,9 @@ void Service::OnSABackup(const std::string &bundleName, void Service::OnSARestore(const std::string &bundleName, const std::string &result, const ErrCode &errCode) {} -void Service::ClearResidualBundleData(const std::string &bundleName) +ErrCode Service::ClearResidualBundleData(const std::string &bundleName) { + return BError(BError::Codes::OK); } std::shared_ptr Service::GetExtensionMutex(const BundleName &bundleName) @@ -263,6 +264,27 @@ void Service::RemoveExtensionMutex(const BundleName &bundleName) { } +void Service::OnBundleStarted(BError error, sptr session, const BundleName &bundleName) {} + +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) {} + +void Service::BundleEndRadarReport(const std::string &bundleName, const ErrCode errCode, + const IServiceReverse::Scenario scenario) {} + +void Service::FileReadyRadarReport(const std::string &bundleName, const std::string &fileName, const ErrCode errCode, + const IServiceReverse::Scenario scenario) {} + +void Service::ExtensionConnectFailRadarReport(const std::string &bundleName, const ErrCode errCode, + const IServiceReverse::Scenario scenario) {} + +void Service::UpdateFailedBundles(const std::string &bundleName, BundleTaskInfo taskInfo) {} + +void Service::ClearFailedBundles() {} + void Service::CreateDirIfNotExist(const std::string &path) { } 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 dff5599bc..4cad2e71b 100644 --- a/tests/unittests/backup_sa/module_ipc/service_incremental_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_incremental_test.cpp @@ -221,6 +221,27 @@ bool SvcRestoreDepsManager::UpdateToRestoreBundleMap(const string&, const string { return true; } + +void Service::OnBundleStarted(BError error, sptr session, const BundleName &bundleName) {} + +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) {} + +void Service::BundleEndRadarReport(const std::string &bundleName, const ErrCode errCode, + const IServiceReverse::Scenario scenario) {} + +void Service::FileReadyRadarReport(const std::string &bundleName, const std::string &fileName, const ErrCode errCode, + const IServiceReverse::Scenario scenario) {} + +void Service::ExtensionConnectFailRadarReport(const std::string &bundleName, const ErrCode errCode, + const IServiceReverse::Scenario scenario) {} + +void Service::UpdateFailedBundles(const std::string &bundleName, BundleTaskInfo taskInfo) {} + +void Service::ClearFailedBundles() {} } // namespace OHOS::FileManagement::Backup namespace OHOS::FileManagement::Backup { diff --git a/tests/unittests/backup_sa/module_ipc/service_other_test.cpp b/tests/unittests/backup_sa/module_ipc/service_other_test.cpp index 2d964a2f5..117b1be3a 100644 --- a/tests/unittests/backup_sa/module_ipc/service_other_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_other_test.cpp @@ -621,14 +621,14 @@ HWTEST_F(ServiceTest, SUB_Service_OnBundleStarted_0100, TestSize.Level1) sptr session_ = service->session_; BundleName bundleName; EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); - OnBundleStarted(error, session_, bundleName); + service->OnBundleStarted(error, session_, bundleName); EXPECT_TRUE(true); EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); EXPECT_CALL(*param, GetBackupOverrideIncrementalRestore()).WillOnce(Return(false)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); EXPECT_CALL(*srProxy, RestoreOnBundleStarted(_, _)).WillOnce(Return()); - OnBundleStarted(error, session_, bundleName); + service->OnBundleStarted(error, session_, bundleName); EXPECT_TRUE(true); EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); @@ -636,7 +636,7 @@ HWTEST_F(ServiceTest, SUB_Service_OnBundleStarted_0100, TestSize.Level1) EXPECT_CALL(*session, ValidRestoreDataType(_)).WillOnce(Return(false)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); EXPECT_CALL(*srProxy, RestoreOnBundleStarted(_, _)).WillOnce(Return()); - OnBundleStarted(error, session_, bundleName); + service->OnBundleStarted(error, session_, bundleName); EXPECT_TRUE(true); EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); @@ -644,7 +644,7 @@ HWTEST_F(ServiceTest, SUB_Service_OnBundleStarted_0100, TestSize.Level1) EXPECT_CALL(*session, ValidRestoreDataType(_)).WillOnce(Return(true)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); EXPECT_CALL(*srProxy, IncrementalRestoreOnBundleStarted(_, _)).WillOnce(Return()); - OnBundleStarted(error, session_, bundleName); + service->OnBundleStarted(error, session_, bundleName); EXPECT_TRUE(true); } catch (...) { EXPECT_TRUE(false); @@ -694,12 +694,12 @@ HWTEST_F(ServiceTest, SUB_Service_HandleExceptionOnAppendBundles_0100, TestSize. vector appendBundleNames { "bundleName" }; vector restoreBundleNames; EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); - HandleExceptionOnAppendBundles(service->session_, appendBundleNames, restoreBundleNames); + service->HandleExceptionOnAppendBundles(service->session_, appendBundleNames, restoreBundleNames); EXPECT_TRUE(true); restoreBundleNames.emplace_back("bundleName"); restoreBundleNames.emplace_back("bundleName2"); - HandleExceptionOnAppendBundles(service->session_, appendBundleNames, restoreBundleNames); + service->HandleExceptionOnAppendBundles(service->session_, appendBundleNames, restoreBundleNames); EXPECT_TRUE(true); } catch (...) { EXPECT_TRUE(false); diff --git a/tests/unittests/backup_sa/module_ipc/service_test.cpp b/tests/unittests/backup_sa/module_ipc/service_test.cpp index 7f7ef75ec..6a83d2469 100644 --- a/tests/unittests/backup_sa/module_ipc/service_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_test.cpp @@ -1271,11 +1271,11 @@ HWTEST_F(ServiceTest, SUB_Service_OnBundleStarted_0100, testing::ext::TestSize.L wptr reversePtr(new Service(saID)); sptr session(new SvcSessionManager(reversePtr)); EXPECT_TRUE(servicePtr_ != nullptr); - OnBundleStarted(BError(BError::Codes::SA_INVAL_ARG), session, BUNDLE_NAME); + servicePtr_->OnBundleStarted(BError(BError::Codes::SA_INVAL_ARG), session, BUNDLE_NAME); SvcSessionManager::Impl impl_; impl_.clientToken = 1; impl_.scenario = IServiceReverse::Scenario::RESTORE; - OnBundleStarted(BError(BError::Codes::SA_INVAL_ARG), session, BUNDLE_NAME); + servicePtr_->OnBundleStarted(BError(BError::Codes::SA_INVAL_ARG), session, BUNDLE_NAME); } catch (...) { EXPECT_TRUE(false); GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by OnBundleStarted."; @@ -1302,14 +1302,14 @@ HWTEST_F(ServiceTest, SUB_Service_HandleExceptionOnAppendBundles_0100, testing:: vector appendBundleNames {"123456"}; vector restoreBundleNames {"abcdef"}; EXPECT_TRUE(servicePtr_ != nullptr); - HandleExceptionOnAppendBundles(session, appendBundleNames, restoreBundleNames); + servicePtr_->HandleExceptionOnAppendBundles(session, appendBundleNames, restoreBundleNames); appendBundleNames.push_back("789"); - HandleExceptionOnAppendBundles(session, appendBundleNames, restoreBundleNames); + servicePtr_->HandleExceptionOnAppendBundles(session, appendBundleNames, restoreBundleNames); restoreBundleNames.push_back("123456"); restoreBundleNames.push_back("123"); - HandleExceptionOnAppendBundles(session, appendBundleNames, restoreBundleNames); + servicePtr_->HandleExceptionOnAppendBundles(session, appendBundleNames, restoreBundleNames); } catch (...) { EXPECT_TRUE(false); GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by HandleExceptionOnAppendBundles."; diff --git a/utils/include/b_error/b_error.h b/utils/include/b_error/b_error.h index 4cded015b..3863761c7 100644 --- a/utils/include/b_error/b_error.h +++ b/utils/include/b_error/b_error.h @@ -116,6 +116,7 @@ public: E_EXCEPTION = 13500007, E_UNPACKET = 13500008, E_BEF = 13500009, + E_TASKFAIL = 13500010, }; public: diff --git a/utils/include/b_radar/b_radar.h b/utils/include/b_radar/b_radar.h index 226e0ece4..148181dd7 100644 --- a/utils/include/b_radar/b_radar.h +++ b/utils/include/b_radar/b_radar.h @@ -17,6 +17,7 @@ #define OHOS_FILEMGMT_BACKUP_B_RADAR_H #include #include +#include "i_service_reverse.h" namespace OHOS::FileManagement::Backup { enum class BizStageBackup : int32_t { @@ -26,15 +27,20 @@ enum class BizStageBackup : int32_t { BIZ_STAGE_CREATE_BACKUP_SESSION_FAIL, BIZ_STAGE_APPEND_BUNDLES_FAIL, BIZ_STAGE_CONNECT_EXTENSION_FAIL, - BIZ_STAGE_START_DISPOSE_FAIL, - BIZ_STAGE_EXTENSION_ABNORMAL_EXIT, + BIZ_STAGE_START_DISPOSE, + BIZ_STAGE_EXTENSION_ABNORMAL_EXIT_CLEAR_FAIL, BIZ_STAGE_GET_BACKUP_INFO_FAIL, BIZ_STAGE_ON_BACKUP, BIZ_STAGE_DO_BACKUP, BIZ_STAGE_CHECK_DATA_FAIL, - BIZ_STAGE_END_DISPOSE_FAIL, - BIZ_STAGE_CLIENT_ABNORMAL_EXIT, - BIZ_STAGE_PERMISSION_CHECK_FAIL + BIZ_STAGE_END_DISPOSE, + BIZ_STAGE_PERMISSION_CHECK_FAIL, + BIZ_STAGE_EXECU_FAIL, + BIZ_STAGE_ACTIVE_SESSION, + BIZ_STAGE_DEACTIVE_SESSION, + BIZ_STAGE_RELEASE, + BIZ_STAGE_ONSTART_DISPOSE, + BIZ_STAGE_ONSTART_RESIDUAL }; enum class BizStageRestore : int32_t { @@ -44,15 +50,20 @@ enum class BizStageRestore : int32_t { BIZ_STAGE_CREATE_RESTORE_SESSION_FAIL, BIZ_STAGE_APPEND_BUNDLES_FAIL, BIZ_STAGE_CONNECT_EXTENSION_FAIL, - BIZ_STAGE_START_DISPOSE_FAIL, - BIZ_STAGE_EXTENSION_ABNORMAL_EXIT, + BIZ_STAGE_START_DISPOSE, + BIZ_STAGE_EXTENSION_ABNORMAL_EXIT_CLEAR_FAIL, BIZ_STAGE_GET_FILE_HANDLE_FAIL, BIZ_STAGE_DO_RESTORE, BIZ_STAGE_CHECK_DATA_FAIL, BIZ_STAGE_ON_RESTORE, - BIZ_STAGE_END_DISPOSE_FAIL, - BIZ_STAGE_CLIENT_ABNORMAL_EXIT, - BIZ_STAGE_PERMISSION_CHECK_FAIL + BIZ_STAGE_END_DISPOSE, + BIZ_STAGE_PERMISSION_CHECK_FAIL, + BIZ_STAGE_EXECU_FAIL, + BIZ_STAGE_ACTIVE_SESSION, + BIZ_STAGE_DEACTIVE_SESSION, + BIZ_STAGE_RELEASE, + BIZ_STAGE_ONSTART_DISPOSE, + BIZ_STAGE_ONSTART_RESIDUAL }; class AppRadar { @@ -83,6 +94,14 @@ public: int64_t totalFileSpendTime; }; + struct StatInfo { + std::string callerName; + std::string resInfo; + + StatInfo(const std::string &callerName, const std::string &resInfo) + : callerName(callerName), resInfo(resInfo) {} + }; + public: int32_t GetUserId(); void RecordDefaultFuncRes(Info &info, const std::string &func, int32_t userId, diff --git a/utils/include/b_resources/b_constants.h b/utils/include/b_resources/b_constants.h index 447cde28b..548b7000c 100644 --- a/utils/include/b_resources/b_constants.h +++ b/utils/include/b_resources/b_constants.h @@ -229,8 +229,11 @@ const std::string UNICAST_TYPE = "unicast"; // 雷达打点引用到的常量 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; 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 #endif // OHOS_FILEMGMT_BACKUP_B_CONSTANTS_H diff --git a/utils/src/b_radar/b_radar.cpp b/utils/src/b_radar/b_radar.cpp index 31ef80f3d..1316310e0 100644 --- a/utils/src/b_radar/b_radar.cpp +++ b/utils/src/b_radar/b_radar.cpp @@ -39,7 +39,7 @@ void AppRadar::RecordDefaultFuncRes(Info &info, const std::string &func, int32_t enum BizStageBackup bizStage, int32_t resultCode) { std::stringstream ss; - ss << "{\"result_info\": {" << info.resInfo << "}}"; + ss << R"("result_info": {)" << info.resInfo << "}}"; HiSysEventWrite( OHOS::HiviewDFX::HiSysEvent::Domain::FILEMANAGEMENT, BConstants::FILE_BACKUP_RESTORE_EVENTS, @@ -60,7 +60,7 @@ void AppRadar::RecordBackupFuncRes(Info &info, const std::string &func, int32_t enum BizStageBackup bizStage, int32_t resultCode) { std::stringstream ss; - ss << "{\"result_info\": {" << info.resInfo << "}}"; + ss << R"("result_info": {)" << info.resInfo << "}}"; HiSysEventWrite( OHOS::HiviewDFX::HiSysEvent::Domain::FILEMANAGEMENT, BConstants::FILE_BACKUP_RESTORE_EVENTS, @@ -81,7 +81,7 @@ void AppRadar::RecordRestoreFuncRes(Info &info, const std::string &func, int32_t enum BizStageRestore bizStage, int32_t resultCode) { std::stringstream ss; - ss << "{\"result_info\": {" << info.resInfo << "}}"; + ss << R"("result_info": {)" << info.resInfo << "}}"; HiSysEventWrite( OHOS::HiviewDFX::HiSysEvent::Domain::FILEMANAGEMENT, BConstants::FILE_BACKUP_RESTORE_EVENTS, -- Gitee