diff --git a/frameworks/native/backup_ext/src/ext_extension.cpp b/frameworks/native/backup_ext/src/ext_extension.cpp index ccbe6518fa6f02cfd4f1b190d7ed55875c873fe8..faca627f9108947ae5a7ad1dd61e5ecedeed6378 100644 --- a/frameworks/native/backup_ext/src/ext_extension.cpp +++ b/frameworks/native/backup_ext/src/ext_extension.cpp @@ -75,21 +75,41 @@ 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(), BizStageRestore::BIZ_STAGE_DO_RESTORE, err); } +static void RecordDoBackupRes(const std::string &bundleName, const ErrCode errCode, AppRadar::DoBackupInfo &backupInfo) +{ + uint32_t inExcludeNum = backupInfo.includeNum + backupInfo.excludeNum; + if (inExcludeNum >= BConstants::MAX_INEXCLUDE_SIZE) { + AppRadar::Info infoInExclude(bundleName, "", string("\"total inExclude\":").append(to_string(inExcludeNum))); + AppRadar::GetInstance().RecordBackupFuncRes(infoInExclude, "BackupExtExtension::DoBackup", + AppRadar::GetInstance().GetUserId(), BizStageBackup::BIZ_STAGE_DO_BACKUP, ERR_OK); + } + if (errCode == ERR_OK && backupInfo.cost >= BConstants::MAX_TIME_COST) { + std::stringstream ss; + ss << R"("spendTime": )" << backupInfo.cost << "ms, "; + ss << R"("totalFilesNum": )" << backupInfo.allFileNum << ", "; + ss << R"("smallFilesNum": )" << backupInfo.smallFileNum << ", "; + ss << R"("bigFilesNum": )" << backupInfo.allFileNum - backupInfo.tarFileNum; + AppRadar::Info info(bundleName, "", ss.str()); + AppRadar::GetInstance().RecordBackupFuncRes(info, "BackupExtExtension::DoBackup", + AppRadar::GetInstance().GetUserId(), BizStageBackup::BIZ_STAGE_DO_BACKUP, errCode); + } +} + static string GetIndexFileRestorePath(const string &bundleName) { if (BFile::EndsWith(bundleName, BConstants::BUNDLE_FILE_MANAGER) && bundleName.size() == BConstants::FM_LEN) { @@ -730,6 +750,7 @@ int BackupExtExtension::DoBackup(const BJsonEntityExtensionConfig &usrConfig) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); HILOGI("Start Do backup"); + auto start = std::chrono::system_clock::now(); if (extension_ == nullptr) { HILOGE("Failed to do backup, extension is nullptr"); throw BError(BError::Codes::EXT_INVAL_ARG, "Extension is nullptr"); @@ -745,7 +766,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)); @@ -778,6 +798,11 @@ int BackupExtExtension::DoBackup(const BJsonEntityExtensionConfig &usrConfig) } HILOGI("HandleBackup finish, ret = %{public}d", res); + auto end = std::chrono::system_clock::now(); + auto cost = std::chrono::duration_cast(end - start).count(); + AppRadar::DoBackupInfo doBackupInfo = {cost, bigFileInfo.size(), smallFiles.size(), tarMap.size(), + includes.size(), excludes.size()}; + RecordDoBackupRes(bundleName_, res, doBackupInfo); return res; } @@ -939,13 +964,7 @@ void BackupExtExtension::AsyncTaskBackup(const string config) HILOGI("Do backup, start fwk timer end."); BJsonCachedEntity cachedEntity(config); auto cache = cachedEntity.Structuralize(); - auto start = std::chrono::system_clock::now(); auto ret = ptr->DoBackup(cache); - auto end = std::chrono::system_clock::now(); - auto cost = to_string(std::chrono::duration_cast(end - start).count()); - AppRadar::Info info(ptr->bundleName_, "", string("\"spend_time\":").append(cost).append(string("ms\""))); - AppRadar::GetInstance().RecordBackupFuncRes(info, "BackupExtExtension::AsyncTaskBackup", - AppRadar::GetInstance().GetUserId(), BizStageBackup::BIZ_STAGE_DO_BACKUP, static_cast(ret)); // REM: 处理返回结果 ret ptr->AppDone(ret); HILOGI("backup app done %{public}d", ret); diff --git a/frameworks/native/backup_ext/src/sub_ext_extension.cpp b/frameworks/native/backup_ext/src/sub_ext_extension.cpp index 6038f48b416ca56b8c9cc7786dee2f9b2e60b951..0fed7a3140e4fcce3f3a467bd1d1e5f50ddbf512 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 cfaaf5ef5b51eba86f25e3e869a1a578992bcdf8..0d69e9ba8def6d05197e461e7c378f78d7a40858 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 @@ -54,7 +54,7 @@ unique_ptr BIncrementalBackupSession::Init(Callbacks } int32_t res = proxy->InitIncrementalBackupSession(sptr(new ServiceReverse(callbacks))); - if (res != 0) { + if (res != ERR_OK) { HILOGE("Failed to Backup because of %{public}d", res); AppRadar::Info info("", "", ""); AppRadar::GetInstance().RecordBackupFuncRes(info, "BIncrementalBackupSession::Init", @@ -97,8 +97,8 @@ ErrCode BIncrementalBackupSession::AppendBundles(vector bundle return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } - int32_t res = proxy->AppendBundlesIncrementalBackupSession(bundlesToBackup); - if (res != 0) { + ErrCode res = proxy->AppendBundlesIncrementalBackupSession(bundlesToBackup); + if (res != ERR_OK) { std::string ss; for (const auto &bundle : bundlesToBackup) { ss += bundle.bundleName + ", "; @@ -119,7 +119,7 @@ ErrCode BIncrementalBackupSession::AppendBundles(vector bundle } int32_t res = proxy->AppendBundlesIncrementalBackupSession(bundlesToBackup, infos); - if (res != 0) { + if (res != ERR_OK) { std::string ss; for (const auto &bundle : bundlesToBackup) { ss += bundle.bundleName + ", "; 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 ed51e8cb9d9f36ff35ab1fa049558da2ae8f5bf2..0999dac1d385f0ed6add68593f2faf7d8274a6a7 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 @@ -53,12 +53,11 @@ unique_ptr BIncrementalRestoreSession::Init(Callback return nullptr; } int32_t res = proxy->InitRestoreSession(sptr(new ServiceReverse(callbacks))); - if (res != 0) { + if (res != ERR_OK) { 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,17 @@ ErrCode BIncrementalRestoreSession::AppendBundles(UniqueFd remoteCap, vectorAppendBundlesRestoreSession(move(remoteCap), bundlesToRestore); + ErrCode res = proxy->AppendBundlesRestoreSession(move(remoteCap), bundlesToRestore); + if (res != ERR_OK) { + std::string ss; + for (const auto &bundle : bundlesToRestore) { + ss += bundle + ", "; + } + AppRadar::Info info(ss.c_str(), "", ""); + 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 +123,17 @@ ErrCode BIncrementalRestoreSession::AppendBundles(UniqueFd remoteCap, vectorAppendBundlesRestoreSession(move(remoteCap), bundlesToRestore, detailInfos); + ErrCode res = proxy->AppendBundlesRestoreSession(move(remoteCap), bundlesToRestore, detailInfos); + if (res != ERR_OK) { + std::string ss; + for (const auto &bundle : bundlesToRestore) { + ss += bundle + ", "; + } + AppRadar::Info info(ss.c_str(), "", "AppendBundles with infos"); + 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 75c7e3cbcd54dada7b498c614fd72659b24428a6..cb79d416cd0e807b4111af0f65cd331bfadb3ce0 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 @@ -61,12 +61,11 @@ shared_ptr BIncrementalSessionRestoreAsync::Ini .onResultReport = callbacks.onResultReport, .onBackupServiceDied = callbacks.onBackupServiceDied}; int32_t res = proxy->InitRestoreSession(sptr(new ServiceReverse(callbacksTmp))); - if (res != 0) { + if (res != ERR_OK) { 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,18 @@ 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 != ERR_OK) { + std::string ss; + for (const auto &bundle : bundlesToRestore) { + ss += bundle + ", "; + } + AppRadar::Info info(ss.c_str(), "", "AppendBundles with infos"); + 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 +129,17 @@ 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 != ERR_OK) { + std::string ss; + for (const auto &bundle : bundlesToRestore) { + ss += bundle + ", "; + } + AppRadar::Info info(ss.c_str(), "", ""); + 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 f20285515766b6ea0c189b588ec5dd5d75b19864..ae41a356b2b4335521ee547e6a0d62cb191078e3 100644 --- a/frameworks/native/backup_kit_inner/src/b_session_backup.cpp +++ b/frameworks/native/backup_kit_inner/src/b_session_backup.cpp @@ -54,7 +54,7 @@ unique_ptr BSessionBackup::Init(Callbacks callbacks) } int32_t res = proxy->InitBackupSession(sptr(new ServiceReverse(callbacks))); - if (res != 0) { + if (res != ERR_OK) { HILOGE("Failed to Backup because of %{public}d", res); AppRadar::Info info("", "", ""); AppRadar::GetInstance().RecordBackupFuncRes(info, "BSessionBackup::Init", @@ -108,10 +108,10 @@ ErrCode BSessionBackup::AppendBundles(vector bundlesToBackup) } int32_t res = proxy->AppendBundlesBackupSession(bundlesToBackup); - if (res != 0) { + if (res != ERR_OK) { std::string ss; - for (const auto &bundleName:bundlesToBackup) { - ss += bundleName + ", "; + for (const auto &bundle : bundlesToBackup) { + ss += bundle + ", "; } AppRadar::Info info(ss.c_str(), "", ""); AppRadar::GetInstance().RecordBackupFuncRes(info, "BSessionBackup::AppendBundles", @@ -128,12 +128,12 @@ ErrCode BSessionBackup::AppendBundles(vector bundlesToBackup, vector } int32_t res = proxy->AppendBundlesDetailsBackupSession(bundlesToBackup, detailInfos); - if (res != 0) { + if (res != ERR_OK) { std::string ss; - for (const auto &bundleName:bundlesToBackup) { - ss += bundleName + ", "; + for (const auto &bundle : bundlesToBackup) { + ss += bundle + ", "; } - AppRadar::Info info(ss.c_str(), "", ""); + AppRadar::Info info(ss.c_str(), "", "AppendBundles with infos"); 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 0c37d260361e7e01f255690eb351f1004cc42362..9247c39ffe785d68ca37b484e4841a384dfce082 100644 --- a/frameworks/native/backup_kit_inner/src/b_session_restore.cpp +++ b/frameworks/native/backup_kit_inner/src/b_session_restore.cpp @@ -53,12 +53,11 @@ unique_ptr BSessionRestore::Init(Callbacks callbacks) return nullptr; } int32_t res = proxy->InitRestoreSession(new ServiceReverse(callbacks)); - if (res != 0) { + if (res != ERR_OK) { 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,17 @@ 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 != ERR_OK) { + std::string ss; + for (const auto &bundle : bundlesToRestore) { + ss += bundle + ", "; + } + AppRadar::Info info(ss.c_str(), "", "AppendBundles with infos"); + 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 +124,17 @@ 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 != ERR_OK) { + std::string ss; + for (const auto &bundle : bundlesToRestore) { + ss += bundle + ", "; + } + AppRadar::Info info(ss.c_str(), "", ""); + 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 b3cea05e1fd1a036aa43eb8d86d6e5ec39c08ba7..12b82a250b54e5f06c6c6889b241bb1a83daf8cf 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 @@ -62,12 +62,11 @@ shared_ptr BSessionRestoreAsync::Init(Callbacks callbacks) .onBackupServiceDied = callbacks.onBackupServiceDied, .onProcess = callbacks.onProcess}; int32_t res = proxy->InitRestoreSession(sptr(new ServiceReverse(callbacksTmp))); - if (res != 0) { + if (res != ERR_OK) { 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,18 @@ 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 != ERR_OK) { + std::string ss; + for (const auto &bundle : bundlesToRestore) { + ss += bundle + ", "; + } + AppRadar::Info info(ss.c_str(), "", "AppendBundles with infos"); + 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 +131,17 @@ 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 != ERR_OK) { + std::string ss; + for (const auto &bundle : bundlesToRestore) { + ss += bundle + ", "; + } + AppRadar::Info info(ss.c_str(), "", ""); + 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 ec842c43283f26fb25cf3bac5788038aeb5efb5e..ba1e761c5fd39867a97fe704e0efbfacb2b9d283 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 f3e1854ba5319212d1e014e0f8e3da3982fe9abd..e05fb51381c173b4f8be2c2fa6348fe17f04bfbf 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 828c311bc4106db63916f933fb08abec79a91afe..a093d680cfa80bc30a96622aab7520a885e5f56e 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 5818f706143c1feaf465a52627a752668e0e27e5..f739a3c404f4baf8bda2c5c3d8df0687e9889dc4 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 @@ -66,13 +66,21 @@ sptr AppGalleryDisposeProxy::GetInstance() DisposeErr AppGalleryDisposeProxy::StartBackup(const std::string &bundleName) { HILOGI("StartBackup, app %{public}s", bundleName.c_str()); - return DoDispose(bundleName, DisposeOperation::START_BACKUP); + DisposeErr res = DoDispose(bundleName, DisposeOperation::START_BACKUP); + AppRadar::Info info(bundleName, "", ""); + AppRadar::GetInstance().RecordBackupFuncRes(info, "StartBackup", AppRadar::GetInstance().GetUserId(), + BizStageBackup::BIZ_STAGE_START_DISPOSE, static_cast(res)); + return res; } DisposeErr AppGalleryDisposeProxy::EndBackup(const std::string &bundleName) { HILOGI("EndBackup, app %{public}s", bundleName.c_str()); - return DoDispose(bundleName, DisposeOperation::END_BACKUP); + DisposeErr res = DoDispose(bundleName, DisposeOperation::END_BACKUP); + AppRadar::Info info(bundleName, "", ""); + AppRadar::GetInstance().RecordBackupFuncRes(info, "EndBackup", AppRadar::GetInstance().GetUserId(), + BizStageBackup::BIZ_STAGE_END_DISPOSE, static_cast(res)); + return res; } DisposeErr AppGalleryDisposeProxy::StartRestore(const std::string &bundleName) @@ -82,7 +90,11 @@ DisposeErr AppGalleryDisposeProxy::StartRestore(const std::string &bundleName) return DisposeErr::OK; } HILOGI("StartRestore, app %{public}s", bundleName.c_str()); - return DoDispose(bundleName, DisposeOperation::START_RESTORE); + DisposeErr res = DoDispose(bundleName, DisposeOperation::START_RESTORE); + AppRadar::Info info(bundleName, "", ""); + AppRadar::GetInstance().RecordRestoreFuncRes(info, "StartRestore", AppRadar::GetInstance().GetUserId(), + BizStageRestore::BIZ_STAGE_START_DISPOSE, static_cast(res)); + return res; } DisposeErr AppGalleryDisposeProxy::EndRestore(const std::string &bundleName) @@ -92,33 +104,11 @@ DisposeErr AppGalleryDisposeProxy::EndRestore(const std::string &bundleName) return DisposeErr::OK; } HILOGI("EndRestore, app %{public}s", bundleName.c_str()); - return DoDispose(bundleName, DisposeOperation::END_RESTORE); -} - -void RecordDoDisposeRes(const std::string &bundleName, - AppGalleryDisposeProxy::DisposeOperation disposeOperation, int32_t err) -{ - AppRadar::Info info (bundleName, "", ""); - switch (disposeOperation) { - case AppGalleryDisposeProxy::DisposeOperation::START_BACKUP: - AppRadar::GetInstance().RecordBackupFuncRes(info, "StartBackup", AppRadar::GetInstance().GetUserId(), - BizStageBackup::BIZ_STAGE_START_DISPOSE_FAIL, err); - break; - case AppGalleryDisposeProxy::DisposeOperation::END_BACKUP: - AppRadar::GetInstance().RecordBackupFuncRes(info, "EndBackup", AppRadar::GetInstance().GetUserId(), - BizStageBackup::BIZ_STAGE_END_DISPOSE_FAIL, err); - break; - case AppGalleryDisposeProxy::DisposeOperation::START_RESTORE: - AppRadar::GetInstance().RecordRestoreFuncRes(info, "StartRestore", AppRadar::GetInstance().GetUserId(), - BizStageRestore::BIZ_STAGE_START_DISPOSE_FAIL, err); - break; - case AppGalleryDisposeProxy::DisposeOperation::END_RESTORE: - AppRadar::GetInstance().RecordRestoreFuncRes(info, "EndRestore", AppRadar::GetInstance().GetUserId(), - BizStageRestore::BIZ_STAGE_END_DISPOSE_FAIL, err); - break; - default: - break; - } + DisposeErr res = DoDispose(bundleName, DisposeOperation::END_RESTORE); + AppRadar::Info info(bundleName, "", ""); + AppRadar::GetInstance().RecordRestoreFuncRes(info, "EndRestore", AppRadar::GetInstance().GetUserId(), + BizStageRestore::BIZ_STAGE_END_DISPOSE, static_cast(res)); + return res; } DisposeErr AppGalleryDisposeProxy::DoDispose(const std::string &bundleName, DisposeOperation disposeOperation) @@ -152,7 +142,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 c2af171df66e43e603487f3c3f03e57543ccac6d..aeffd6886630398a291b202aa9b3dd311233ed5f 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,30 @@ UniqueFd Service::GetLocalCapabilities() void Service::StopAll(const wptr &obj, bool force) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + std::lock_guard lock(failedBundlesLock_); + int32_t fail_cnt = failedBundles_.size(); + int32_t totalBundles = fail_cnt + successBundlesNum_.load(); + if (totalBundles != 0) { + int32_t result = 0; + if (fail_cnt != 0) { + result = BError::BackupErrorCode::E_TASKFAIL; + } + std::stringstream ss; + ss << "successBundleNum:" << successBundlesNum_ << "," << "failedBundleNum:" << + fail_cnt << "," << "failedBundles:{"; + for (auto &failBundle : failedBundles_) { + ss << "\"" << failBundle.first << "\":" << "{errCode:" << failBundle.second.errCode << "," + << "reportTime:" << failBundle.second.reportTime << "},"; + } + ss << "}"; + string resultInfo = ss.str(); + AppRadar::StatInfo statInfo("", resultInfo); + IServiceReverse::Scenario scenario = session_->GetScenario(); + AppRadar::GetInstance().RecordStatisticRes(statInfo, GetUserIdDefault(), scenario, + successBundlesNum_.load(), fail_cnt, result); + } + failedBundles_.clear(); + successBundlesNum_ = 0; session_->Deactive(obj, force); } @@ -307,12 +447,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 +478,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 +526,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 +535,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 +589,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 +825,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 +900,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 +959,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 +1055,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 +1080,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 +1152,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 +1164,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 +1200,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 +1231,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 +1263,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 +1608,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 +1622,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 +1631,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 +1874,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 +1894,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 +1979,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 0d643218c829747456321387cca0a6beda86f49d..3fb3acf14d0f3033e65c21131d7c84b5ce29cbf2 100644 --- a/services/backup_sa/src/module_ipc/service_incremental.cpp +++ b/services/backup_sa/src/module_ipc/service_incremental.cpp @@ -81,7 +81,16 @@ ErrCode Service::Release() { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); HILOGI("KILL"); - VerifyCaller(session_->GetScenario()); + IServiceReverse::Scenario scenario = session_->GetScenario(); + VerifyCaller(scenario); + AppRadar::Info info("", "", "call release"); + if (scenario == IServiceReverse::Scenario::RESTORE) { + AppRadar::GetInstance().RecordRestoreFuncRes(info, "Service::Release", session_->GetSessionUserId(), + BizStageRestore::BIZ_STAGE_RELEASE, ERR_OK); + } else if (scenario == IServiceReverse::Scenario::BACKUP) { + AppRadar::GetInstance().RecordBackupFuncRes(info, "Service::Release", session_->GetSessionUserId(), + BizStageBackup::BIZ_STAGE_RELEASE, ERR_OK); + } SessionDeactive(); return BError(BError::Codes::OK); } @@ -275,11 +284,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 +332,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 +406,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 +483,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 +492,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 +511,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 +594,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 +632,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 +642,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 +661,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 +679,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 2e85358892a75cf5745c1814d6f859a7981d6d29..7798384122ed85a689e818fda91e58724621282f 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, scenario); 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 a809082f08d311e72ee0a65e59633cfba35ba251..f84668de14ea2615b8674c319430f1e8e10ec798 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 8d85731b3f3e1d6d8cd2a5f723f7bfbe75b03525..ca7e528f8c6ceba2cf55fe9ff671ff07f7d086eb 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 d2cc3ba158ff722e7a9d3b87f716f0f3c8fe3b77..9c1fc72f27a924bf05388162292b689c3d24ba21 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 dff5599bc07d449216a3689a1e1284e2dda3a3f8..4cad2e71b188a10cdae89d4a675036c2a1857fc8 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 2d964a2f566f7ae379b3f67c51b7bb7d347dd513..9f7295b245d0d506c1ca7f55cc0a422afccb5d2d 100644 --- a/tests/unittests/backup_sa/module_ipc/service_other_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_other_test.cpp @@ -370,6 +370,7 @@ HWTEST_F(ServiceTest, SUB_Service_OnStart_0200, TestSize.Level1) EXPECT_CALL(*jdConfig, GetBundleNameFromConfigFile()).WillOnce(Return(vector(1))) .WillOnce(Return(vector())); EXPECT_CALL(*cdConfig, GetAllClearBundleRecords()).WillOnce(Return(vector())); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); EXPECT_CALL(*skeleton, GetCallingTokenID()).WillOnce(Return(0)); EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); @@ -383,6 +384,7 @@ HWTEST_F(ServiceTest, SUB_Service_OnStart_0200, TestSize.Level1) EXPECT_CALL(*jdConfig, GetBundleNameFromConfigFile()).WillOnce(Return(vector())) .WillOnce(Return(vector())); EXPECT_CALL(*cdConfig, GetAllClearBundleRecords()).WillOnce(Return(vector(1))); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); EXPECT_CALL(*skeleton, GetCallingTokenID()).WillOnce(Return(0)); EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); @@ -394,6 +396,7 @@ HWTEST_F(ServiceTest, SUB_Service_OnStart_0200, TestSize.Level1) EXPECT_CALL(*jdConfig, GetBundleNameFromConfigFile()).WillOnce(Return(vector(1))) .WillOnce(Return(vector())); EXPECT_CALL(*cdConfig, GetAllClearBundleRecords()).WillOnce(Return(vector(1))); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); EXPECT_CALL(*skeleton, GetCallingTokenID()).WillOnce(Return(0)); EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); @@ -621,14 +624,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 +639,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 +647,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 +697,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); @@ -1301,7 +1304,8 @@ HWTEST_F(ServiceTest, SUB_Service_LaunchBackupExtension_0200, TestSize.Level1) ASSERT_TRUE(service != nullptr); string bundleName = ""; BJsonUtil::BundleDetailInfo info; - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)) + .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(false)); EXPECT_CALL(*jsonUtil, ParseBundleNameIndexStr(_)).WillOnce(Return(info)); EXPECT_CALL(*session, GetBackupExtName(_)).WillOnce(Return("")); @@ -1317,7 +1321,8 @@ HWTEST_F(ServiceTest, SUB_Service_LaunchBackupExtension_0200, TestSize.Level1) auto ret = service->LaunchBackupExtension(bundleName); EXPECT_EQ(ret, BError(BError::Codes::SA_BOOT_EXT_FAIL)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)); + EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::RESTORE)) + .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED)); EXPECT_CALL(*saUtils, IsSABundleName(_)).WillOnce(Return(false)); EXPECT_CALL(*jsonUtil, ParseBundleNameIndexStr(_)).WillOnce(Return(info)); EXPECT_CALL(*session, GetBackupExtName(_)).WillOnce(Return("")); @@ -1577,6 +1582,8 @@ HWTEST_F(ServiceTest, SUB_Service_BackupSA_0000, TestSize.Level1) EXPECT_CALL(*saConnect, CallBackupSA()).WillOnce(Return(BError(BError::Codes::OK).GetCode())); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); EXPECT_CALL(*srProxy, BackupOnBundleStarted(_, _)).WillOnce(Return()); + EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) + .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); ret = service->BackupSA(bundleName); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); @@ -1587,6 +1594,8 @@ HWTEST_F(ServiceTest, SUB_Service_BackupSA_0000, TestSize.Level1) EXPECT_CALL(*saConnect, CallBackupSA()).WillOnce(Return(BError(BError::Codes::SA_INVAL_ARG).GetCode())); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); EXPECT_CALL(*srProxy, BackupOnBundleStarted(_, _)).WillOnce(Return()); + EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) + .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*cdConfig, DeleteClearBundleRecord(_)).WillOnce(Return(false)); EXPECT_CALL(*session, IsOnAllBundlesFinished()).WillOnce(Return(false)); ret = service->BackupSA(bundleName); diff --git a/tests/unittests/backup_sa/module_ipc/service_test.cpp b/tests/unittests/backup_sa/module_ipc/service_test.cpp index 7f7ef75eca9ed0b74ebad47b3b868f121e0427c5..6a83d2469ccc391a509daa8f928dab3fe88a63e0 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 4cded015bb8f53cc90a51bb1079b6bd0c7b398d0..3863761c7c09fd2713dacd438f0f477b1ce9945a 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 226e0ece4186c82ab359383a63d6cc96e86ba3ac..2ec80872ed849717674d7aa70fc536c7e16f95d6 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,23 @@ public: int64_t totalFileSpendTime; }; + struct DoBackupInfo { + int64_t cost; + uint32_t allFileNum; + uint32_t smallFileNum; + uint32_t tarFileNum; + uint32_t includeNum; + uint32_t excludeNum; + }; + + 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, @@ -91,6 +119,8 @@ public: enum BizStageBackup bizStage, int32_t resultCode); void RecordRestoreFuncRes(Info &info, const std::string &func, int32_t userId, enum BizStageRestore bizStage, int32_t resultCode); + void RecordStatisticRes(StatInfo &statInfo, int32_t userId, enum IServiceReverse::Scenario scenario, + int32_t succ_cnt, int32_t fail_cnt, int32_t resultCode); private: AppRadar() = default; ~AppRadar() = default; diff --git a/utils/include/b_resources/b_constants.h b/utils/include/b_resources/b_constants.h index 0cfc16d259be34afb43dd72ce5239425fcac044c..fe7934006af567336cd85b49f86762f2645b64ec 100644 --- a/utils/include/b_resources/b_constants.h +++ b/utils/include/b_resources/b_constants.h @@ -231,8 +231,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 31ef80f3df37c713bea1937c7d336221d33aa92a..1c7f7ac8450ded0c0756ae40d4f69b87ef234dc3 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, @@ -97,4 +97,24 @@ void AppRadar::RecordRestoreFuncRes(Info &info, const std::string &func, int32_t "RESULT_CODE", resultCode, "RESULT_INFO", ss.str()); } + +void AppRadar::RecordStatisticRes(StatInfo &statInfo, int32_t userId, enum IServiceReverse::Scenario scenario, + int32_t succ_cnt, int32_t fail_cnt, int32_t resultCode) +{ + std::stringstream ss; + ss << R"("result_info": {)" << statInfo.resInfo << "}}"; + HiSysEventWrite( + OHOS::HiviewDFX::HiSysEvent::Domain::FILEMANAGEMENT, + BConstants::FILE_BACKUP_RESTORE_STATISTIC, + OHOS::HiviewDFX::HiSysEvent::EventType::STATISTIC, + "CALLER_NAME", statInfo.callerName, + "USER_ID", userId, + "PID", getpid(), + "TIME", TimeUtils::GetCurrentTime(), + "BIZ_SCENE", static_cast(scenario), + "SUCC_CNT", succ_cnt, + "FAIL_CNT", fail_cnt, + "RESULT_CODE", resultCode, + "RESULT_INFO", ss.str()); +} } // namespace OHOS::FileManagement::Backup \ No newline at end of file