diff --git a/frameworks/native/backup_ext/src/ext_extension.cpp b/frameworks/native/backup_ext/src/ext_extension.cpp index 2ba8859d9cebaac2c0b5641f1f0d07ada11d08ba..e2e6fae9ef92df2546cf23e701b5bc804aca6087 100644 --- a/frameworks/native/backup_ext/src/ext_extension.cpp +++ b/frameworks/native/backup_ext/src/ext_extension.cpp @@ -73,15 +73,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(), 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..5086262692d1999cb8711bcab191ab77926862f6 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,7 +108,7 @@ 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 + ", "; @@ -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 + ", "; } - 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 5882fc979c9f3299ad054ab25a1b3f5ddc513c58..6e1677d019e4d54ab83066148a26058c7072544c 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 添加清理记录 @@ -512,6 +517,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(); std::vector GetSupportBackupBundleNames(vector &bundleInfos, bool isIncBackup); private: @@ -534,8 +559,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..0540db747a48c4907cf5c8f903770394075b1240 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 @@ -102,19 +102,19 @@ void RecordDoDisposeRes(const std::string &bundleName, switch (disposeOperation) { case AppGalleryDisposeProxy::DisposeOperation::START_BACKUP: AppRadar::GetInstance().RecordBackupFuncRes(info, "StartBackup", AppRadar::GetInstance().GetUserId(), - BizStageBackup::BIZ_STAGE_START_DISPOSE_FAIL, err); + BizStageBackup::BIZ_STAGE_START_DISPOSE, err); break; case AppGalleryDisposeProxy::DisposeOperation::END_BACKUP: AppRadar::GetInstance().RecordBackupFuncRes(info, "EndBackup", AppRadar::GetInstance().GetUserId(), - BizStageBackup::BIZ_STAGE_END_DISPOSE_FAIL, err); + BizStageBackup::BIZ_STAGE_END_DISPOSE, err); break; case AppGalleryDisposeProxy::DisposeOperation::START_RESTORE: AppRadar::GetInstance().RecordRestoreFuncRes(info, "StartRestore", AppRadar::GetInstance().GetUserId(), - BizStageRestore::BIZ_STAGE_START_DISPOSE_FAIL, err); + BizStageRestore::BIZ_STAGE_START_DISPOSE, err); break; case AppGalleryDisposeProxy::DisposeOperation::END_RESTORE: AppRadar::GetInstance().RecordRestoreFuncRes(info, "EndRestore", AppRadar::GetInstance().GetUserId(), - BizStageRestore::BIZ_STAGE_END_DISPOSE_FAIL, err); + BizStageRestore::BIZ_STAGE_END_DISPOSE, err); break; default: break; diff --git a/services/backup_sa/src/module_ipc/service.cpp b/services/backup_sa/src/module_ipc/service.cpp index c0865bb8770bf5e7960e5a65e4e968b99f69dce8..5785bc60ca89d7c74900330358c761bb89708342 100644 --- a/services/backup_sa/src/module_ipc/service.cpp +++ b/services/backup_sa/src/module_ipc/service.cpp @@ -50,6 +50,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,106 @@ static inline int32_t GetUserIdDefault() return multiuser.userId; } +void OnStartResRadarReport(const std::vector &bundleNameList, int32_t stage) +{ + std::stringstream ss; + ss << "failedBundles:{"; + for (auto &bundleName : bundleNameList) { + ss << bundleName << ", "; + } + ss << "}"; + AppRadar::Info info("", "", ss.str()); + AppRadar::GetInstance().RecordDefaultFuncRes(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 +217,14 @@ void Service::OnStart() residualBundleNameList = clearRecorder_->GetAllClearBundleRecords(); } if (!bundleNameList.empty() || !residualBundleNameList.empty()) { + if (!bundleNameList.empty()) { + OnStartResRadarReport(bundleNameList, + static_cast(BizStageBackup::BIZ_STAGE_ONSTART_DISPOSE)); + } + if (!residualBundleNameList.empty()) { + OnStartResRadarReport(residualBundleNameList, + static_cast(BizStageBackup::BIZ_STAGE_ONSTART_RESIDUAL)); + } session_->Active( { .clientToken = IPCSkeleton::GetCallingTokenID(), @@ -206,6 +315,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); } @@ -302,12 +414,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(); @@ -328,12 +445,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(); @@ -371,7 +493,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() && @@ -380,6 +502,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, @@ -431,7 +554,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()) { @@ -770,6 +893,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); } @@ -860,6 +989,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); } @@ -878,21 +1008,6 @@ ErrCode Service::GetFileHandle(const string &bundleName, const string &fileName) void Service::OnBackupExtensionDied(const string &&bundleName, bool isSecondCalled) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - if (isSecondCalled) { - HILOGE("Backup <%{public}s> Extension Process second Died", bundleName.c_str()); - ClearSessionAndSchedInfo(bundleName); - 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()); @@ -967,29 +1082,29 @@ 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)); } return; - } - if (scenario != IServiceReverse::Scenario::RESTORE) { + } else if (scenario != IServiceReverse::Scenario::RESTORE) { throw BError(BError::Codes::SA_INVAL_ARG, "Failed to scenario"); } 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; } } @@ -1014,18 +1129,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()); @@ -1042,14 +1160,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)); @@ -1082,6 +1192,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) { @@ -1426,10 +1537,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) { @@ -1440,7 +1551,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(); } @@ -1449,6 +1560,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) @@ -1698,6 +1810,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); @@ -1717,6 +1830,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]() { @@ -1801,6 +1915,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 5eff11cf04c38c240e6032277bfe5ed5b60a43b6..7d330e0d1c04e65dddc6b517dbd60289aa1c7b0c 100644 --- a/services/backup_sa/src/module_ipc/service_incremental.cpp +++ b/services/backup_sa/src/module_ipc/service_incremental.cpp @@ -262,11 +262,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(); @@ -442,6 +447,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); } @@ -451,6 +457,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); if (session_->OnBundleFileReady(callerName, fileName)) { auto backUpConnection = session_->GetExtConnection(callerName); auto proxy = backUpConnection->GetBackupExtProxy(); @@ -466,6 +473,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); @@ -549,8 +557,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", @@ -587,6 +595,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)); @@ -596,6 +605,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); @@ -614,6 +624,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()); @@ -631,6 +642,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 6395fc2935283bb31ca2c56666e1b9adec849f5d..96c10ca86f99328d57557c704426f87508f2531b 100644 --- a/services/backup_sa/src/module_ipc/sub_service.cpp +++ b/services/backup_sa/src/module_ipc/sub_service.cpp @@ -135,6 +135,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()); if (session_->OnBundleFileReady(callerName, fileName)) { auto backUpConnection = session_->GetExtConnection(callerName); if (backUpConnection == nullptr) { @@ -153,6 +154,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); @@ -251,6 +253,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); @@ -302,6 +305,8 @@ std::vector Service::GetSupportBackupBundleNames(vectorGetServiceReverseProxy()->BackupOnBundleStarted( BError(BError::Codes::SA_FORBID_BACKUP_RESTORE), bundleNameIndexInfo); } + BundleBeginRadarReport(bundleNameIndexInfo, BError(BError::Codes::SA_FORBID_BACKUP_RESTORE).GetCode(), + IServiceReverse::Scenario::BACKUP); continue; } supportBackupNames.emplace_back(bundleNameIndexInfo); 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 273b7ce5791c01873e865705b83634f2c860ea67..aebfe1d916dfaf4d743cdb62a1902697071708e7 100644 --- a/services/backup_sa/src/module_ipc/svc_session_manager.cpp +++ b/services/backup_sa/src/module_ipc/svc_session_manager.cpp @@ -108,6 +108,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; @@ -367,15 +375,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..efcfb24d6329383f4989b9eff341440a7ff4c6d6 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" diff --git a/tests/mock/module_ipc/service_mock.cpp b/tests/mock/module_ipc/service_mock.cpp index f4b3294809193381874caa4da15c639c4e3d7d01..657809995d06256233af7369b0fabf97f00b6d54 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,26 @@ 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() {} std::vector Service::GetSupportBackupBundleNames(vector&, bool) { return {}; diff --git a/tests/unittests/backup_sa/module_ipc/service_test.cpp b/tests/unittests/backup_sa/module_ipc/service_test.cpp index 55251cc252116d601a307159cf54184af29b42b2..9065de6caf3f39b991638d0ab6cb783db6fc4a94 100644 --- a/tests/unittests/backup_sa/module_ipc/service_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_test.cpp @@ -1269,11 +1269,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."; @@ -1300,14 +1300,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..9bf798493280064a1cb7f702640ef55a75db7bf5 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 { 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..1316310e04abf32c7bff25ad0b6c17a10b8ca444 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,