From 63a881d968df8a5dbdbfe5a02293a68fea51df9a Mon Sep 17 00:00:00 2001 From: zhangyaomaggie Date: Tue, 22 Oct 2024 15:05:21 +0800 Subject: [PATCH] add radar Signed-off-by: zhangyaomaggie --- .../native/backup_ext/src/ext_extension.cpp | 23 ++- .../backup_ext/src/sub_ext_extension.cpp | 13 +- .../src/b_incremental_backup_session.cpp | 23 ++- .../src/b_incremental_restore_session.cpp | 29 +++- .../b_incremental_session_restore_async.cpp | 29 +++- .../backup_kit_inner/src/b_session_backup.cpp | 21 +-- .../src/b_session_restore.cpp | 29 +++- .../src/b_session_restore_async.cpp | 28 +++- .../src/service_incremental_reverse.cpp | 1 + .../backup_kit_inner/src/service_proxy.cpp | 16 +- .../backup_sa/include/module_ipc/service.h | 22 +++ services/backup_sa/src/module_ipc/service.cpp | 142 +++++++++++++++++- .../src/module_ipc/service_incremental.cpp | 39 ++++- .../backup_sa/src/module_ipc/sub_service.cpp | 4 + .../src/module_ipc/svc_session_manager.cpp | 5 - .../backup_sa/module_ipc/service_test.cpp | 10 +- utils/include/b_radar/b_radar.h | 14 +- utils/src/b_radar/b_radar.cpp | 22 +++ 18 files changed, 364 insertions(+), 106 deletions(-) diff --git a/frameworks/native/backup_ext/src/ext_extension.cpp b/frameworks/native/backup_ext/src/ext_extension.cpp index b5fcb349f..e8f61b26e 100644 --- a/frameworks/native/backup_ext/src/ext_extension.cpp +++ b/frameworks/native/backup_ext/src/ext_extension.cpp @@ -69,6 +69,7 @@ const string INDEX_FILE_INCREMENTAL_BACKUP = string(BConstants::PATH_BUNDLE_BACK append(BConstants::SA_BUNDLE_BACKUP_BACKUP); const string MEDIA_LIBRARY_BUNDLE_NAME = "com.ohos.medialibrary.medialibrarydata"; const string FILE_MANAGER_BUNDLE_NAME = "com.ohos.filepicker"; +const int32_t MAX_INEXCLUDE_SIZE = 25; using namespace std; static void RecordDoRestoreRes(const std::string &bundleName, const std::string &func, @@ -745,7 +746,12 @@ int BackupExtExtension::DoBackup(const BJsonEntityExtensionConfig &usrConfig) vector includes = usrConfig.GetIncludes(); vector excludes = usrConfig.GetExcludes(); - + // zhangyao includes / excludes 超过25 个打点 + if (includes.size() >= MAX_INEXCLUDE_SIZE || excludes.size() >= MAX_INEXCLUDE_SIZE) { + AppRadar::Info info(bundleName_, "", "includes or excludes exceed 25"); + AppRadar::GetInstance().RecordBackupFuncRes(info, "BackupExtExtension::DoBackup", + AppRadar::GetInstance().GetUserId(), BizStageBackup::BIZ_STAGE_DO_BACKUP, ERR_OK); + } auto proxy = ServiceProxy::GetInstance(); if (proxy == nullptr) { throw BError(BError::Codes::EXT_BROKEN_BACKUP_SA, std::generic_category().message(errno)); @@ -930,11 +936,16 @@ void BackupExtExtension::AsyncTaskBackup(const string 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)); + // zhangyao 只有成功的时候才计算backup耗时 + if (ret == ERR_OK) { + 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 6038f48b4..c7e3b0e79 100644 --- a/frameworks/native/backup_ext/src/sub_ext_extension.cpp +++ b/frameworks/native/backup_ext/src/sub_ext_extension.cpp @@ -976,11 +976,14 @@ 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)); + // zhangyao 只有成功时才计算时间 + if (ret == ERR_OK) { + 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)); + } return ret; } diff --git a/frameworks/native/backup_kit_inner/src/b_incremental_backup_session.cpp b/frameworks/native/backup_kit_inner/src/b_incremental_backup_session.cpp index cfaaf5ef5..a24f58fb1 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 @@ -56,9 +56,12 @@ unique_ptr BIncrementalBackupSession::Init(Callbacks int32_t res = proxy->InitIncrementalBackupSession(sptr(new ServiceReverse(callbacks))); if (res != 0) { HILOGE("Failed to Backup because of %{public}d", res); - AppRadar::Info info("", "", ""); - AppRadar::GetInstance().RecordBackupFuncRes(info, "BIncrementalBackupSession::Init", - AppRadar::GetInstance().GetUserId(), BizStageBackup::BIZ_STAGE_CREATE_BACKUP_SESSION_FAIL, res); + // zhangyao session 冲突不上报 + if (res != BError::BackupErrorCode::E_PERM) { + AppRadar::Info info("", "", ""); + AppRadar::GetInstance().RecordBackupFuncRes(info, "BIncrementalBackupSession::Init", + AppRadar::GetInstance().GetUserId(), BizStageBackup::BIZ_STAGE_CREATE_BACKUP_SESSION_FAIL, res); + } return nullptr; } @@ -97,13 +100,9 @@ ErrCode BIncrementalBackupSession::AppendBundles(vector bundle return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } - int32_t res = proxy->AppendBundlesIncrementalBackupSession(bundlesToBackup); + ErrCode res = proxy->AppendBundlesIncrementalBackupSession(bundlesToBackup); if (res != 0) { - std::string ss; - for (const auto &bundle : bundlesToBackup) { - ss += bundle.bundleName + ", "; - } - AppRadar::Info info(ss.c_str(), "", ""); + AppRadar::Info info("", "", ""); AppRadar::GetInstance().RecordBackupFuncRes(info, "BIncrementalBackupSession::AppendBundles", AppRadar::GetInstance().GetUserId(), BizStageBackup::BIZ_STAGE_APPEND_BUNDLES_FAIL, res); } @@ -120,11 +119,7 @@ ErrCode BIncrementalBackupSession::AppendBundles(vector bundle int32_t res = proxy->AppendBundlesIncrementalBackupSession(bundlesToBackup, infos); if (res != 0) { - std::string ss; - for (const auto &bundle : bundlesToBackup) { - ss += bundle.bundleName + ", "; - } - AppRadar::Info info(ss.c_str(), "", "AppendBundles with infos"); + AppRadar::Info info("", "", "AppendBundles with infos"); AppRadar::GetInstance().RecordBackupFuncRes(info, "BIncrementalBackupSession::AppendBundles", AppRadar::GetInstance().GetUserId(), BizStageBackup::BIZ_STAGE_APPEND_BUNDLES_FAIL, res); } diff --git a/frameworks/native/backup_kit_inner/src/b_incremental_restore_session.cpp b/frameworks/native/backup_kit_inner/src/b_incremental_restore_session.cpp index ed51e8cb9..527d8630b 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 @@ -55,10 +55,12 @@ unique_ptr BIncrementalRestoreSession::Init(Callback int32_t res = proxy->InitRestoreSession(sptr(new ServiceReverse(callbacks))); if (res != 0) { 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); + // zhangyao session 冲突不上报 + if (res != BError::BackupErrorCode::E_PERM) { + AppRadar::Info info ("", "", "create restore session failed"); + AppRadar::GetInstance().RecordRestoreFuncRes(info, "BIncrementalRestoreSession::Init", + AppRadar::GetInstance().GetUserId(), BizStageRestore::BIZ_STAGE_CREATE_RESTORE_SESSION_FAIL, res); + } return nullptr; } @@ -104,7 +106,14 @@ ErrCode BIncrementalRestoreSession::AppendBundles(UniqueFd remoteCap, vectorAppendBundlesRestoreSession(move(remoteCap), bundlesToRestore); + // zhangyao appendBundles 失败上报 遗漏 + ErrCode res = proxy->AppendBundlesRestoreSession(move(remoteCap), bundlesToRestore); + if (res != 0) { + AppRadar::Info info("", "", ""); + AppRadar::GetInstance().RecordRestoreFuncRes(info, "BIncrementalRestoreSession::AppendBundles", + AppRadar::GetInstance().GetUserId(), BizStageRestore::BIZ_STAGE_APPEND_BUNDLES_FAIL, res); + } + return res; } ErrCode BIncrementalRestoreSession::AppendBundles(UniqueFd remoteCap, vector bundlesToRestore, @@ -114,8 +123,14 @@ ErrCode BIncrementalRestoreSession::AppendBundles(UniqueFd remoteCap, vectorAppendBundlesRestoreSession(move(remoteCap), bundlesToRestore, detailInfos); + // zhangyao appendBundles 失败上报 遗漏 + ErrCode res = proxy->AppendBundlesRestoreSession(move(remoteCap), bundlesToRestore, detailInfos); + if (res != 0) { + AppRadar::Info info("", "", ""); + AppRadar::GetInstance().RecordRestoreFuncRes(info, "BIncrementalRestoreSession::AppendBundles", + AppRadar::GetInstance().GetUserId(), BizStageRestore::BIZ_STAGE_APPEND_BUNDLES_FAIL, res); + } + return res; } ErrCode BIncrementalRestoreSession::Release() diff --git a/frameworks/native/backup_kit_inner/src/b_incremental_session_restore_async.cpp b/frameworks/native/backup_kit_inner/src/b_incremental_session_restore_async.cpp index 75c7e3cbc..f5bdafd4f 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 @@ -63,10 +63,12 @@ shared_ptr BIncrementalSessionRestoreAsync::Ini int32_t res = proxy->InitRestoreSession(sptr(new ServiceReverse(callbacksTmp))); if (res != 0) { 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); + // zhangyao session 冲突不上报 + if (res != BError::BackupErrorCode::E_PERM) { + AppRadar::Info info ("", "", "create restore session failed"); + AppRadar::GetInstance().RecordRestoreFuncRes(info, "BIncrementalSessionRestoreAsync::Init", + AppRadar::GetInstance().GetUserId(), BizStageRestore::BIZ_STAGE_CREATE_RESTORE_SESSION_FAIL, res); + } return nullptr; } @@ -107,8 +109,15 @@ 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, + // zhangyao appendBundles 遗漏 + ErrCode res = proxy->AppendBundlesRestoreSession(move(remoteCap), bundlesToRestore, detailInfos, restoreType, userId); + if (res != 0) { + AppRadar::Info info("", "", ""); + AppRadar::GetInstance().RecordRestoreFuncRes(info, "BIncrementalSessionRestoreAsync::AppendBundles", + AppRadar::GetInstance().GetUserId(), BizStageRestore::BIZ_STAGE_APPEND_BUNDLES_FAIL, res); + } + return res; } ErrCode BIncrementalSessionRestoreAsync::AppendBundles(UniqueFd remoteCap, @@ -120,8 +129,14 @@ ErrCode BIncrementalSessionRestoreAsync::AppendBundles(UniqueFd remoteCap, if (proxy == nullptr) { return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } - - return proxy->AppendBundlesRestoreSession(move(remoteCap), bundlesToRestore, restoreType, userId); + // zhangyao appendBundles 遗漏 + ErrCode res = proxy->AppendBundlesRestoreSession(move(remoteCap), bundlesToRestore, restoreType, userId); + if (res != 0) { + AppRadar::Info info("", "", ""); + AppRadar::GetInstance().RecordRestoreFuncRes(info, "BIncrementalSessionRestoreAsync::AppendBundles", + AppRadar::GetInstance().GetUserId(), BizStageRestore::BIZ_STAGE_APPEND_BUNDLES_FAIL, res); + } + return res; } ErrCode BIncrementalSessionRestoreAsync::Release() diff --git a/frameworks/native/backup_kit_inner/src/b_session_backup.cpp b/frameworks/native/backup_kit_inner/src/b_session_backup.cpp index f20285515..ef6714289 100644 --- a/frameworks/native/backup_kit_inner/src/b_session_backup.cpp +++ b/frameworks/native/backup_kit_inner/src/b_session_backup.cpp @@ -56,9 +56,12 @@ unique_ptr BSessionBackup::Init(Callbacks callbacks) int32_t res = proxy->InitBackupSession(sptr(new ServiceReverse(callbacks))); if (res != 0) { HILOGE("Failed to Backup because of %{public}d", res); - AppRadar::Info info("", "", ""); - AppRadar::GetInstance().RecordBackupFuncRes(info, "BSessionBackup::Init", - AppRadar::GetInstance().GetUserId(), BizStageBackup::BIZ_STAGE_CREATE_BACKUP_SESSION_FAIL, res); + // zhangyao session 冲突不上报 + if (res != BError::BackupErrorCode::E_PERM) { + AppRadar::Info info("", "", ""); + AppRadar::GetInstance().RecordBackupFuncRes(info, "BSessionBackup::Init", + AppRadar::GetInstance().GetUserId(), BizStageBackup::BIZ_STAGE_CREATE_BACKUP_SESSION_FAIL, res); + } return nullptr; } @@ -109,11 +112,7 @@ ErrCode BSessionBackup::AppendBundles(vector bundlesToBackup) int32_t res = proxy->AppendBundlesBackupSession(bundlesToBackup); if (res != 0) { - std::string ss; - for (const auto &bundleName:bundlesToBackup) { - ss += bundleName + ", "; - } - AppRadar::Info info(ss.c_str(), "", ""); + AppRadar::Info info("", "", ""); AppRadar::GetInstance().RecordBackupFuncRes(info, "BSessionBackup::AppendBundles", AppRadar::GetInstance().GetUserId(), BizStageBackup::BIZ_STAGE_APPEND_BUNDLES_FAIL, res); } @@ -129,11 +128,7 @@ ErrCode BSessionBackup::AppendBundles(vector bundlesToBackup, vector int32_t res = proxy->AppendBundlesDetailsBackupSession(bundlesToBackup, detailInfos); if (res != 0) { - std::string ss; - for (const auto &bundleName:bundlesToBackup) { - ss += bundleName + ", "; - } - AppRadar::Info info(ss.c_str(), "", ""); + AppRadar::Info info("", "", ""); AppRadar::GetInstance().RecordBackupFuncRes(info, "BSessionBackup::AppendBundles", AppRadar::GetInstance().GetUserId(), BizStageBackup::BIZ_STAGE_APPEND_BUNDLES_FAIL, res); } diff --git a/frameworks/native/backup_kit_inner/src/b_session_restore.cpp b/frameworks/native/backup_kit_inner/src/b_session_restore.cpp index 0c37d2603..f2133e66f 100644 --- a/frameworks/native/backup_kit_inner/src/b_session_restore.cpp +++ b/frameworks/native/backup_kit_inner/src/b_session_restore.cpp @@ -55,10 +55,12 @@ unique_ptr BSessionRestore::Init(Callbacks callbacks) int32_t res = proxy->InitRestoreSession(new ServiceReverse(callbacks)); if (res != 0) { 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); + // zhangyao session 冲突不上报 + if (res != BError::BackupErrorCode::E_PERM) { + AppRadar::Info info ("", "", "create restore session failed"); + AppRadar::GetInstance().RecordRestoreFuncRes(info, "BSessionRestore::Init", + AppRadar::GetInstance().GetUserId(), BizStageRestore::BIZ_STAGE_CREATE_RESTORE_SESSION_FAIL, res); + } return nullptr; } @@ -106,7 +108,14 @@ 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); + // zhangyao appendBundles 遗漏 + ErrCode res = proxy->AppendBundlesRestoreSession(move(remoteCap), bundlesToRestore, detailInfos); + if (res != 0) { + AppRadar::Info info("", "", ""); + AppRadar::GetInstance().RecordRestoreFuncRes(info, "BSessionRestore::AppendBundles", + AppRadar::GetInstance().GetUserId(), BizStageRestore::BIZ_STAGE_APPEND_BUNDLES_FAIL, res); + } + return res; } ErrCode BSessionRestore::AppendBundles(UniqueFd remoteCap, vector bundlesToRestore) @@ -115,8 +124,14 @@ 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); + // zhangyao appendBundles 遗漏 + ErrCode res = proxy->AppendBundlesRestoreSession(move(remoteCap), bundlesToRestore); + if (res != 0) { + AppRadar::Info info("", "", ""); + AppRadar::GetInstance().RecordRestoreFuncRes(info, "BSessionRestore::AppendBundles", + AppRadar::GetInstance().GetUserId(), BizStageRestore::BIZ_STAGE_APPEND_BUNDLES_FAIL, res); + } + return res; } ErrCode BSessionRestore::Finish() diff --git a/frameworks/native/backup_kit_inner/src/b_session_restore_async.cpp b/frameworks/native/backup_kit_inner/src/b_session_restore_async.cpp index b3cea05e1..6f054fdeb 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 @@ -64,10 +64,12 @@ shared_ptr BSessionRestoreAsync::Init(Callbacks callbacks) int32_t res = proxy->InitRestoreSession(sptr(new ServiceReverse(callbacksTmp))); if (res != 0) { 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); + // zhangyao session 冲突不上报 + if (res != BError::BackupErrorCode::E_PERM) { + AppRadar::Info info ("", "", "create restore session failed"); + AppRadar::GetInstance().RecordRestoreFuncRes(info, "BSessionRestoreAsync::Init", + AppRadar::GetInstance().GetUserId(), BizStageRestore::BIZ_STAGE_CREATE_RESTORE_SESSION_FAIL, res); + } return nullptr; } @@ -108,8 +110,15 @@ 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, + // zhangyao appendBundles 遗漏 + ErrCode res = proxy->AppendBundlesRestoreSession(move(remoteCap), bundlesToRestore, detailInfos, restoreType, userId); + if (res != 0) { + AppRadar::Info info("", "", ""); + AppRadar::GetInstance().RecordRestoreFuncRes(info, "BSessionRestoreAsync::AppendBundles", + AppRadar::GetInstance().GetUserId(), BizStageRestore::BIZ_STAGE_APPEND_BUNDLES_FAIL, res); + } + return res; } ErrCode BSessionRestoreAsync::AppendBundles(UniqueFd remoteCap, @@ -122,7 +131,14 @@ 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); + // zhangyao appendBundles 失败 + ErrCode res = proxy->AppendBundlesRestoreSession(move(remoteCap), bundlesToRestore, restoreType, userId); + if (res != 0) { + AppRadar::Info info("", "", ""); + AppRadar::GetInstance().RecordRestoreFuncRes(info, "BSessionRestoreAsync::AppendBundles", + AppRadar::GetInstance().GetUserId(), BizStageRestore::BIZ_STAGE_APPEND_BUNDLES_FAIL, res); + } + return res; } ErrCode BSessionRestoreAsync::Release() diff --git a/frameworks/native/backup_kit_inner/src/service_incremental_reverse.cpp b/frameworks/native/backup_kit_inner/src/service_incremental_reverse.cpp index ec842c432..ba1e761c5 100644 --- a/frameworks/native/backup_kit_inner/src/service_incremental_reverse.cpp +++ b/frameworks/native/backup_kit_inner/src/service_incremental_reverse.cpp @@ -16,6 +16,7 @@ #include "service_reverse.h" #include "b_error/b_error.h" +#include "b_radar/b_radar.h" #include "filemgmt_libhilog.h" namespace OHOS::FileManagement::Backup { diff --git a/frameworks/native/backup_kit_inner/src/service_proxy.cpp b/frameworks/native/backup_kit_inner/src/service_proxy.cpp index f3e1854ba..e05fb5138 100644 --- a/frameworks/native/backup_kit_inner/src/service_proxy.cpp +++ b/frameworks/native/backup_kit_inner/src/service_proxy.cpp @@ -301,13 +301,6 @@ ErrCode ServiceProxy::AppendBundlesRestoreSession(UniqueFd fd, const vector(IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_RESTORE_SESSION), data, reply, option); if (ret != NO_ERROR) { string str = "Failed to send out the request because of " + to_string(ret); - std::string ss; - for (const auto &bundleName : bundleNames) { - ss += bundleName + ", "; - } - AppRadar::Info info(ss.c_str(), "", str); - AppRadar::GetInstance().RecordRestoreFuncRes(info, "ServiceProxy::AppendBundlesRestoreSession", userId, - BizStageRestore::BIZ_STAGE_APPEND_BUNDLES_FAIL, ret); return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); } return reply.ReadInt32(); @@ -473,7 +459,7 @@ sptr ServiceProxy::GetInstance() AppRadar::Info info("", "", "\"reason\":\"Load backup sa timeout\""); AppRadar::GetInstance().RecordBackupFuncRes(info, "ServiceProxy::GetInstance", AppRadar::GetInstance().GetUserId(), BizStageBackup::BIZ_STAGE_BOOT_BACKUP_SA_FAIL, - static_cast(BError::Codes::SA_INVAL_ARG)); + BError(BError::Codes::SA_INVAL_ARG).GetCode()); return nullptr; } return serviceProxy_; diff --git a/services/backup_sa/include/module_ipc/service.h b/services/backup_sa/include/module_ipc/service.h index d9c1c4bcf..67c31b869 100644 --- a/services/backup_sa/include/module_ipc/service.h +++ b/services/backup_sa/include/module_ipc/service.h @@ -38,6 +38,11 @@ struct extensionInfo { extensionInfo(std::string bundleName_) : bundleName(bundleName_) {}; }; +struct BundleTaskInfo { + std::string reportTime; + ErrCode errCode; +}; + class Service : public SystemAbility, public ServiceStub, protected NoCopyable { DECLARE_SYSTEM_ABILITY(Service); @@ -514,6 +519,21 @@ private: void HandleCurGroupIncBackupInfos(vector &bundleInfos, std::map> &bundleNameDetailMap, std::map &isClearDataFlags); + + 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); + private: static sptr instance_; static std::mutex instanceLock_; @@ -536,6 +556,8 @@ private: std::mutex extensionLock_; public: std::map> backupExtMutexMap_; + std::map failedBundles_; + uint32_t successBundlesNum_; }; } // namespace OHOS::FileManagement::Backup diff --git a/services/backup_sa/src/module_ipc/service.cpp b/services/backup_sa/src/module_ipc/service.cpp index b363d02d3..f0c5b5bad 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,64 @@ static inline int32_t GetUserIdDefault() return multiuser.userId; } +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; + failedBundles_[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; + failedBundles_[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::OnStart() { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); @@ -210,6 +269,31 @@ UniqueFd Service::GetLocalCapabilities() void Service::StopAll(const wptr &obj, bool force) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + // zhangyao session粒度 成功应用数量 失败应用数量 + int32_t totalBundles = failedBundles_.size() + successBundlesNum_; + if (totalBundles != 0) { + std::stringstream ss; + ss << "successBundleNum:" << successBundlesNum_ << "," << "failedBundleNum:" << + failedBundles_.size() << "," << "failedBundles:{"; + for (auto &failBundle : failedBundles_) { + ss << "\"" << failBundle.first << "\":" << "{errCode:" << failBundle.second.errCode << "," + << "reportTime:" << failBundle.second.reportTime << "},"; + } + ss << "}"; + string resultInfo = ss.str(); + AppRadar::Info info("", "", resultInfo); + if (session_->GetScenario() == IServiceReverse::Scenario::RESTORE) { + AppRadar::GetInstance().RecordSessionStatsticRes(info, "Service::StopAll", GetUserIdDefault(), + IServiceReverse::Scenario::RESTORE, BizStageRestore::BIZ_STAGE_EXECU_RESULT, + successBundlesNum_, failedBundles_.size()); + } else if (session_->GetScenario() == IServiceReverse::Scenario::BACKUP) { + AppRadar::GetInstance().RecordSessionStatsticRes(info, "Service::StopAll", GetUserIdDefault(), + IServiceReverse::Scenario::BACKUP, BizStageRestore::BIZ_STAGE_EXECU_RESULT, + successBundlesNum_, failedBundles_.size()); + } + } + failedBundles_.clear(); + successBundlesNum_ = 0; session_->Deactive(obj, force); } @@ -306,12 +390,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) { + failedBundles_.clear(); + successBundlesNum_ = 0; + } + return errCode; } catch (const BError &e) { StopAll(nullptr, true); return e.GetCode(); @@ -332,12 +421,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) { + failedBundles_.clear(); + successBundlesNum_ = 0; + } + return errCode; } catch (const BError &e) { StopAll(nullptr, true); return e.GetCode(); @@ -375,7 +469,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() && @@ -384,6 +478,8 @@ static void OnBundleStarted(BError error, sptr session, const } else if (scenario == IServiceReverse::Scenario::RESTORE) { session->GetServiceReverseProxy()->RestoreOnBundleStarted(error, bundleName); } + // zhangyao onBundleBegin 失败 + BundleBeginRadarReport(bundleName, error.GetCode(), scenario); } static vector GetRestoreBundleNames(UniqueFd fd, @@ -437,7 +533,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()) { @@ -671,6 +767,9 @@ ErrCode Service::AppendBundlesBackupSession(const vector &bundleName if (info.allToBackup == false) { session_->GetServiceReverseProxy()->BackupOnBundleStarted( BError(BError::Codes::SA_FORBID_BACKUP_RESTORE), bundleNameIndexInfo); + // zhangyao onBundleBegin 失败 + BundleBeginRadarReport(bundleNameIndexInfo, BError(BError::Codes::SA_FORBID_BACKUP_RESTORE).GetCode(), + IServiceReverse::Scenario::BACKUP); session_->RemoveExtInfo(bundleNameIndexInfo); } } @@ -744,6 +843,9 @@ void Service::HandleCurGroupBackupInfos(std::vector if (info.allToBackup == false) { session_->GetServiceReverseProxy()->BackupOnBundleStarted( BError(BError::Codes::SA_FORBID_BACKUP_RESTORE), bundleNameIndexInfo); + // zhangyao onBundleBegin 失败 + BundleBeginRadarReport(bundleNameIndexInfo, BError(BError::Codes::SA_FORBID_BACKUP_RESTORE).GetCode(), + IServiceReverse::Scenario::BACKUP); session_->RemoveExtInfo(bundleNameIndexInfo); } BJsonUtil::BundleDetailInfo uniCastInfo; @@ -801,6 +903,13 @@ ErrCode Service::SAResultReport(const std::string bundleName, const std::string } else if (sennario == BackupRestoreScenario::INCREMENTAL_BACKUP) { session_->GetServiceReverseProxy()->IncrementalBackupOnResultReport(restoreRetInfo, bundleName); } + // zhangyao onBundleEnd失败 + 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); } @@ -886,6 +995,8 @@ 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); + // zhangyao onFileReady 失败 + FileReadyRadarReport(bundleName, fileName, errCode, IServiceReverse::Scenario::RESTORE); } else { session_->SetExtFileNameRequest(bundleName, fileName); } @@ -986,6 +1097,8 @@ void Service::ExtStart(const string &bundleName) if (scenario == IServiceReverse::Scenario::BACKUP) { auto ret = proxy->HandleBackup(session_->GetClearDataFlag(bundleName)); session_->GetServiceReverseProxy()->BackupOnBundleStarted(ret, bundleName); + // zhangyao onBundleBegin 失败 + BundleBeginRadarReport(bundleName, ret, scenario); if (ret) { ClearSessionAndSchedInfo(bundleName); NoticeClientFinish(bundleName, BError(BError::Codes::SA_INVAL_ARG)); @@ -997,11 +1110,15 @@ void Service::ExtStart(const string &bundleName) } auto ret = proxy->HandleRestore(session_->GetClearDataFlag(bundleName)); session_->GetServiceReverseProxy()->RestoreOnBundleStarted(ret, bundleName); + // zhangyao onBundleBegin 失败 + 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); + // zhangyao onFileReady 失败 + FileReadyRadarReport(bundleName, fileName, errCode, scenario); } return; } catch (...) { @@ -1033,18 +1150,25 @@ void Service::ReportOnExtConnectFailed(const IServiceReverse::Scenario scenario, } if (scenario == IServiceReverse::Scenario::BACKUP && session_->GetIsIncrementalBackup()) { session_->GetServiceReverseProxy()->IncrementalBackupOnBundleStarted(ret, bundleName); + // zhangyao onBundleBegin 失败 + BundleBeginRadarReport(bundleName, ret, scenario); } else if (scenario == IServiceReverse::Scenario::RESTORE && BackupPara().GetBackupOverrideIncrementalRestore() && session_->ValidRestoreDataType(RestoreTypeEnum::RESTORE_DATA_WAIT_SEND)) { session_->GetServiceReverseProxy()->IncrementalRestoreOnBundleStarted(ret, bundleName); - + // zhangyao onBundleBegin 失败 + 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); + // zhangyao onBundleBegin 失败 + BundleBeginRadarReport(bundleName, ret, scenario); } else if (scenario == IServiceReverse::Scenario::RESTORE) { session_->GetServiceReverseProxy()->RestoreOnBundleStarted(ret, bundleName); + // zhangyao onBundleBegin 失败 + BundleBeginRadarReport(bundleName, ret, scenario); DisposeErr disposeErr = AppGalleryDisposeProxy::GetInstance()->EndRestore(bundleName); HILOGI("ExtConnectFailed EndRestore, code=%{public}d, bundleName=%{public}s", disposeErr, bundleName.c_str()); @@ -1101,6 +1225,8 @@ void Service::NoticeClientFinish(const string &bundleName, ErrCode errCode) } else if (scenario == IServiceReverse::Scenario::RESTORE) { session_->GetServiceReverseProxy()->RestoreOnBundleFinished(errCode, bundleName); }; + // zhangyao onBundleEnd 失败 + BundleEndRadarReport(bundleName, errCode, scenario); /* If all bundle ext process finish, notice client. */ OnAllBundlesFinished(BError(BError::Codes::OK)); } catch(const BError &e) { @@ -1709,6 +1835,8 @@ ErrCode Service::BackupSA(std::string bundleName) if (scenario == IServiceReverse::Scenario::BACKUP) { auto ret = saConnection->CallBackupSA(); session_->GetServiceReverseProxy()->BackupOnBundleStarted(ret, bundleName); + // zhangyao onBundleBegin 失败 + BundleBeginRadarReport(bundleName, ret, scenario); if (ret) { HILOGI("BackupSA ret is %{public}d", ret); ClearSessionAndSchedInfo(bundleName); @@ -1728,6 +1856,8 @@ 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); + // zhangyao onFileReady 失败 + FileReadyRadarReport(bundleName, fileName, errCode, IServiceReverse::Scenario::BACKUP); SAResultReport(bundleName, result, errCode, BackupRestoreScenario::FULL_BACKUP); }; threadPool_.AddTask([task]() { @@ -1812,6 +1942,8 @@ void Service::NotifyCallerCurAppDone(ErrCode errCode, const std::string &callerN HILOGI("will notify clone data, scenario is Restore"); session_->GetServiceReverseProxy()->RestoreOnBundleFinished(errCode, callerName); } + // zhangyao onBundleEnd 失败 + 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 ec2f4efea..a6ff9c018 100644 --- a/services/backup_sa/src/module_ipc/service_incremental.cpp +++ b/services/backup_sa/src/module_ipc/service_incremental.cpp @@ -254,11 +254,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) { + failedBundles_.clear(); + successBundlesNum_ = 0; + } + return errCode; } catch (const BError &e) { StopAll(nullptr, true); return e.GetCode(); @@ -297,6 +302,9 @@ ErrCode Service::AppendBundlesIncrementalBackupSession(const std::vectorGetServiceReverseProxy()->IncrementalBackupOnBundleStarted( BError(BError::Codes::SA_FORBID_BACKUP_RESTORE), bundleNameIndexInfo); + // zhangyao onBundleBegin 失败 + BundleBeginRadarReport(bundleNameIndexInfo, BError(BError::Codes::SA_FORBID_BACKUP_RESTORE).GetCode(), + IServiceReverse::Scenario::BACKUP); session_->RemoveExtInfo(bundleNameIndexInfo); } } @@ -369,6 +377,9 @@ void Service::HandleCurGroupIncBackupInfos(vector & if (info.allToBackup == false) { session_->GetServiceReverseProxy()->IncrementalBackupOnBundleStarted( BError(BError::Codes::SA_FORBID_BACKUP_RESTORE), bundleNameIndexInfo); + // zhangyao onBundleBegin 失败 + BundleBeginRadarReport(bundleNameIndexInfo, BError(BError::Codes::SA_FORBID_BACKUP_RESTORE).GetCode(), + IServiceReverse::Scenario::BACKUP); session_->RemoveExtInfo(bundleNameIndexInfo); } BJsonUtil::BundleDetailInfo uniCastInfo; @@ -444,6 +455,8 @@ 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); + // zhangyao onFileReady 失败 + FileReadyRadarReport(callerName, fileName, errCode, IServiceReverse::Scenario::RESTORE); return BError(BError::Codes::OK); } if (fileName == BConstants::EXT_BACKUP_MANAGE) { @@ -452,6 +465,8 @@ ErrCode Service::AppIncrementalFileReady(const std::string &fileName, UniqueFd f HILOGD("reverse: Will notify IncrementalBackupOnFileReady"); session_->GetServiceReverseProxy()->IncrementalBackupOnFileReady(callerName, fileName, move(fd), move(manifestFd), errCode); + // zhangyao onFileReady 失败 + 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); @@ -470,6 +485,8 @@ ErrCode Service::AppIncrementalFileReady(const std::string &fileName, UniqueFd f HILOGI("reverse: Will notify IncrementalBackupOnBundleFinished"); session_->GetServiceReverseProxy()->IncrementalBackupOnBundleFinished(BError(BError::Codes::OK), callerName); + // zhangyao onBundleEnd 失败 + BundleEndRadarReport(callerName, BError(BError::Codes::OK), IServiceReverse::Scenario::BACKUP); // 断开extension backUpConnection->DisconnectBackupExtAbility(); ClearSessionAndSchedInfo(callerName); @@ -547,8 +564,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", @@ -585,6 +602,8 @@ 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); + // zhangyao onBundleBegin 失败 + BundleBeginRadarReport(bundleName, ret, IServiceReverse::Scenario::BACKUP); if (ret) { ClearSessionAndSchedInfo(bundleName); NoticeClientFinish(bundleName, BError(BError::Codes::EXT_ABILITY_DIED)); @@ -594,6 +613,8 @@ 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); + // zhangyao onBundleBegin 失败 + BundleBeginRadarReport(bundleName, ret, IServiceReverse::Scenario::RESTORE); auto fileNameVec = session_->GetExtFileNameRequest(bundleName); for (auto &fileName : fileNameVec) { ret = proxy->GetIncrementalFileHandle(fileName); @@ -612,6 +633,8 @@ 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); + // zhangyao onBundleEnd 失败 + 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()); @@ -629,6 +652,8 @@ void Service::NotifyCallerCurAppIncrementDone(ErrCode errCode, const std::string HILOGI("will notify clone data, scenario is Restore"); SendEndAppGalleryNotify(callerName); session_->GetServiceReverseProxy()->IncrementalRestoreOnBundleFinished(errCode, callerName); + // zhangyao onBundleEnd 失败 + 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 282247d0a..2b1b97271 100644 --- a/services/backup_sa/src/module_ipc/sub_service.cpp +++ b/services/backup_sa/src/module_ipc/sub_service.cpp @@ -136,6 +136,8 @@ 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); + // zhangyao onFileReady 失败 + 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 +159,8 @@ ErrCode Service::AppFileReady(const string &fileName, UniqueFd fd, int32_t errCo session_->StopExtTimer(callerName); // 通知TOOL 备份完成 session_->GetServiceReverseProxy()->BackupOnBundleFinished(BError(BError::Codes::OK), callerName); + // zhangyao onBundleEnd 失败 + BundleEndRadarReport(callerName, BError(BError::Codes::OK), session_->GetScenario()); // 断开extension backUpConnection->DisconnectBackupExtAbility(); ClearSessionAndSchedInfo(callerName); 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 6723765ae..a6353cf94 100644 --- a/services/backup_sa/src/module_ipc/svc_session_manager.cpp +++ b/services/backup_sa/src/module_ipc/svc_session_manager.cpp @@ -368,11 +368,6 @@ 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)); diff --git a/tests/unittests/backup_sa/module_ipc/service_test.cpp b/tests/unittests/backup_sa/module_ipc/service_test.cpp index 1d45f92de..1cd1e1098 100644 --- a/tests/unittests/backup_sa/module_ipc/service_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_test.cpp @@ -1286,11 +1286,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."; @@ -1317,14 +1317,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_radar/b_radar.h b/utils/include/b_radar/b_radar.h index 226e0ece4..df69944b1 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 { @@ -33,8 +34,9 @@ enum class BizStageBackup : int32_t { 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_PERMISSION_CHECK_FAIL, + BIZ_STAGE_EXECU_FAIL, + BIZ_STAGE_EXECU_RESULT }; enum class BizStageRestore : int32_t { @@ -51,8 +53,9 @@ enum class BizStageRestore : int32_t { 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_PERMISSION_CHECK_FAIL, + BIZ_STAGE_EXECU_FAIL, + BIZ_STAGE_EXECU_RESULT }; class AppRadar { @@ -91,6 +94,9 @@ 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 RecordSessionStatsticRes(Info &info, const std::string &func, int32_t userId, + enum IServiceReverse::Scenario scenario, enum BizStageRestore bizStage, + int32_t succ_cnt, int32_t fail_cnt); private: AppRadar() = default; ~AppRadar() = default; diff --git a/utils/src/b_radar/b_radar.cpp b/utils/src/b_radar/b_radar.cpp index 31ef80f3d..88ca9fd52 100644 --- a/utils/src/b_radar/b_radar.cpp +++ b/utils/src/b_radar/b_radar.cpp @@ -97,4 +97,26 @@ void AppRadar::RecordRestoreFuncRes(Info &info, const std::string &func, int32_t "RESULT_CODE", resultCode, "RESULT_INFO", ss.str()); } + +void AppRadar::RecordSessionStatsticRes(Info &info, const std::string &func, int32_t userId, + enum IServiceReverse::Scenario scenario, enum BizStageRestore bizStage, + int32_t succ_cnt, int32_t fail_cnt) +{ + std::stringstream ss; + ss << "{\"result_info\": {" << info.resInfo << "}}"; + HiSysEventWrite( + OHOS::HiviewDFX::HiSysEvent::Domain::FILEMANAGEMENT, + BConstants::FILE_BACKUP_RESTORE_EVENTS, + OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, + "BUNDLE_NAME", info.bundleName, + "USER_ID", userId, + "PID", getpid(), + "FUNC", func, + "TIME", TimeUtils::GetCurrentTime(), + "BIZ_SCENE", static_cast(scenario), + "BIZ_STAGE", static_cast(bizStage), + "SUCC_CNT", succ_cnt, + "FAIL_CNT", fail_cnt, + "RESULT_INFO", ss.str()); +} } // namespace OHOS::FileManagement::Backup \ No newline at end of file -- Gitee