From ef147db2389157b885c8912f780f9997c1c219d4 Mon Sep 17 00:00:00 2001 From: zhangyaomaggie Date: Fri, 23 Aug 2024 19:35:56 +0800 Subject: [PATCH 1/3] add radar v1 Signed-off-by: zhangyaomaggie --- .../native/backup_ext/src/ext_extension.cpp | 42 ++++ .../backup_ext/src/sub_ext_extension.cpp | 61 +++++ .../src/b_incremental_backup_session.cpp | 25 +- .../src/b_incremental_restore_session.cpp | 4 + .../b_incremental_session_restore_async.cpp | 4 + .../backup_kit_inner/src/b_session_backup.cpp | 25 +- .../src/b_session_restore.cpp | 3 + .../src/b_session_restore_async.cpp | 4 + .../backup_kit_inner/src/service_proxy.cpp | 14 ++ .../native/backup_kit_inner/BUILD.gn | 1 + .../backup_sa/include/module_ipc/service.h | 3 + .../app_gallery_dispose_proxy.cpp | 31 +++ services/backup_sa/src/module_ipc/service.cpp | 91 +++++++ .../src/module_ipc/service_incremental.cpp | 6 + .../src/module_ipc/svc_session_manager.cpp | 11 + utils/BUILD.gn | 3 + utils/include/b_radar/b_radar.h | 105 ++++++++ utils/src/b_radar/b_radar.cpp | 228 ++++++++++++++++++ 18 files changed, 657 insertions(+), 4 deletions(-) create mode 100644 utils/include/b_radar/b_radar.h create mode 100644 utils/src/b_radar/b_radar.cpp diff --git a/frameworks/native/backup_ext/src/ext_extension.cpp b/frameworks/native/backup_ext/src/ext_extension.cpp index 2d836e2b9..f00b12abf 100644 --- a/frameworks/native/backup_ext/src/ext_extension.cpp +++ b/frameworks/native/backup_ext/src/ext_extension.cpp @@ -47,6 +47,7 @@ #include "b_json/b_json_cached_entity.h" #include "b_jsonutil/b_jsonutil.h" #include "b_ohos/startup/backup_para.h" +#include "b_radar/b_radar.h" #include "b_tarball/b_tarball_factory.h" #include "filemgmt_libhilog.h" #include "hitrace_meter.h" @@ -126,10 +127,18 @@ void BackupExtExtension::VerifyCaller() uint32_t tokenCaller = IPCSkeleton::GetCallingTokenID(); int tokenType = Security::AccessToken::AccessTokenKit::GetTokenType(tokenCaller); if (tokenType != Security::AccessToken::ATokenTypeEnum::TOKEN_NATIVE) { + Backup::AppRadar::GetInstance().RecordBackUpFuncResWithoutBundle("BackupExtExtension::VerifyCaller", + AppRadar::GetInstance().GetUserId(), BizStage::BIZ_STAGE_PERMISSION_CHECK, + static_cast(BError::Codes::SA_REFUSED_ACT), + "{\"reason\":\"Calling tokenType error\"}"); throw BError(BError::Codes::EXT_BROKEN_IPC, string("Calling tokenType is error, token type is ").append(to_string(tokenType))); } if (IPCSkeleton::GetCallingUid() != BConstants::BACKUP_UID) { + Backup::AppRadar::GetInstance().RecordBackUpFuncResWithoutBundle("BackupExtExtension::VerifyCaller", + AppRadar::GetInstance().GetUserId(), BizStage::BIZ_STAGE_PERMISSION_CHECK, + static_cast(BError::Codes::SA_REFUSED_ACT), + "{\"reason\":\"Calling uid invalid\"}"); throw BError(BError::Codes::EXT_BROKEN_IPC, string("Calling uid is invalid, calling uid is ").append(to_string(IPCSkeleton::GetCallingUid()))); } @@ -826,7 +835,13 @@ void BackupExtExtension::AsyncTaskBackup(const string config) HILOGI("Do backup, start fwk timer end."); BJsonCachedEntity cachedEntity(config); auto cache = cachedEntity.Structuralize(); + auto start = std::chrono::system_clock::now(); auto ret = ptr->DoBackup(cache); + auto end = std::chrono::system_clock::now(); + auto exportDuration = std::chrono::duration_cast(end - start); + Backup::AppRadar::GetInstance().RecordDoBackUpRes("BackupExtExtension::AsyncTaskBackup", + AppRadar::GetInstance().GetUserId(), static_cast(ret), + static_cast(exportDuration.count())); // REM: 处理返回结果 ret ptr->AppDone(ret); HILOGI("backup app done %{public}d", ret); @@ -1150,6 +1165,16 @@ void BackupExtExtension::HandleSpecialVersionRestore() } } +void RecordDoRestoreRes(const std::string &bundleName, const std::string &func, int32_t ms, int32_t fileNum, + int32_t fileSize) +{ + std::stringstream ss; + ss << "\"file_count\": \"" << fileNum << "\", \"file_size\": \"" << fileSize + << "\", \"spend_time\": \"" << ms << "ms\""; + AppRadar::GetInstance().RecordRestoreFuncResWithStatus(bundleName, AppRadar::GetInstance().GetUserId(), + func, BizStageRestore::BIZ_STAGE_DO_RESTORE, ss.str(), static_cast(BError::Codes::OK)); +} + void BackupExtExtension::AsyncTaskRestore(std::set fileSet, const std::vector extManageInfo) { @@ -1159,6 +1184,7 @@ void BackupExtExtension::AsyncTaskRestore(std::set fileSet, BExcepUltils::BAssert(ptr->extension_, BError::Codes::EXT_INVAL_ARG, "Extension handle have been released"); try { int ret = ERR_OK; + auto startTime = std::chrono::system_clock::now(); if (ptr->extension_->SpecialVersionForCloneAndCloud()) { ptr->HandleSpecialVersionRestore(); return; @@ -1176,6 +1202,11 @@ void BackupExtExtension::AsyncTaskRestore(std::set fileSet, ptr->extension_->UseFullBackupOnly() && !ptr->extension_->SpecialVersionForCloneAndCloud(); ptr->RestoreBigFiles(appendTargetPath); ptr->DeleteBackupTars(); + + auto endTime = std::chrono::system_clock::now(); + auto ms = std::chrono::duration_cast(endTime-startTime).count(); + RecordDoRestoreRes("bundlename", "AsyncTaskRestore", static_cast(ms), + static_cast(fileSet.size()), 0); if (ret == ERR_OK) { ptr->AsyncTaskRestoreForUpgrade(); } else { @@ -1215,6 +1246,9 @@ void BackupExtExtension::AsyncTaskIncrementalRestore() ptr->CheckTmpDirFileInfos(); } // 解压 + auto startTime = std::chrono::system_clock::now(); + int32_t fileSize = 0; + int32_t fileNum = 0; int ret = ptr->DoIncrementalRestore(); // 恢复用户tar包以及大文件 // 目的地址是否需要拼接path(临时目录),FullBackupOnly为true并且非特殊场景 @@ -1224,6 +1258,10 @@ void BackupExtExtension::AsyncTaskIncrementalRestore() // delete 1.tar/manage.json ptr->DeleteBackupIncrementalTars(); + auto endTime = std::chrono::system_clock::now(); + auto ms = std::chrono::duration_cast(endTime-startTime).count(); + RecordDoRestoreRes("bundlename", "AsyncTaskIncrementalRestore", + static_cast(ms), fileNum, fileSize); if (ptr != nullptr && ptr->isDebug_) { ptr->CheckRestoreFileInfos(); } @@ -1317,6 +1355,7 @@ void BackupExtExtension::AsyncTaskRestoreForUpgrade() ptr->StartOnProcessTaskThread(obj, BackupRestoreScenario::FULL_RESTORE); auto callBackup = ptr->OnRestoreCallback(obj); auto callBackupEx = ptr->OnRestoreExCallback(obj); + g_onRestoreStart = std::chrono::system_clock::now(); ErrCode err = ptr->extension_->OnRestore(callBackup, callBackupEx); if (err != ERR_OK) { ptr->AppDone(BError::GetCodeByErrno(err)); @@ -1367,6 +1406,7 @@ void BackupExtExtension::AsyncTaskIncrementalRestoreForUpgrade() ptr->StartOnProcessTaskThread(obj, BackupRestoreScenario::INCREMENTAL_RESTORE); auto callBackup = ptr->IncreOnRestoreCallback(obj); auto callBackupEx = ptr->IncreOnRestoreExCallback(obj); + g_onRestoreStart = std::chrono::system_clock::now(); ErrCode err = ptr->extension_->OnRestore(callBackup, callBackupEx); if (err != ERR_OK) { HILOGE("OnRestore done, err = %{pubilc}d", err); @@ -1494,6 +1534,7 @@ void BackupExtExtension::AsyncTaskOnBackup() ptr->StartOnProcessTaskThread(obj, BackupRestoreScenario::FULL_BACKUP); auto callBackup = ptr->OnBackupCallback(obj); auto callBackupEx = ptr->OnBackupExCallback(obj); + g_onBackUpStart = std::chrono::system_clock::now(); ErrCode err = ptr->extension_->OnBackup(callBackup, callBackupEx); if (err != ERR_OK) { HILOGE("OnBackup done, err = %{pubilc}d", err); @@ -1879,6 +1920,7 @@ void BackupExtExtension::AsyncTaskOnIncrementalBackup() ptr->StartOnProcessTaskThread(obj, BackupRestoreScenario::INCREMENTAL_BACKUP); auto callBackup = ptr->IncOnBackupCallback(obj); auto callBackupEx = ptr->IncOnBackupExCallback(obj); + g_onBackUpStart = std::chrono::system_clock::now(); ErrCode err = ptr->extension_->OnBackup(callBackup, callBackupEx); if (err != ERR_OK) { HILOGE("OnBackup done, err = %{pubilc}d", err); diff --git a/frameworks/native/backup_ext/src/sub_ext_extension.cpp b/frameworks/native/backup_ext/src/sub_ext_extension.cpp index 55ed437d3..b4f63b222 100644 --- a/frameworks/native/backup_ext/src/sub_ext_extension.cpp +++ b/frameworks/native/backup_ext/src/sub_ext_extension.cpp @@ -47,6 +47,7 @@ #include "b_json/b_json_cached_entity.h" #include "b_jsonutil/b_jsonutil.h" #include "b_ohos/startup/backup_para.h" +#include "b_radar/b_radar.h" #include "b_tarball/b_tarball_factory.h" #include "filemgmt_libhilog.h" #include "hitrace_meter.h" @@ -249,6 +250,14 @@ std::function BackupExtExtension::OnRestoreCallback( return; } HILOGI("Current bundle will execute app done"); + if (errCode == ERR_OK) { + auto endTime = std::chrono::system_clock::now(); + auto ms = std::chrono::duration_cast(endTime - g_onRestoreStart).count(); + std::stringstream ss; + ss << "\"spend_time\": \"" << ms << "ms\""; + AppRadar::GetInstance().RecordOnRestoreRes("bundlename", AppRadar::GetInstance().GetUserId(), + "BackupExtExtension::OnRestoreCallback", ss.str(), ERR_OK); + } extensionPtr->FinishOnProcessTask(); if (errMsg.empty()) { extensionPtr->AppDone(errCode); @@ -274,6 +283,14 @@ std::function BackupExtExtension::OnRestoreExCallbac HILOGE("Extension handle have been released"); return; } + if (errCode == ERR_OK && !restoreRetInfo.empty()) { + auto endTime = std::chrono::system_clock::now(); + auto ms = std::chrono::duration_cast(endTime - g_onRestoreStart).count(); + std::stringstream ss; + ss << "\"spend_time\": \"" << ms << "ms\""; + AppRadar::GetInstance().RecordOnRestoreRes("bundlename", AppRadar::GetInstance().GetUserId(), + "OnRestoreExCallback", ss.str(), ERR_OK); + } extensionPtr->FinishOnProcessTask(); extensionPtr->extension_->InvokeAppExtMethod(errCode, restoreRetInfo); if (errCode == ERR_OK) { @@ -324,6 +341,14 @@ std::function BackupExtExtension::IncreOnRestoreExCa HILOGE("Extension handle have been released"); return; } + if (errCode == ERR_OK && !restoreRetInfo.empty()) { + auto endTime = std::chrono::system_clock::now(); + auto ms = std::chrono::duration_cast(endTime - g_onRestoreStart).count(); + std::stringstream ss; + ss << "\"spend_time\": \"" << ms << "ms\""; + AppRadar::GetInstance().RecordOnRestoreRes("bundlename", AppRadar::GetInstance().GetUserId(), + "IncreOnRestoreExCallback", ss.str(), ERR_OK); + } extensionPtr->FinishOnProcessTask(); extensionPtr->extension_->InvokeAppExtMethod(errCode, restoreRetInfo); if (errCode == ERR_OK) { @@ -353,6 +378,14 @@ std::function BackupExtExtension::IncreOnRestoreCall return; } HILOGI("Current bundle will execute app done"); + if (errCode == ERR_OK) { + auto endTime = std::chrono::system_clock::now(); + auto ms = std::chrono::duration_cast(endTime - g_onRestoreStart).count(); + std::stringstream ss; + ss << "\"spend_time\": \"" << ms << "ms\""; + AppRadar::GetInstance().RecordOnRestoreRes("bundlename", AppRadar::GetInstance().GetUserId(), + "IncreOnRestoreCallback", ss.str(), ERR_OK); + } extensionPtr->FinishOnProcessTask(); if (errMsg.empty()) { extensionPtr->AppIncrementalDone(errCode); @@ -379,6 +412,13 @@ std::function BackupExtExtension::OnBackupCall HILOGE("Extension handle have been released"); return; } + if (errCode == ERR_OK) { + auto onBackUpEnd = std::chrono::system_clock::now(); + auto ms = std::chrono::duration_cast(onBackUpEnd - g_onBackUpStart).count(); + AppRadar::GetInstance().RecordBackUpFuncResWithBundle("BackupExtExtension::OnBackupCallback", + "bundleName", AppRadar::GetInstance().GetUserId(), BizStage::BIZ_STAGE_ON_BACKUP, 0, + string("{\"spend_time\":\" ").append(to_string(ms)).append(string("ms\"}"))); + } extensionPtr->FinishOnProcessTask(); extensionPtr->AsyncTaskBackup(extensionPtr->extension_->GetUsrConfig()); }; @@ -398,6 +438,13 @@ std::function BackupExtExtension::OnBackupExCa HILOGE("Extension handle have been released"); return; } + if (errCode == ERR_OK && !backupExRetInfo.empty()) { + auto onBackUpEnd = std::chrono::system_clock::now(); + auto ms = std::chrono::duration_cast(onBackUpEnd - g_onBackUpStart).count(); + AppRadar::GetInstance().RecordBackUpFuncResWithBundle("BackupExtExtension::OnBackupExCallback", + "bundleName", AppRadar::GetInstance().GetUserId(), BizStage::BIZ_STAGE_ON_BACKUP, 0, + string("{\"spend_time\":\" ").append(to_string(ms)).append(string("ms\"}"))); + } extensionPtr->extension_->InvokeAppExtMethod(errCode, backupExRetInfo); if (backupExRetInfo.size()) { HILOGI("Will notify backup result report"); @@ -423,6 +470,13 @@ std::function BackupExtExtension::IncOnBackupC return; } HILOGI("Start GetAppLocalListAndDoIncrementalBackup"); + if (errCode == ERR_OK) { + auto onBackUpEnd = std::chrono::system_clock::now(); + auto ms = std::chrono::duration_cast(onBackUpEnd - g_onBackUpStart).count(); + AppRadar::GetInstance().RecordBackUpFuncResWithBundle("BackupExtExtension::IncOnBackupCallback", + "bundleName", AppRadar::GetInstance().GetUserId(), BizStage::BIZ_STAGE_ON_BACKUP, 0, + string("{\"spend_time\":\" ").append(to_string(ms)).append(string("ms\"}"))); + } extPtr->FinishOnProcessTask(); proxy->GetAppLocalListAndDoIncrementalBackup(); }; @@ -445,6 +499,13 @@ std::function BackupExtExtension::IncOnBackupE HILOGE("Extension handle have been released"); return; } + if (errCode == ERR_OK && !backupExRetInfo.empty()) { + auto onBackUpEnd = std::chrono::system_clock::now(); + auto ms = std::chrono::duration_cast(onBackUpEnd - g_onBackUpStart).count(); + AppRadar::GetInstance().RecordBackUpFuncResWithBundle("BackupExtExtension::IncOnBackupExCallback", + "bundleName", AppRadar::GetInstance().GetUserId(), BizStage::BIZ_STAGE_ON_BACKUP, 0, + string("{\"spend_time\":\" ").append(to_string(ms)).append(string("ms\"}"))); + } extensionPtr->extension_->InvokeAppExtMethod(errCode, backupExRetInfo); if (backupExRetInfo.size()) { HILOGI("Start GetAppLocalListAndDoIncrementalBackup"); 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 f747d28c7..ade0f0864 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 @@ -16,6 +16,7 @@ #include "b_incremental_backup_session.h" #include "b_error/b_error.h" +#include "b_radar/b_radar.h" #include "filemgmt_libhilog.h" #include "service_proxy.h" #include "service_reverse.h" @@ -55,6 +56,8 @@ 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); + Backup::AppRadar::GetInstance().RecordBackUpFuncResWithoutBundle("BIncrementalBackupSession::Init", + AppRadar::GetInstance().GetUserId(), BizStage::BIZ_STAGE_CREATE_SESSION_BACKUP, res); return nullptr; } @@ -93,7 +96,16 @@ ErrCode BIncrementalBackupSession::AppendBundles(vector bundle return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } - return proxy->AppendBundlesIncrementalBackupSession(bundlesToBackup); + int32_t res = proxy->AppendBundlesIncrementalBackupSession(bundlesToBackup); + if (res != 0) { + std::string ss; + for (const auto &bundle:bundlesToBackup) { + ss += bundle.bundleName + ", "; + } + Backup::AppRadar::GetInstance().RecordBackUpFuncResWithBundle("BIncrementalBackupSession::AppendBundles", + ss.c_str(), AppRadar::GetInstance().GetUserId(), BizStage::BIZ_STAGE_APPEND_BUNDLES, res); + } + return res; } ErrCode BIncrementalBackupSession::AppendBundles(vector bundlesToBackup, @@ -104,7 +116,16 @@ ErrCode BIncrementalBackupSession::AppendBundles(vector bundle return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } - return proxy->AppendBundlesIncrementalBackupSession(bundlesToBackup, infos); + int32_t res = proxy->AppendBundlesIncrementalBackupSession(bundlesToBackup, infos); + if (res != 0) { + std::string ss; + for (const auto &bundle:bundlesToBackup) { + ss += bundle.bundleName + ", "; + } + Backup::AppRadar::GetInstance().RecordBackUpFuncResWithBundle("BIncrementalBackupSession::AppendBundles", + ss.c_str(), AppRadar::GetInstance().GetUserId(), BizStage::BIZ_STAGE_APPEND_BUNDLES, res); + } + return res; } ErrCode BIncrementalBackupSession::Release() 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 000241ad0..b2a7041f5 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 @@ -16,6 +16,7 @@ #include "b_incremental_restore_session.h" #include "b_error/b_error.h" +#include "b_radar/b_radar.h" #include "filemgmt_libhilog.h" #include "service_proxy.h" #include "service_reverse.h" @@ -54,6 +55,9 @@ 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::GetInstance().RecordRestoreFuncRes(AppRadar::GetInstance().GetUserId(), + "BIncrementalRestoreSession::Init", + BizStageRestore::BIZ_STAGE_CREATE_SESSION_RESTORE, res); return nullptr; } 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 84f75d66e..f6008298e 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 @@ -16,6 +16,7 @@ #include "b_incremental_session_restore_async.h" #include "b_error/b_error.h" +#include "b_radar/b_radar.h" #include "b_resources/b_constants.h" #include "filemgmt_libhilog.h" #include "service_proxy.h" @@ -62,6 +63,9 @@ 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::GetInstance().RecordRestoreFuncRes(AppRadar::GetInstance().GetUserId(), + "BIncrementalSessionRestoreAsync::Init", + BizStageRestore::BIZ_STAGE_CREATE_SESSION_RESTORE, res); return nullptr; } 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 04176686b..b0f55c78b 100644 --- a/frameworks/native/backup_kit_inner/src/b_session_backup.cpp +++ b/frameworks/native/backup_kit_inner/src/b_session_backup.cpp @@ -16,6 +16,7 @@ #include "b_session_backup.h" #include "b_error/b_error.h" +#include "b_radar/b_radar.h" #include "filemgmt_libhilog.h" #include "service_proxy.h" #include "service_reverse.h" @@ -55,6 +56,8 @@ 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); + Backup::AppRadar::GetInstance().RecordBackUpFuncResWithoutBundle("BSessionBackup::Init", + AppRadar::GetInstance().GetUserId(), BizStage::BIZ_STAGE_CREATE_SESSION_BACKUP, res); return nullptr; } @@ -103,7 +106,16 @@ ErrCode BSessionBackup::AppendBundles(vector bundlesToBackup) return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } - return proxy->AppendBundlesBackupSession(bundlesToBackup); + int32_t res = proxy->AppendBundlesBackupSession(bundlesToBackup); + if (res != 0) { + std::string ss; + for (const auto &bundleName:bundlesToBackup) { + ss += bundleName + ", "; + } + Backup::AppRadar::GetInstance().RecordBackUpFuncResWithBundle("BSessionBackup::AppendBundles", + ss.c_str(), AppRadar::GetInstance().GetUserId(), BizStage::BIZ_STAGE_APPEND_BUNDLES, res); + } + return res; } ErrCode BSessionBackup::AppendBundles(vector bundlesToBackup, vector detailInfos) @@ -113,7 +125,16 @@ ErrCode BSessionBackup::AppendBundles(vector bundlesToBackup, vector return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } - return proxy->AppendBundlesDetailsBackupSession(bundlesToBackup, detailInfos); + int32_t res = proxy->AppendBundlesDetailsBackupSession(bundlesToBackup, detailInfos); + if (res != 0) { + std::string ss; + for (const auto &bundleName:bundlesToBackup) { + ss += bundleName + ", "; + } + Backup::AppRadar::GetInstance().RecordBackUpFuncResWithBundle("BSessionBackup::AppendBundles", + ss.c_str(), AppRadar::GetInstance().GetUserId(), BizStage::BIZ_STAGE_APPEND_BUNDLES, res); + } + return res; } ErrCode BSessionBackup::Finish() 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 250d68bc7..ec2c95bb7 100644 --- a/frameworks/native/backup_kit_inner/src/b_session_restore.cpp +++ b/frameworks/native/backup_kit_inner/src/b_session_restore.cpp @@ -16,6 +16,7 @@ #include "b_session_restore.h" #include "b_error/b_error.h" +#include "b_radar/b_radar.h" #include "filemgmt_libhilog.h" #include "service_proxy.h" #include "service_reverse.h" @@ -54,6 +55,8 @@ 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::GetInstance().RecordRestoreFuncRes(AppRadar::GetInstance().GetUserId(), "BSessionRestore::Init", + BizStageRestore::BIZ_STAGE_CREATE_SESSION_RESTORE, res); return nullptr; } 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 0e86b3df7..52177d113 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 @@ -16,6 +16,7 @@ #include "b_session_restore_async.h" #include "b_error/b_error.h" +#include "b_radar/b_radar.h" #include "b_resources/b_constants.h" #include "b_session_restore.h" #include "filemgmt_libhilog.h" @@ -63,6 +64,9 @@ 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::GetInstance().RecordRestoreFuncRes(AppRadar::GetInstance().GetUserId(), + "BSessionRestoreAsync::Init", + BizStageRestore::BIZ_STAGE_CREATE_SESSION_RESTORE, res); return nullptr; } diff --git a/frameworks/native/backup_kit_inner/src/service_proxy.cpp b/frameworks/native/backup_kit_inner/src/service_proxy.cpp index 1870448e3..cf818b94e 100644 --- a/frameworks/native/backup_kit_inner/src/service_proxy.cpp +++ b/frameworks/native/backup_kit_inner/src/service_proxy.cpp @@ -15,11 +15,14 @@ #include "service_proxy.h" +#include + #include "iservice_registry.h" #include "system_ability_definition.h" #include "b_error/b_error.h" #include "b_error/b_excep_utils.h" +#include "b_radar/b_radar.h" #include "b_resources/b_constants.h" #include "filemgmt_libhilog.h" #include "svc_death_recipient.h" @@ -446,6 +449,9 @@ sptr ServiceProxy::GetInstance() [loadCallback]() { return loadCallback->isLoadSuccess_.load(); }); if (!waitStatus) { HILOGE("Load backup sa timeout"); + Backup::AppRadar::GetInstance().RecordBackUpFuncResWithoutBundle("ServiceProxy::GetInstance", + AppRadar::GetInstance().GetUserId(), BizStage::BIZ_STAGE_BACKUP_SA, + static_cast(BError::Codes::SA_INVAL_ARG), "{\"reason\":\"Load backup sa timeout\"}"); return nullptr; } return serviceProxy_; @@ -481,6 +487,10 @@ void ServiceProxy::ServiceProxyLoadCallback::OnLoadSystemAbilitySuccess(int32_t HILOGE("Failed to get remote object"); serviceProxy_ = nullptr; isLoadSuccess_.store(false); + Backup::AppRadar::GetInstance().RecordBackUpFuncResWithoutBundle( + "ServiceProxyLoadCallback::OnLoadSystemAbilitySuccess", + AppRadar::GetInstance().GetUserId(), BizStage::BIZ_STAGE_BACKUP_SA, + static_cast(BError::Codes::SA_INVAL_ARG), "{\"reason\":\"Load backup sa fail\"}"); proxyConVar_.notify_one(); return; } @@ -499,6 +509,10 @@ void ServiceProxy::ServiceProxyLoadCallback::OnLoadSystemAbilityFail(int32_t sys { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); HILOGE("Load backup sa failed, systemAbilityId:%{private}d", systemAbilityId); + std::stringstream ss; + ss << "\"reason\": \"Load backup sa failed\", \"system_ability_id\": \"" << systemAbilityId << "\""; + AppRadar::GetInstance().RecordBackupSARes(AppRadar::GetInstance().GetUserId(), "ServiceProxy::GetInstance", + static_cast(BError::Codes::EXT_BROKEN_IPC), ss.str()); unique_lock lock(proxyMutex_); serviceProxy_ = nullptr; isLoadSuccess_.store(false); diff --git a/interfaces/inner_api/native/backup_kit_inner/BUILD.gn b/interfaces/inner_api/native/backup_kit_inner/BUILD.gn index c84d227f2..2ee1a876d 100644 --- a/interfaces/inner_api/native/backup_kit_inner/BUILD.gn +++ b/interfaces/inner_api/native/backup_kit_inner/BUILD.gn @@ -27,6 +27,7 @@ config("private_config") { "${path_backup}/frameworks/native/backup_kit_inner/include", "${path_backup}/interfaces/inner_api/native/backup_kit_inner", "${path_backup}/interfaces/inner_api/native/backup_kit_inner/impl", + "${path_backup}/utils/include", ] } diff --git a/services/backup_sa/include/module_ipc/service.h b/services/backup_sa/include/module_ipc/service.h index fa1da2e93..78ed2c935 100644 --- a/services/backup_sa/include/module_ipc/service.h +++ b/services/backup_sa/include/module_ipc/service.h @@ -91,6 +91,9 @@ public: void OnStop() override; void StopAll(const wptr &obj, bool force = false); int Dump(int fd, const std::vector &args) override; + void PermissionCheckFailRadar(const std::string &info); + void GetLocalCapabilitiesRadar(const std::string &func, int32_t resultCode, + const std::string &info); /** * @brief 执行启动 backup extension 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 f49ed5bd3..c60236c02 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 @@ -17,6 +17,7 @@ #include +#include "b_radar/b_radar.h" #include "message_parcel.h" #include "want.h" @@ -85,6 +86,35 @@ DisposeErr AppGalleryDisposeProxy::EndRestore(const std::string &bundleName) return DoDispose(bundleName, DisposeOperation::END_RESTORE); } +void RecordDoDisposeRes(const std::string &bundleName, + AppGalleryDisposeProxy::DisposeOperation disposeOperation, int32_t err) +{ + switch (disposeOperation) { + case AppGalleryDisposeProxy::DisposeOperation::START_BACKUP: + AppRadar::GetInstance().RecordBackUpFuncResWithBundle("AppGalleryDisposeProxy::StartBackup", + bundleName, AppRadar::GetInstance().GetUserId(), + BizStage::BIZ_STAGE_APPLICATION, err); + break; + case AppGalleryDisposeProxy::DisposeOperation::END_BACKUP: + AppRadar::GetInstance().RecordBackUpFuncResWithBundle("AppGalleryDisposeProxy::EndBackup", + bundleName, AppRadar::GetInstance().GetUserId(), + BizStage::BIZ_STAGE_APPLICATION, err); + break; + case AppGalleryDisposeProxy::DisposeOperation::START_RESTORE: + AppRadar::GetInstance().RecordRestoreFuncResWithBundle(bundleName, AppRadar::GetInstance().GetUserId(), + "AppGalleryDisposeProxy::StartRestore", + BizStageRestore::BIZ_STAGE_STATUS_CLEAR, err); + break; + case AppGalleryDisposeProxy::DisposeOperation::END_RESTORE: + AppRadar::GetInstance().RecordRestoreFuncResWithBundle(bundleName, AppRadar::GetInstance().GetUserId(), + "AppGalleryDisposeProxy::EndRestore", + BizStageRestore::BIZ_STAGE_STATUS_CLEAR, err); + break; + default: + break; + } +} + DisposeErr AppGalleryDisposeProxy::DoDispose(const std::string &bundleName, DisposeOperation disposeOperation) { HILOGI("DoDispose, app %{public}s, operation %{public}d", bundleName.c_str(), disposeOperation); @@ -113,6 +143,7 @@ DisposeErr AppGalleryDisposeProxy::DoDispose(const std::string &bundleName, Disp MessageOption option(MessageOption::TF_ASYNC); int32_t ret = appRemoteObj_->SendRequest(static_cast(disposeOperation), data, reply, option); if (ret != ERR_NONE) { + RecordDoDisposeRes(bundleName, disposeOperation, ret); HILOGI("SendRequest error, code=%{public}d, bundleName=%{public}s", ret, bundleName.c_str()); return DisposeErr::REQUEST_FAIL; } diff --git a/services/backup_sa/src/module_ipc/service.cpp b/services/backup_sa/src/module_ipc/service.cpp index 6e834db31..fab10321c 100644 --- a/services/backup_sa/src/module_ipc/service.cpp +++ b/services/backup_sa/src/module_ipc/service.cpp @@ -47,6 +47,7 @@ #include "b_jsonutil/b_jsonutil.h" #include "b_ohos/startup/backup_para.h" #include "b_process/b_multiuser.h" +#include "b_radar/b_radar.h" #include "b_resources/b_constants.h" #include "b_sa/b_sa_utils.h" #include "bundle_mgr_client.h" @@ -138,6 +139,14 @@ void Service::OnStop() HILOGI("SA OnStop End."); } +void Service::GetLocalCapabilitiesRadar(const std::string &func, int32_t resultCode, + const std::string &info) +{ + std::string funcPos = "Service::"; + Backup::AppRadar::GetInstance().RecordBackUpFuncResWithoutBundle(funcPos.append(func), + GetUserIdDefault(), BizStage::BIZ_STAGE_GET_LOCAL_CAPABILITIES, resultCode, info); +} + UniqueFd Service::GetLocalCapabilities() { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); @@ -149,6 +158,7 @@ UniqueFd Service::GetLocalCapabilities() HILOGI("Begin"); if (session_ == nullptr) { HILOGE("GetLocalCapabilities error, session is empty."); + GetLocalCapabilitiesRadar("GetLocalCapabilities", EPERM, "{\"reason\":\"session empty\"}"); return UniqueFd(-EPERM); } session_->IncreaseSessionCnt(); @@ -160,6 +170,8 @@ UniqueFd Service::GetLocalCapabilities() if (fd < 0) { HILOGE("Failed to open config file = %{private}s, err = %{public}d", path.c_str(), errno); session_->DecreaseSessionCnt(); + GetLocalCapabilitiesRadar("GetLocalCapabilities", EPERM, + "{\"reason\":\"failed to open config file\"}"); return UniqueFd(-EPERM); } BJsonCachedEntity cachedEntity(std::move(fd)); @@ -177,14 +189,17 @@ UniqueFd Service::GetLocalCapabilities() } catch (const BError &e) { session_->DecreaseSessionCnt(); HILOGE("GetLocalCapabilities failed, errCode = %{public}d", e.GetCode()); + GetLocalCapabilitiesRadar("GetLocalCapabilities", e.GetCode(), "{\"reason\":\"failed\"}"); return UniqueFd(-e.GetCode()); } catch (const exception &e) { session_->DecreaseSessionCnt(); HILOGI("Catched an unexpected low-level exception %{public}s", e.what()); + GetLocalCapabilitiesRadar("GetLocalCapabilities", EPERM, "{\"reason\":\"exception\"}"); return UniqueFd(-EPERM); } catch (...) { session_->DecreaseSessionCnt(); HILOGI("Unexpected exception"); + GetLocalCapabilitiesRadar("GetLocalCapabilities", EPERM, "{\"reason\":\"exception\"}"); return UniqueFd(-EPERM); } } @@ -203,6 +218,10 @@ string Service::VerifyCallerAndGetCallerName() if (tokenType == Security::AccessToken::ATokenTypeEnum::TOKEN_HAP) { Security::AccessToken::HapTokenInfo hapTokenInfo; if (Security::AccessToken::AccessTokenKit::GetHapTokenInfo(tokenCaller, hapTokenInfo) != 0) { + Backup::AppRadar::GetInstance().RecordBackUpFuncResWithoutBundle("Service::VerifyCallerAndGetCallerName", + GetUserIdDefault(), BizStage::BIZ_STAGE_PERMISSION_CHECK, + static_cast(BError::Codes::SA_REFUSED_ACT), + "{\"reason\":\"Get hap token info failed\"}"); throw BError(BError::Codes::SA_INVAL_ARG, "Get hap token info failed"); } std::string bundleNameIndexInfo = BJsonUtil::BuildBundleNameIndexInfo(hapTokenInfo.bundleName, @@ -212,10 +231,21 @@ string Service::VerifyCallerAndGetCallerName() } else { string str = to_string(tokenCaller); HILOGE("tokenID = %{private}s", GetAnonyString(str).c_str()); + Backup::AppRadar::GetInstance().RecordBackUpFuncResWithoutBundle("Service::VerifyCallerAndGetCallerName", + GetUserIdDefault(), BizStage::BIZ_STAGE_PERMISSION_CHECK, + static_cast(BError::Codes::SA_REFUSED_ACT), + string("{\"reason\":\"Invalid token type ").append(to_string(tokenType)).append(string("\"}"))); throw BError(BError::Codes::SA_INVAL_ARG, string("Invalid token type ").append(to_string(tokenType))); } } +void Service::PermissionCheckFailRadar(const std::string &info) +{ + Backup::AppRadar::GetInstance().RecordBackUpFuncResWithoutBundle("Service::VerifyCaller", + GetUserIdDefault(), BizStage::BIZ_STAGE_PERMISSION_CHECK, + static_cast(BError::Codes::SA_REFUSED_ACT), info); +} + void Service::VerifyCaller() { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); @@ -225,6 +255,8 @@ void Service::VerifyCaller() case Security::AccessToken::ATokenTypeEnum::TOKEN_NATIVE: { /* Update Service */ if (Security::AccessToken::AccessTokenKit::VerifyAccessToken(tokenCaller, BACKUP_PERMISSION) != Security::AccessToken::PermissionState::PERMISSION_GRANTED) { + std::string info = "{\"reason\":\"Permission denied, token type is " + to_string(tokenType) + "\"}"; + PermissionCheckFailRadar(info); throw BError(BError::Codes::SA_REFUSED_ACT, string("Permission denied, token type is ").append(to_string(tokenType))); } @@ -233,11 +265,15 @@ void Service::VerifyCaller() case Security::AccessToken::ATokenTypeEnum::TOKEN_HAP: { if (Security::AccessToken::AccessTokenKit::VerifyAccessToken(tokenCaller, BACKUP_PERMISSION) != Security::AccessToken::PermissionState::PERMISSION_GRANTED) { + std::string info = "{\"reason\":\"Permission denied, token type is " + to_string(tokenType) + "\"}"; + PermissionCheckFailRadar(info); throw BError(BError::Codes::SA_REFUSED_ACT, string("Permission denied, token type is ").append(to_string(tokenType))); } uint64_t fullTokenId = OHOS::IPCSkeleton::GetCallingFullTokenID(); if (!Security::AccessToken::TokenIdKit::IsSystemAppByFullTokenID(fullTokenId)) { + std::string info = "{\"reason\":\"Permission denied, token type is " + to_string(tokenType) + "\"}"; + PermissionCheckFailRadar(info); throw BError(BError::Codes::SA_REFUSED_ACT, string("Permission denied, token type is ").append(to_string(tokenType))); } @@ -245,10 +281,14 @@ void Service::VerifyCaller() } case Security::AccessToken::ATokenTypeEnum::TOKEN_SHELL: if (IPCSkeleton::GetCallingUid() != BConstants::SYSTEM_UID) { + std::string info = "{\"reason\":\"invalid calling uid\"}"; + PermissionCheckFailRadar(info); throw BError(BError::Codes::SA_REFUSED_ACT, "Calling uid is invalid"); } break; default: + std::string info = "{\"reason\":\"Permission denied, token type is " + to_string(tokenType) + "\"}"; + PermissionCheckFailRadar(info); throw BError(BError::Codes::SA_REFUSED_ACT, string("Invalid token type ").append(to_string(tokenType))); break; } @@ -446,6 +486,9 @@ ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, const vectorDecreaseSessionCnt(); return e.GetCode(); @@ -511,6 +554,9 @@ ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, return BError(BError::Codes::OK); } catch (const BError &e) { HILOGE("Catch exception"); + AppRadar::GetInstance().RecordRestoreFuncResWithBundle("bundlename", GetUserIdDefault(), + "Service::AppendBundlesRestoreSession", + BizStageRestore::BIZ_STAGE_APPEND_BUNDLES, e.GetCode()); HandleExceptionOnAppendBundles(session_, bundleNames, {}); session_->DecreaseSessionCnt(); return e.GetCode(); @@ -930,6 +976,9 @@ ErrCode Service::LaunchBackupExtension(const BundleName &bundleName) } return BError(BError::Codes::OK); } catch (const BError &e) { + AppRadar::GetInstance().RecordGetFileHandleRes(bundleName, GetUserIdDefault(), + static_cast(e.GetCode()), + "{\"reason\":\"catch error\"}"); return e.GetCode(); } catch (const exception &e) { HILOGI("Catched an unexpected low-level exception %{public}s", e.what()); @@ -975,11 +1024,17 @@ ErrCode Service::GetFileHandle(const string &bundleName, const string &fileName) auto backUpConnection = session_->GetExtConnection(bundleName); if (backUpConnection == nullptr) { HILOGE("GetFileHandle error, backUpConnection is empty"); + AppRadar::GetInstance().RecordGetFileHandleRes(bundleName, GetUserIdDefault(), + static_cast(BError::Codes::SA_INVAL_ARG), + "{\"reason\":\"backUpConnection is empty\"}"); return BError(BError::Codes::SA_INVAL_ARG); } auto proxy = backUpConnection->GetBackupExtProxy(); if (!proxy) { HILOGE("GetFileHandle error, Extension backup Proxy is empty"); + AppRadar::GetInstance().RecordGetFileHandleRes(bundleName, GetUserIdDefault(), + static_cast(BError::Codes::SA_INVAL_ARG), + "{\"reason\":\"Extension backup Proxy is empty\"}"); return BError(BError::Codes::SA_INVAL_ARG); } int32_t errCode = 0; @@ -1003,6 +1058,14 @@ ErrCode Service::GetFileHandle(const string &bundleName, const string &fileName) void Service::OnBackupExtensionDied(const string &&bundleName) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + int32_t errCode = static_cast(BError::Codes::EXT_ABILITY_DIED); + if (session_->GetScenario() == IServiceReverse::Scenario::BACKUP) { + Backup::AppRadar::GetInstance().RecordBackUpFuncResWithBundle("Service::OnBackupExtensionDied", + bundleName, GetUserIdDefault(), BizStage::BIZ_STAGE_EXTENSION_STATUS, errCode); + } else if (session_->GetScenario() == IServiceReverse::Scenario::RESTORE) { + AppRadar::GetInstance().RecordRestoreFuncResWithBundle(bundleName, GetUserIdDefault(), "OnBackupExtensionDied", + BizStageRestore::BIZ_STAGE_EXTENSION_STATUS, errCode); + } try { string callName = move(bundleName); HILOGE("Backup <%{public}s> Extension Process Died", callName.c_str()); @@ -1136,6 +1199,13 @@ void Service::ExtConnectFailed(const string &bundleName, ErrCode ret) try { HILOGE("begin %{public}s", bundleName.data()); IServiceReverse::Scenario scenario = session_->GetScenario(); + if (scenario == IServiceReverse::Scenario::BACKUP) { + Backup::AppRadar::GetInstance().RecordBackUpFuncResWithBundle("Service::ExtConnectFailed", + bundleName, GetUserIdDefault(), BizStage::BIZ_STAGE_APPLICATION, ret); + } else if (scenario == IServiceReverse::Scenario::RESTORE) { + AppRadar::GetInstance().RecordRestoreFuncResWithBundle(bundleName, GetUserIdDefault(), + "Service::ExtConnectFailed", BizStageRestore::BIZ_STAGE_CONNECT_BACKUP_EXTENSION, ret); + } if (scenario == IServiceReverse::Scenario::BACKUP && session_->GetIsIncrementalBackup()) { session_->GetServiceReverseProxy()->IncrementalBackupOnBundleStarted(ret, bundleName); } else if (scenario == IServiceReverse::Scenario::RESTORE && @@ -1425,6 +1495,16 @@ void Service::UnloadService() void Service::SessionDeactive() { + IServiceReverse::Scenario scenario = session_->GetScenario(); + if (scenario == IServiceReverse::Scenario::BACKUP) { + AppRadar::GetInstance().RecordBackUpFuncResWithoutBundle("Service::SessionDeactive", + AppRadar::GetInstance().GetUserId(), BizStage::BIZ_STAGE_CLIENT_STATUS, + static_cast(BError::Codes::SA_BROKEN_IPC), "cloud_clone"); + } else if (scenario == IServiceReverse::Scenario::RESTORE) { + AppRadar::GetInstance().RecordRestoreFuncRes(AppRadar::GetInstance().GetUserId(), + "Service::SessionDeactive", BizStageRestore::BIZ_STAGE_CLIENT_STATUS, + static_cast(BError::Codes::SA_BROKEN_IPC)); + } HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); try { HILOGI("Begin"); @@ -1520,6 +1600,8 @@ ErrCode Service::GetBackupInfoCmdHandle(BundleName &bundleName, std::string &res backupConnection->DisconnectBackupExtAbility(); if (ret != ERR_OK) { HILOGE("Call Ext GetBackupInfo faild."); + Backup::AppRadar::GetInstance().RecordBackUpFuncResWithBundle("Service::GetBackupInfoCmdHandle", + bundleName, GetUserIdDefault(), BizStage::BIZ_STAGE_GET_BACKUP_INFO, ret); return BError(BError::Codes::SA_INVAL_ARG); } @@ -1828,6 +1910,15 @@ std::function Service::TimeOutCallback(wptr ptr, std::string bu HILOGE("SessionPtr is nullptr."); return; } + IServiceReverse::Scenario scenario = sessionPtr->GetScenario(); + int32_t errCode = static_cast(BError::Codes::EXT_ABILITY_TIMEOUT); + if (scenario == IServiceReverse::Scenario::BACKUP) { + AppRadar::GetInstance().RecordBackUpFuncResWithBundle("TimeOutCallback", bundleName, GetUserIdDefault(), + BizStage::BIZ_STAGE_ON_BACKUP, errCode); + } else if (scenario == IServiceReverse::Scenario::RESTORE) { + AppRadar::GetInstance().RecordRestoreFuncResWithBundle(bundleName, GetUserIdDefault(), "TimeOutCallback", + BizStageRestore::BIZ_STAGE_EXEC_ON_RESTORE, errCode); + } try { if (SAUtils::IsSABundleName(bundleName)) { auto sessionConnection = sessionPtr->GetSAExtConnection(bundleName); diff --git a/services/backup_sa/src/module_ipc/service_incremental.cpp b/services/backup_sa/src/module_ipc/service_incremental.cpp index deb63ff3c..0f5f29345 100644 --- a/services/backup_sa/src/module_ipc/service_incremental.cpp +++ b/services/backup_sa/src/module_ipc/service_incremental.cpp @@ -38,6 +38,7 @@ #include "b_json/b_json_entity_caps.h" #include "b_ohos/startup/backup_para.h" #include "b_process/b_multiuser.h" +#include "b_radar/b_radar.h" #include "b_resources/b_constants.h" #include "b_sa/b_sa_utils.h" #include "filemgmt_libhilog.h" @@ -95,6 +96,7 @@ UniqueFd Service::GetLocalCapabilitiesIncremental(const std::vectorIncreaseSessionCnt(); @@ -106,6 +108,7 @@ UniqueFd Service::GetLocalCapabilitiesIncremental(const std::vectorDecreaseSessionCnt(); + GetLocalCapabilitiesRadar("GetLocalCapabilitiesIncremental", ENOENT, "{\"reason\":\"open file failed\"}"); return UniqueFd(-ENOENT); } BJsonCachedEntity cachedEntity(move(fd)); @@ -123,14 +126,17 @@ UniqueFd Service::GetLocalCapabilitiesIncremental(const std::vectorDecreaseSessionCnt(); HILOGE("GetLocalCapabilitiesIncremental failed, errCode = %{public}d", e.GetCode()); + GetLocalCapabilitiesRadar("GetLocalCapabilitiesIncremental", e.GetCode(), "{\"reason\":\"fail\"}"); return UniqueFd(-e.GetCode()); } catch (const exception &e) { session_->DecreaseSessionCnt(); HILOGI("Catched an unexpected low-level exception %{public}s", e.what()); + GetLocalCapabilitiesRadar("GetLocalCapabilitiesIncremental", EPERM, "{\"reason\":\"exception\"}"); return UniqueFd(-EPERM); } catch (...) { session_->DecreaseSessionCnt(); HILOGI("Unexpected exception"); + GetLocalCapabilitiesRadar("GetLocalCapabilitiesIncremental", EPERM, "{\"reason\":\"exception\"}"); return UniqueFd(-EPERM); } } 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 4ad667a9f..d22b1a5e8 100644 --- a/services/backup_sa/src/module_ipc/svc_session_manager.cpp +++ b/services/backup_sa/src/module_ipc/svc_session_manager.cpp @@ -26,6 +26,7 @@ #include "b_file_info.h" #include "b_json/b_json_entity_caps.h" #include "b_json/b_json_entity_ext_manage.h" +#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" @@ -42,9 +43,19 @@ void SvcSessionManager::VerifyCallerAndScenario(uint32_t clientToken, IServiceRe shared_lock lock(lock_); if (impl_.scenario != scenario) { HILOGE("Inconsistent scenario, impl scenario:%{public}d", impl_.scenario); + Backup::AppRadar::GetInstance().RecordBackUpFuncResWithoutBundle( + "SvcSessionManager::VerifyCallerAndScenario", + impl_.userId, BizStage::BIZ_STAGE_PERMISSION_CHECK, + static_cast(BError::Codes::SDK_MIXED_SCENARIO), + "{\"reason\":\"Inconsistent scenario\"}"); throw BError(BError::Codes::SDK_MIXED_SCENARIO); } if (impl_.clientToken != clientToken) { + Backup::AppRadar::GetInstance().RecordBackUpFuncResWithoutBundle( + "SvcSessionManager::VerifyCallerAndScenario", + impl_.userId, BizStage::BIZ_STAGE_PERMISSION_CHECK, + static_cast(BError::Codes::SA_REFUSED_ACT), + "{\"reason\":\"Caller mismatched\"}"); throw BError(BError::Codes::SA_REFUSED_ACT, "Caller mismatched"); } HILOGD("Succeed to verify the caller"); diff --git a/utils/BUILD.gn b/utils/BUILD.gn index 1ff282364..90126bd99 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -74,6 +74,7 @@ ohos_shared_library("backup_utils") { "src/b_process/b_guard_cwd.cpp", "src/b_process/b_guard_signal.cpp", "src/b_process/b_process.cpp", + "src/b_radar/b_radar.cpp", "src/b_sa/b_sa_utils.cpp", "src/b_tarball/b_tarball_cmdline.cpp", "src/b_tarball/b_tarball_factory.cpp", @@ -90,6 +91,7 @@ ohos_shared_library("backup_utils") { "c_utils:utils", "faultloggerd:libdfx_dumpcatcher", "hilog:libhilog", + "hisysevent:libhisysevent", "hitrace:hitrace_meter", "init:libbegetutil", "ipc:ipc_core", @@ -98,6 +100,7 @@ ohos_shared_library("backup_utils") { include_dirs = [ "${path_init}/interfaces/innerkits/include/syspara", "${path_backup}/interfaces/inner_api/native/backup_kit_inner/impl", + "${path_backup}/utils/include", ] deps = [ diff --git a/utils/include/b_radar/b_radar.h b/utils/include/b_radar/b_radar.h new file mode 100644 index 000000000..c6eb1c168 --- /dev/null +++ b/utils/include/b_radar/b_radar.h @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_FILEMGMT_BACKUP_B_RADAR_H +#define OHOS_FILEMGMT_BACKUP_B_RADAR_H +#include +#include + +namespace OHOS::FileManagement::Backup { +static std::chrono::time_point g_onBackUpStart; +static std::chrono::time_point g_onRestoreStart; + +enum class BizScene : int32_t { + BACKUP = 1, + RESTORE = 2 +}; + +enum class BizStage : int32_t { + BIZ_STAGE_GET_LOCAL_CAPABILITIES = 1, + BIZ_STAGE_GET_BACKUP_INFO, + BIZ_STAGE_CREATE_SESSION_BACKUP, + BIZ_STAGE_BACKUP_SA, + BIZ_STAGE_APPEND_BUNDLES, + BIZ_STAGE_BACKUP_EXTENSION, + BIZ_STAGE_APPLICATION, + BIZ_STAGE_EXTENSION_STATUS, + BIZ_STAGE_ON_BACKUP, + BIZ_STAGE_DO_BACKUP, + BIZ_STAGE_DATA_CONSISTENCY, + BIZ_STAGE_STATUS_CLEAR, + BIZ_STAGE_CLIENT_STATUS, + BIZ_STAGE_PERMISSION_CHECK +}; + +enum class BizStageRestore : int32_t { + BIZ_STAGE_GET_LOCAL_CAPABILITIES = 1, + BIZ_STAGE_CREATE_SESSION_RESTORE, + BIZ_STAGE_BACKUP_SA, + BIZ_STAGE_APPEND_BUNDLES, + BIZ_STAGE_CONNECT_BACKUP_EXTENSION, + BIZ_STAGE_APPLICATION, + BIZ_STAGE_EXTENSION_STATUS, + BIZ_STAGE_GET_FILE_HANDLE, + BIZ_STAGE_DO_RESTORE, + BIZ_STAGE_DATA_CONSISTENCY, + BIZ_STAGE_EXEC_ON_RESTORE, + BIZ_STAGE_STATUS_CLEAR, + BIZ_STAGE_CLIENT_STATUS, + BIZ_STAGE_PERMISSION_CHECK +}; + +class AppRadar { +public: + static AppRadar &GetInstance() + { + static AppRadar instance; + return instance; + } + +public: + int32_t GetUserId(); + void RecordBackUpFuncResWithBundle(const std::string &func, const std::string &bundleName, int32_t userId, + enum BizStage bizStage, int32_t resultCode, + const std::string &resultInfo = "{\"reason\":\"failed\"}"); + void RecordBackUpFuncResWithoutBundle(const std::string &func, int32_t userId, + enum BizStage bizStage, int32_t resultCode, + const std::string &resultInfo = "{\"reason\":\"failed\"}"); + void RecordDoBackUpRes(const std::string &func, int32_t userId, int32_t resultCode, int32_t exportDuration); + void RecordRestoreFuncRes(int32_t userId, const std::string &func, enum BizStageRestore bizStage, + int32_t resultCode); + void RecordRestoreFuncResWithBundle(const std::string &bundleName, int32_t userId, const std::string &func, + enum BizStageRestore bizStage, int32_t resultCode); + void RecordRestoreFuncResWithResult(const std::string &bundleName, int32_t userId, const std::string &func, + enum BizStageRestore bizStage, int32_t resultCode, + const std::string &resultInfo); + void RecordRestoreFuncResWithStatus(const std::string &bundleName, int32_t userId, const std::string &func, + enum BizStageRestore bizStage, const std::string &execStatus, + int32_t resultCode); + void RecordGetFileHandleRes(const std::string &bundleName, int32_t userId, int32_t resultCode, + const std::string &resultInfo); + void RecordOnRestoreRes(const std::string &bundleName, int32_t userId, const std::string &func, + const std::string &execStatus, int32_t resultCode); + void RecordBackupSARes(int32_t userId, const std::string &func, int32_t resultCode, const std::string &resultInfo); +private: + AppRadar() = default; + ~AppRadar() = default; + AppRadar(const AppRadar &) = delete; + AppRadar &operator=(const AppRadar &) = delete; + AppRadar(AppRadar &&) = delete; + AppRadar &operator=(AppRadar &&) = delete; +}; +} // namespace OHOS::FileManagement::AppRadar +#endif // OHOS_FILEMGMT_BACKUP_B_RADAR_H diff --git a/utils/src/b_radar/b_radar.cpp b/utils/src/b_radar/b_radar.cpp new file mode 100644 index 000000000..0f4e314d2 --- /dev/null +++ b/utils/src/b_radar/b_radar.cpp @@ -0,0 +1,228 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "b_radar/b_radar.h" + +#include +#include +#include + +#include "b_process/b_multiuser.h" +#include "b_resources/b_constants.h" +#include "hisysevent.h" + +namespace { +constexpr uint8_t INDEX = 3; +constexpr int32_t MS_1000 = 1000; +const std::string FILE_BACKUP_EVENTS = "FILE_BACKUP_EVENTS"; +} +namespace OHOS::FileManagement::Backup { +static std::string GetCurrentTime() +{ + 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()); + std::stringstream strTime; + strTime << (std::put_time(std::localtime(&time), "%Y-%m-%d %H:%M:%S:")) << (std::setfill('0')) + << (std::setw(INDEX)) << (ms.count() % MS_1000); + return strTime.str(); +} + +int32_t AppRadar::GetUserId() +{ + auto multiuser = BMultiuser::ParseUid(getuid()); + if ((multiuser.userId == BConstants::SYSTEM_UID) || (multiuser.userId == BConstants::XTS_UID)) { + return BConstants::DEFAULT_USER_ID; + } + return multiuser.userId; +} + +void AppRadar::RecordBackUpFuncResWithBundle(const std::string &func, const std::string &bundleName, + int32_t userId, enum BizStage bizStage, int32_t resultCode, + const std::string &resultInfo) +{ + HiSysEventWrite( + OHOS::HiviewDFX::HiSysEvent::Domain::FILEMANAGEMENT, + FILE_BACKUP_EVENTS, + OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, + "BUNDLE_NAME", bundleName, + "USER_ID", userId, + "PID", getpid(), + "FUNC", func, + "TIME", GetCurrentTime(), + "BIZ_SCENE", static_cast(BizScene::BACKUP), + "BIZ_STAGE", static_cast(bizStage), + "RESULT_CODE", resultCode, + "RESULT_INFO", resultInfo); +} + +void AppRadar::RecordBackUpFuncResWithoutBundle(const std::string &func, int32_t userId, enum BizStage bizStage, + int32_t resultCode, const std::string &resultInfo) +{ + HiSysEventWrite( + OHOS::HiviewDFX::HiSysEvent::Domain::FILEMANAGEMENT, + FILE_BACKUP_EVENTS, + OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, + "USER_ID", userId, + "PID", getpid(), + "FUNC", func, + "TIME", GetCurrentTime(), + "BIZ_SCENE", static_cast(BizScene::BACKUP), + "BIZ_STAGE", static_cast(bizStage), + "RESULT_CODE", resultCode, + "RESULT_INFO", resultInfo); +} + +void AppRadar::RecordDoBackUpRes(const std::string &func, int32_t userId, int32_t resultCode, + int32_t exportDuration) +{ + HiSysEventWrite( + OHOS::HiviewDFX::HiSysEvent::Domain::FILEMANAGEMENT, + FILE_BACKUP_EVENTS, + OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, + "USER_ID", userId, + "PID", getpid(), + "FUNC", func, + "TIME", GetCurrentTime(), + "BIZ_SCENE", static_cast(BizScene::BACKUP), + "BIZ_STAGE", static_cast(BizStage::BIZ_STAGE_DO_BACKUP), + "EXEC_STATUS", "{\"spend_time\":" + std::to_string(exportDuration) + "ms\"}", + "RESULT_CODE", resultCode); +} + +void AppRadar::RecordRestoreFuncRes(int32_t userId, const std::string &func, enum BizStageRestore bizStage, + int32_t resultCode) +{ + HiSysEventWrite( + OHOS::HiviewDFX::HiSysEvent::Domain::FILEMANAGEMENT, + FILE_BACKUP_EVENTS, + OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, + "USER_ID", userId, + "PID", getpid(), + "FUNC", func, + "TIME", GetCurrentTime(), + "BIZ_SCENE", static_cast(BizScene::RESTORE), + "BIZ_STAGE", static_cast(bizStage), + "RESULT_CODE", resultCode); +} + +void AppRadar::RecordRestoreFuncResWithBundle(const std::string &bundleName, int32_t userId, const std::string &func, + enum BizStageRestore bizStage, int32_t resultCode) +{ + HiSysEventWrite( + OHOS::HiviewDFX::HiSysEvent::Domain::FILEMANAGEMENT, + FILE_BACKUP_EVENTS, + OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, + "BUNDLE_NAME", bundleName, + "USER_ID", userId, + "PID", getpid(), + "FUNC", func, + "TIME", GetCurrentTime(), + "BIZ_SCENE", static_cast(BizScene::RESTORE), + "BIZ_STAGE", static_cast(bizStage), + "RESULT_CODE", resultCode); +} + +void AppRadar::RecordRestoreFuncResWithResult(const std::string &bundleName, int32_t userId, const std::string &func, + enum BizStageRestore bizStage, int32_t resultCode, + const std::string &resultInfo) +{ + HiSysEventWrite( + OHOS::HiviewDFX::HiSysEvent::Domain::FILEMANAGEMENT, + FILE_BACKUP_EVENTS, + OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, + "BUNDLE_NAME", bundleName, + "USER_ID", userId, + "PID", getpid(), + "FUNC", func, + "TIME", GetCurrentTime(), + "BIZ_SCENE", static_cast(BizScene::RESTORE), + "BIZ_STAGE", static_cast(bizStage), + "RESULT_CODE", resultCode, + "RESULT_INFO", resultInfo); +} + +void AppRadar::RecordRestoreFuncResWithStatus(const std::string &bundleName, int32_t userId, const std::string &func, + enum BizStageRestore bizStage, const std::string &execStatus, + int32_t resultCode) +{ + HiSysEventWrite( + OHOS::HiviewDFX::HiSysEvent::Domain::FILEMANAGEMENT, + FILE_BACKUP_EVENTS, + OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, + "BUNDLE_NAME", bundleName, + "USER_ID", userId, + "PID", getpid(), + "FUNC", func, + "TIME", GetCurrentTime(), + "BIZ_SCENE", static_cast(BizScene::RESTORE), + "BIZ_STAGE", static_cast(bizStage), + "EXEC_STATUS", execStatus, + "RESULT_CODE", resultCode); +} + +void AppRadar::RecordGetFileHandleRes(const std::string &bundleName, int32_t userId, int32_t resultCode, + const std::string &resultInfo) +{ + HiSysEventWrite( + OHOS::HiviewDFX::HiSysEvent::Domain::FILEMANAGEMENT, + FILE_BACKUP_EVENTS, + OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, + "BUNDLE_NAME", bundleName, + "USER_ID", userId, + "PID", getpid(), + "FUNC", "GetFileHandle", + "TIME", GetCurrentTime(), + "BIZ_SCENE", static_cast(BizScene::RESTORE), + "BIZ_STAGE", static_cast(BizStageRestore::BIZ_STAGE_GET_FILE_HANDLE), + "RESULT_CODE", resultCode, + "RESULT_INFO", resultInfo); +} + +void AppRadar::RecordOnRestoreRes(const std::string &bundleName, int32_t userId, const std::string &func, + const std::string &execStatus, int32_t resultCode) +{ + HiSysEventWrite( + OHOS::HiviewDFX::HiSysEvent::Domain::FILEMANAGEMENT, + FILE_BACKUP_EVENTS, + OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, + "BUNDLE_NAME", bundleName, + "USER_ID", userId, + "PID", getpid(), + "FUNC", func, + "TIME", GetCurrentTime(), + "BIZ_SCENE", static_cast(BizScene::RESTORE), + "BIZ_STAGE", static_cast(BizStageRestore::BIZ_STAGE_EXEC_ON_RESTORE), + "EXEC_STATUS", execStatus, + "RESULT_CODE", resultCode); +} + +void AppRadar::RecordBackupSARes(int32_t userId, const std::string &func, int32_t resultCode, + const std::string &resultInfo) +{ + HiSysEventWrite( + OHOS::HiviewDFX::HiSysEvent::Domain::FILEMANAGEMENT, + FILE_BACKUP_EVENTS, + OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, + "USER_ID", userId, + "PID", getpid(), + "FUNC", func, + "TIME", GetCurrentTime(), + "BIZ_SCENE", static_cast(BizScene::RESTORE), + "BIZ_STAGE", static_cast(BizStageRestore::BIZ_STAGE_BACKUP_SA), + "RESULT_CODE", resultCode, + "RESULT_INFO", resultInfo); +} +} // namespace OHOS::FileManagement::Backup \ No newline at end of file -- Gitee From 45a8896f97636e38dd7624fe5d1fe13938e4e39b Mon Sep 17 00:00:00 2001 From: zhangyaomaggie Date: Mon, 26 Aug 2024 11:56:03 +0800 Subject: [PATCH 2/3] Revert "add radar v1" This reverts commit ef147db2389157b885c8912f780f9997c1c219d4. --- .../native/backup_ext/src/ext_extension.cpp | 42 ---- .../backup_ext/src/sub_ext_extension.cpp | 61 ----- .../src/b_incremental_backup_session.cpp | 25 +- .../src/b_incremental_restore_session.cpp | 4 - .../b_incremental_session_restore_async.cpp | 4 - .../backup_kit_inner/src/b_session_backup.cpp | 25 +- .../src/b_session_restore.cpp | 3 - .../src/b_session_restore_async.cpp | 4 - .../backup_kit_inner/src/service_proxy.cpp | 14 -- .../native/backup_kit_inner/BUILD.gn | 1 - .../backup_sa/include/module_ipc/service.h | 3 - .../app_gallery_dispose_proxy.cpp | 31 --- services/backup_sa/src/module_ipc/service.cpp | 91 ------- .../src/module_ipc/service_incremental.cpp | 6 - .../src/module_ipc/svc_session_manager.cpp | 11 - utils/BUILD.gn | 3 - utils/include/b_radar/b_radar.h | 105 -------- utils/src/b_radar/b_radar.cpp | 228 ------------------ 18 files changed, 4 insertions(+), 657 deletions(-) delete mode 100644 utils/include/b_radar/b_radar.h delete mode 100644 utils/src/b_radar/b_radar.cpp diff --git a/frameworks/native/backup_ext/src/ext_extension.cpp b/frameworks/native/backup_ext/src/ext_extension.cpp index f00b12abf..2d836e2b9 100644 --- a/frameworks/native/backup_ext/src/ext_extension.cpp +++ b/frameworks/native/backup_ext/src/ext_extension.cpp @@ -47,7 +47,6 @@ #include "b_json/b_json_cached_entity.h" #include "b_jsonutil/b_jsonutil.h" #include "b_ohos/startup/backup_para.h" -#include "b_radar/b_radar.h" #include "b_tarball/b_tarball_factory.h" #include "filemgmt_libhilog.h" #include "hitrace_meter.h" @@ -127,18 +126,10 @@ void BackupExtExtension::VerifyCaller() uint32_t tokenCaller = IPCSkeleton::GetCallingTokenID(); int tokenType = Security::AccessToken::AccessTokenKit::GetTokenType(tokenCaller); if (tokenType != Security::AccessToken::ATokenTypeEnum::TOKEN_NATIVE) { - Backup::AppRadar::GetInstance().RecordBackUpFuncResWithoutBundle("BackupExtExtension::VerifyCaller", - AppRadar::GetInstance().GetUserId(), BizStage::BIZ_STAGE_PERMISSION_CHECK, - static_cast(BError::Codes::SA_REFUSED_ACT), - "{\"reason\":\"Calling tokenType error\"}"); throw BError(BError::Codes::EXT_BROKEN_IPC, string("Calling tokenType is error, token type is ").append(to_string(tokenType))); } if (IPCSkeleton::GetCallingUid() != BConstants::BACKUP_UID) { - Backup::AppRadar::GetInstance().RecordBackUpFuncResWithoutBundle("BackupExtExtension::VerifyCaller", - AppRadar::GetInstance().GetUserId(), BizStage::BIZ_STAGE_PERMISSION_CHECK, - static_cast(BError::Codes::SA_REFUSED_ACT), - "{\"reason\":\"Calling uid invalid\"}"); throw BError(BError::Codes::EXT_BROKEN_IPC, string("Calling uid is invalid, calling uid is ").append(to_string(IPCSkeleton::GetCallingUid()))); } @@ -835,13 +826,7 @@ void BackupExtExtension::AsyncTaskBackup(const string config) HILOGI("Do backup, start fwk timer end."); BJsonCachedEntity cachedEntity(config); auto cache = cachedEntity.Structuralize(); - auto start = std::chrono::system_clock::now(); auto ret = ptr->DoBackup(cache); - auto end = std::chrono::system_clock::now(); - auto exportDuration = std::chrono::duration_cast(end - start); - Backup::AppRadar::GetInstance().RecordDoBackUpRes("BackupExtExtension::AsyncTaskBackup", - AppRadar::GetInstance().GetUserId(), static_cast(ret), - static_cast(exportDuration.count())); // REM: 处理返回结果 ret ptr->AppDone(ret); HILOGI("backup app done %{public}d", ret); @@ -1165,16 +1150,6 @@ void BackupExtExtension::HandleSpecialVersionRestore() } } -void RecordDoRestoreRes(const std::string &bundleName, const std::string &func, int32_t ms, int32_t fileNum, - int32_t fileSize) -{ - std::stringstream ss; - ss << "\"file_count\": \"" << fileNum << "\", \"file_size\": \"" << fileSize - << "\", \"spend_time\": \"" << ms << "ms\""; - AppRadar::GetInstance().RecordRestoreFuncResWithStatus(bundleName, AppRadar::GetInstance().GetUserId(), - func, BizStageRestore::BIZ_STAGE_DO_RESTORE, ss.str(), static_cast(BError::Codes::OK)); -} - void BackupExtExtension::AsyncTaskRestore(std::set fileSet, const std::vector extManageInfo) { @@ -1184,7 +1159,6 @@ void BackupExtExtension::AsyncTaskRestore(std::set fileSet, BExcepUltils::BAssert(ptr->extension_, BError::Codes::EXT_INVAL_ARG, "Extension handle have been released"); try { int ret = ERR_OK; - auto startTime = std::chrono::system_clock::now(); if (ptr->extension_->SpecialVersionForCloneAndCloud()) { ptr->HandleSpecialVersionRestore(); return; @@ -1202,11 +1176,6 @@ void BackupExtExtension::AsyncTaskRestore(std::set fileSet, ptr->extension_->UseFullBackupOnly() && !ptr->extension_->SpecialVersionForCloneAndCloud(); ptr->RestoreBigFiles(appendTargetPath); ptr->DeleteBackupTars(); - - auto endTime = std::chrono::system_clock::now(); - auto ms = std::chrono::duration_cast(endTime-startTime).count(); - RecordDoRestoreRes("bundlename", "AsyncTaskRestore", static_cast(ms), - static_cast(fileSet.size()), 0); if (ret == ERR_OK) { ptr->AsyncTaskRestoreForUpgrade(); } else { @@ -1246,9 +1215,6 @@ void BackupExtExtension::AsyncTaskIncrementalRestore() ptr->CheckTmpDirFileInfos(); } // 解压 - auto startTime = std::chrono::system_clock::now(); - int32_t fileSize = 0; - int32_t fileNum = 0; int ret = ptr->DoIncrementalRestore(); // 恢复用户tar包以及大文件 // 目的地址是否需要拼接path(临时目录),FullBackupOnly为true并且非特殊场景 @@ -1258,10 +1224,6 @@ void BackupExtExtension::AsyncTaskIncrementalRestore() // delete 1.tar/manage.json ptr->DeleteBackupIncrementalTars(); - auto endTime = std::chrono::system_clock::now(); - auto ms = std::chrono::duration_cast(endTime-startTime).count(); - RecordDoRestoreRes("bundlename", "AsyncTaskIncrementalRestore", - static_cast(ms), fileNum, fileSize); if (ptr != nullptr && ptr->isDebug_) { ptr->CheckRestoreFileInfos(); } @@ -1355,7 +1317,6 @@ void BackupExtExtension::AsyncTaskRestoreForUpgrade() ptr->StartOnProcessTaskThread(obj, BackupRestoreScenario::FULL_RESTORE); auto callBackup = ptr->OnRestoreCallback(obj); auto callBackupEx = ptr->OnRestoreExCallback(obj); - g_onRestoreStart = std::chrono::system_clock::now(); ErrCode err = ptr->extension_->OnRestore(callBackup, callBackupEx); if (err != ERR_OK) { ptr->AppDone(BError::GetCodeByErrno(err)); @@ -1406,7 +1367,6 @@ void BackupExtExtension::AsyncTaskIncrementalRestoreForUpgrade() ptr->StartOnProcessTaskThread(obj, BackupRestoreScenario::INCREMENTAL_RESTORE); auto callBackup = ptr->IncreOnRestoreCallback(obj); auto callBackupEx = ptr->IncreOnRestoreExCallback(obj); - g_onRestoreStart = std::chrono::system_clock::now(); ErrCode err = ptr->extension_->OnRestore(callBackup, callBackupEx); if (err != ERR_OK) { HILOGE("OnRestore done, err = %{pubilc}d", err); @@ -1534,7 +1494,6 @@ void BackupExtExtension::AsyncTaskOnBackup() ptr->StartOnProcessTaskThread(obj, BackupRestoreScenario::FULL_BACKUP); auto callBackup = ptr->OnBackupCallback(obj); auto callBackupEx = ptr->OnBackupExCallback(obj); - g_onBackUpStart = std::chrono::system_clock::now(); ErrCode err = ptr->extension_->OnBackup(callBackup, callBackupEx); if (err != ERR_OK) { HILOGE("OnBackup done, err = %{pubilc}d", err); @@ -1920,7 +1879,6 @@ void BackupExtExtension::AsyncTaskOnIncrementalBackup() ptr->StartOnProcessTaskThread(obj, BackupRestoreScenario::INCREMENTAL_BACKUP); auto callBackup = ptr->IncOnBackupCallback(obj); auto callBackupEx = ptr->IncOnBackupExCallback(obj); - g_onBackUpStart = std::chrono::system_clock::now(); ErrCode err = ptr->extension_->OnBackup(callBackup, callBackupEx); if (err != ERR_OK) { HILOGE("OnBackup done, err = %{pubilc}d", err); diff --git a/frameworks/native/backup_ext/src/sub_ext_extension.cpp b/frameworks/native/backup_ext/src/sub_ext_extension.cpp index b4f63b222..55ed437d3 100644 --- a/frameworks/native/backup_ext/src/sub_ext_extension.cpp +++ b/frameworks/native/backup_ext/src/sub_ext_extension.cpp @@ -47,7 +47,6 @@ #include "b_json/b_json_cached_entity.h" #include "b_jsonutil/b_jsonutil.h" #include "b_ohos/startup/backup_para.h" -#include "b_radar/b_radar.h" #include "b_tarball/b_tarball_factory.h" #include "filemgmt_libhilog.h" #include "hitrace_meter.h" @@ -250,14 +249,6 @@ std::function BackupExtExtension::OnRestoreCallback( return; } HILOGI("Current bundle will execute app done"); - if (errCode == ERR_OK) { - auto endTime = std::chrono::system_clock::now(); - auto ms = std::chrono::duration_cast(endTime - g_onRestoreStart).count(); - std::stringstream ss; - ss << "\"spend_time\": \"" << ms << "ms\""; - AppRadar::GetInstance().RecordOnRestoreRes("bundlename", AppRadar::GetInstance().GetUserId(), - "BackupExtExtension::OnRestoreCallback", ss.str(), ERR_OK); - } extensionPtr->FinishOnProcessTask(); if (errMsg.empty()) { extensionPtr->AppDone(errCode); @@ -283,14 +274,6 @@ std::function BackupExtExtension::OnRestoreExCallbac HILOGE("Extension handle have been released"); return; } - if (errCode == ERR_OK && !restoreRetInfo.empty()) { - auto endTime = std::chrono::system_clock::now(); - auto ms = std::chrono::duration_cast(endTime - g_onRestoreStart).count(); - std::stringstream ss; - ss << "\"spend_time\": \"" << ms << "ms\""; - AppRadar::GetInstance().RecordOnRestoreRes("bundlename", AppRadar::GetInstance().GetUserId(), - "OnRestoreExCallback", ss.str(), ERR_OK); - } extensionPtr->FinishOnProcessTask(); extensionPtr->extension_->InvokeAppExtMethod(errCode, restoreRetInfo); if (errCode == ERR_OK) { @@ -341,14 +324,6 @@ std::function BackupExtExtension::IncreOnRestoreExCa HILOGE("Extension handle have been released"); return; } - if (errCode == ERR_OK && !restoreRetInfo.empty()) { - auto endTime = std::chrono::system_clock::now(); - auto ms = std::chrono::duration_cast(endTime - g_onRestoreStart).count(); - std::stringstream ss; - ss << "\"spend_time\": \"" << ms << "ms\""; - AppRadar::GetInstance().RecordOnRestoreRes("bundlename", AppRadar::GetInstance().GetUserId(), - "IncreOnRestoreExCallback", ss.str(), ERR_OK); - } extensionPtr->FinishOnProcessTask(); extensionPtr->extension_->InvokeAppExtMethod(errCode, restoreRetInfo); if (errCode == ERR_OK) { @@ -378,14 +353,6 @@ std::function BackupExtExtension::IncreOnRestoreCall return; } HILOGI("Current bundle will execute app done"); - if (errCode == ERR_OK) { - auto endTime = std::chrono::system_clock::now(); - auto ms = std::chrono::duration_cast(endTime - g_onRestoreStart).count(); - std::stringstream ss; - ss << "\"spend_time\": \"" << ms << "ms\""; - AppRadar::GetInstance().RecordOnRestoreRes("bundlename", AppRadar::GetInstance().GetUserId(), - "IncreOnRestoreCallback", ss.str(), ERR_OK); - } extensionPtr->FinishOnProcessTask(); if (errMsg.empty()) { extensionPtr->AppIncrementalDone(errCode); @@ -412,13 +379,6 @@ std::function BackupExtExtension::OnBackupCall HILOGE("Extension handle have been released"); return; } - if (errCode == ERR_OK) { - auto onBackUpEnd = std::chrono::system_clock::now(); - auto ms = std::chrono::duration_cast(onBackUpEnd - g_onBackUpStart).count(); - AppRadar::GetInstance().RecordBackUpFuncResWithBundle("BackupExtExtension::OnBackupCallback", - "bundleName", AppRadar::GetInstance().GetUserId(), BizStage::BIZ_STAGE_ON_BACKUP, 0, - string("{\"spend_time\":\" ").append(to_string(ms)).append(string("ms\"}"))); - } extensionPtr->FinishOnProcessTask(); extensionPtr->AsyncTaskBackup(extensionPtr->extension_->GetUsrConfig()); }; @@ -438,13 +398,6 @@ std::function BackupExtExtension::OnBackupExCa HILOGE("Extension handle have been released"); return; } - if (errCode == ERR_OK && !backupExRetInfo.empty()) { - auto onBackUpEnd = std::chrono::system_clock::now(); - auto ms = std::chrono::duration_cast(onBackUpEnd - g_onBackUpStart).count(); - AppRadar::GetInstance().RecordBackUpFuncResWithBundle("BackupExtExtension::OnBackupExCallback", - "bundleName", AppRadar::GetInstance().GetUserId(), BizStage::BIZ_STAGE_ON_BACKUP, 0, - string("{\"spend_time\":\" ").append(to_string(ms)).append(string("ms\"}"))); - } extensionPtr->extension_->InvokeAppExtMethod(errCode, backupExRetInfo); if (backupExRetInfo.size()) { HILOGI("Will notify backup result report"); @@ -470,13 +423,6 @@ std::function BackupExtExtension::IncOnBackupC return; } HILOGI("Start GetAppLocalListAndDoIncrementalBackup"); - if (errCode == ERR_OK) { - auto onBackUpEnd = std::chrono::system_clock::now(); - auto ms = std::chrono::duration_cast(onBackUpEnd - g_onBackUpStart).count(); - AppRadar::GetInstance().RecordBackUpFuncResWithBundle("BackupExtExtension::IncOnBackupCallback", - "bundleName", AppRadar::GetInstance().GetUserId(), BizStage::BIZ_STAGE_ON_BACKUP, 0, - string("{\"spend_time\":\" ").append(to_string(ms)).append(string("ms\"}"))); - } extPtr->FinishOnProcessTask(); proxy->GetAppLocalListAndDoIncrementalBackup(); }; @@ -499,13 +445,6 @@ std::function BackupExtExtension::IncOnBackupE HILOGE("Extension handle have been released"); return; } - if (errCode == ERR_OK && !backupExRetInfo.empty()) { - auto onBackUpEnd = std::chrono::system_clock::now(); - auto ms = std::chrono::duration_cast(onBackUpEnd - g_onBackUpStart).count(); - AppRadar::GetInstance().RecordBackUpFuncResWithBundle("BackupExtExtension::IncOnBackupExCallback", - "bundleName", AppRadar::GetInstance().GetUserId(), BizStage::BIZ_STAGE_ON_BACKUP, 0, - string("{\"spend_time\":\" ").append(to_string(ms)).append(string("ms\"}"))); - } extensionPtr->extension_->InvokeAppExtMethod(errCode, backupExRetInfo); if (backupExRetInfo.size()) { HILOGI("Start GetAppLocalListAndDoIncrementalBackup"); 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 ade0f0864..f747d28c7 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 @@ -16,7 +16,6 @@ #include "b_incremental_backup_session.h" #include "b_error/b_error.h" -#include "b_radar/b_radar.h" #include "filemgmt_libhilog.h" #include "service_proxy.h" #include "service_reverse.h" @@ -56,8 +55,6 @@ 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); - Backup::AppRadar::GetInstance().RecordBackUpFuncResWithoutBundle("BIncrementalBackupSession::Init", - AppRadar::GetInstance().GetUserId(), BizStage::BIZ_STAGE_CREATE_SESSION_BACKUP, res); return nullptr; } @@ -96,16 +93,7 @@ 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) { - std::string ss; - for (const auto &bundle:bundlesToBackup) { - ss += bundle.bundleName + ", "; - } - Backup::AppRadar::GetInstance().RecordBackUpFuncResWithBundle("BIncrementalBackupSession::AppendBundles", - ss.c_str(), AppRadar::GetInstance().GetUserId(), BizStage::BIZ_STAGE_APPEND_BUNDLES, res); - } - return res; + return proxy->AppendBundlesIncrementalBackupSession(bundlesToBackup); } ErrCode BIncrementalBackupSession::AppendBundles(vector bundlesToBackup, @@ -116,16 +104,7 @@ ErrCode BIncrementalBackupSession::AppendBundles(vector bundle return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } - int32_t res = proxy->AppendBundlesIncrementalBackupSession(bundlesToBackup, infos); - if (res != 0) { - std::string ss; - for (const auto &bundle:bundlesToBackup) { - ss += bundle.bundleName + ", "; - } - Backup::AppRadar::GetInstance().RecordBackUpFuncResWithBundle("BIncrementalBackupSession::AppendBundles", - ss.c_str(), AppRadar::GetInstance().GetUserId(), BizStage::BIZ_STAGE_APPEND_BUNDLES, res); - } - return res; + return proxy->AppendBundlesIncrementalBackupSession(bundlesToBackup, infos); } ErrCode BIncrementalBackupSession::Release() 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 b2a7041f5..000241ad0 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 @@ -16,7 +16,6 @@ #include "b_incremental_restore_session.h" #include "b_error/b_error.h" -#include "b_radar/b_radar.h" #include "filemgmt_libhilog.h" #include "service_proxy.h" #include "service_reverse.h" @@ -55,9 +54,6 @@ 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::GetInstance().RecordRestoreFuncRes(AppRadar::GetInstance().GetUserId(), - "BIncrementalRestoreSession::Init", - BizStageRestore::BIZ_STAGE_CREATE_SESSION_RESTORE, res); return nullptr; } 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 f6008298e..84f75d66e 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 @@ -16,7 +16,6 @@ #include "b_incremental_session_restore_async.h" #include "b_error/b_error.h" -#include "b_radar/b_radar.h" #include "b_resources/b_constants.h" #include "filemgmt_libhilog.h" #include "service_proxy.h" @@ -63,9 +62,6 @@ 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::GetInstance().RecordRestoreFuncRes(AppRadar::GetInstance().GetUserId(), - "BIncrementalSessionRestoreAsync::Init", - BizStageRestore::BIZ_STAGE_CREATE_SESSION_RESTORE, res); return nullptr; } 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 b0f55c78b..04176686b 100644 --- a/frameworks/native/backup_kit_inner/src/b_session_backup.cpp +++ b/frameworks/native/backup_kit_inner/src/b_session_backup.cpp @@ -16,7 +16,6 @@ #include "b_session_backup.h" #include "b_error/b_error.h" -#include "b_radar/b_radar.h" #include "filemgmt_libhilog.h" #include "service_proxy.h" #include "service_reverse.h" @@ -56,8 +55,6 @@ 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); - Backup::AppRadar::GetInstance().RecordBackUpFuncResWithoutBundle("BSessionBackup::Init", - AppRadar::GetInstance().GetUserId(), BizStage::BIZ_STAGE_CREATE_SESSION_BACKUP, res); return nullptr; } @@ -106,16 +103,7 @@ ErrCode BSessionBackup::AppendBundles(vector bundlesToBackup) return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } - int32_t res = proxy->AppendBundlesBackupSession(bundlesToBackup); - if (res != 0) { - std::string ss; - for (const auto &bundleName:bundlesToBackup) { - ss += bundleName + ", "; - } - Backup::AppRadar::GetInstance().RecordBackUpFuncResWithBundle("BSessionBackup::AppendBundles", - ss.c_str(), AppRadar::GetInstance().GetUserId(), BizStage::BIZ_STAGE_APPEND_BUNDLES, res); - } - return res; + return proxy->AppendBundlesBackupSession(bundlesToBackup); } ErrCode BSessionBackup::AppendBundles(vector bundlesToBackup, vector detailInfos) @@ -125,16 +113,7 @@ ErrCode BSessionBackup::AppendBundles(vector bundlesToBackup, vector return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } - int32_t res = proxy->AppendBundlesDetailsBackupSession(bundlesToBackup, detailInfos); - if (res != 0) { - std::string ss; - for (const auto &bundleName:bundlesToBackup) { - ss += bundleName + ", "; - } - Backup::AppRadar::GetInstance().RecordBackUpFuncResWithBundle("BSessionBackup::AppendBundles", - ss.c_str(), AppRadar::GetInstance().GetUserId(), BizStage::BIZ_STAGE_APPEND_BUNDLES, res); - } - return res; + return proxy->AppendBundlesDetailsBackupSession(bundlesToBackup, detailInfos); } ErrCode BSessionBackup::Finish() 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 ec2c95bb7..250d68bc7 100644 --- a/frameworks/native/backup_kit_inner/src/b_session_restore.cpp +++ b/frameworks/native/backup_kit_inner/src/b_session_restore.cpp @@ -16,7 +16,6 @@ #include "b_session_restore.h" #include "b_error/b_error.h" -#include "b_radar/b_radar.h" #include "filemgmt_libhilog.h" #include "service_proxy.h" #include "service_reverse.h" @@ -55,8 +54,6 @@ 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::GetInstance().RecordRestoreFuncRes(AppRadar::GetInstance().GetUserId(), "BSessionRestore::Init", - BizStageRestore::BIZ_STAGE_CREATE_SESSION_RESTORE, res); return nullptr; } 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 52177d113..0e86b3df7 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 @@ -16,7 +16,6 @@ #include "b_session_restore_async.h" #include "b_error/b_error.h" -#include "b_radar/b_radar.h" #include "b_resources/b_constants.h" #include "b_session_restore.h" #include "filemgmt_libhilog.h" @@ -64,9 +63,6 @@ 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::GetInstance().RecordRestoreFuncRes(AppRadar::GetInstance().GetUserId(), - "BSessionRestoreAsync::Init", - BizStageRestore::BIZ_STAGE_CREATE_SESSION_RESTORE, res); return nullptr; } diff --git a/frameworks/native/backup_kit_inner/src/service_proxy.cpp b/frameworks/native/backup_kit_inner/src/service_proxy.cpp index cf818b94e..1870448e3 100644 --- a/frameworks/native/backup_kit_inner/src/service_proxy.cpp +++ b/frameworks/native/backup_kit_inner/src/service_proxy.cpp @@ -15,14 +15,11 @@ #include "service_proxy.h" -#include - #include "iservice_registry.h" #include "system_ability_definition.h" #include "b_error/b_error.h" #include "b_error/b_excep_utils.h" -#include "b_radar/b_radar.h" #include "b_resources/b_constants.h" #include "filemgmt_libhilog.h" #include "svc_death_recipient.h" @@ -449,9 +446,6 @@ sptr ServiceProxy::GetInstance() [loadCallback]() { return loadCallback->isLoadSuccess_.load(); }); if (!waitStatus) { HILOGE("Load backup sa timeout"); - Backup::AppRadar::GetInstance().RecordBackUpFuncResWithoutBundle("ServiceProxy::GetInstance", - AppRadar::GetInstance().GetUserId(), BizStage::BIZ_STAGE_BACKUP_SA, - static_cast(BError::Codes::SA_INVAL_ARG), "{\"reason\":\"Load backup sa timeout\"}"); return nullptr; } return serviceProxy_; @@ -487,10 +481,6 @@ void ServiceProxy::ServiceProxyLoadCallback::OnLoadSystemAbilitySuccess(int32_t HILOGE("Failed to get remote object"); serviceProxy_ = nullptr; isLoadSuccess_.store(false); - Backup::AppRadar::GetInstance().RecordBackUpFuncResWithoutBundle( - "ServiceProxyLoadCallback::OnLoadSystemAbilitySuccess", - AppRadar::GetInstance().GetUserId(), BizStage::BIZ_STAGE_BACKUP_SA, - static_cast(BError::Codes::SA_INVAL_ARG), "{\"reason\":\"Load backup sa fail\"}"); proxyConVar_.notify_one(); return; } @@ -509,10 +499,6 @@ void ServiceProxy::ServiceProxyLoadCallback::OnLoadSystemAbilityFail(int32_t sys { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); HILOGE("Load backup sa failed, systemAbilityId:%{private}d", systemAbilityId); - std::stringstream ss; - ss << "\"reason\": \"Load backup sa failed\", \"system_ability_id\": \"" << systemAbilityId << "\""; - AppRadar::GetInstance().RecordBackupSARes(AppRadar::GetInstance().GetUserId(), "ServiceProxy::GetInstance", - static_cast(BError::Codes::EXT_BROKEN_IPC), ss.str()); unique_lock lock(proxyMutex_); serviceProxy_ = nullptr; isLoadSuccess_.store(false); diff --git a/interfaces/inner_api/native/backup_kit_inner/BUILD.gn b/interfaces/inner_api/native/backup_kit_inner/BUILD.gn index 2ee1a876d..c84d227f2 100644 --- a/interfaces/inner_api/native/backup_kit_inner/BUILD.gn +++ b/interfaces/inner_api/native/backup_kit_inner/BUILD.gn @@ -27,7 +27,6 @@ config("private_config") { "${path_backup}/frameworks/native/backup_kit_inner/include", "${path_backup}/interfaces/inner_api/native/backup_kit_inner", "${path_backup}/interfaces/inner_api/native/backup_kit_inner/impl", - "${path_backup}/utils/include", ] } diff --git a/services/backup_sa/include/module_ipc/service.h b/services/backup_sa/include/module_ipc/service.h index 78ed2c935..fa1da2e93 100644 --- a/services/backup_sa/include/module_ipc/service.h +++ b/services/backup_sa/include/module_ipc/service.h @@ -91,9 +91,6 @@ public: void OnStop() override; void StopAll(const wptr &obj, bool force = false); int Dump(int fd, const std::vector &args) override; - void PermissionCheckFailRadar(const std::string &info); - void GetLocalCapabilitiesRadar(const std::string &func, int32_t resultCode, - const std::string &info); /** * @brief 执行启动 backup extension 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 c60236c02..f49ed5bd3 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 @@ -17,7 +17,6 @@ #include -#include "b_radar/b_radar.h" #include "message_parcel.h" #include "want.h" @@ -86,35 +85,6 @@ DisposeErr AppGalleryDisposeProxy::EndRestore(const std::string &bundleName) return DoDispose(bundleName, DisposeOperation::END_RESTORE); } -void RecordDoDisposeRes(const std::string &bundleName, - AppGalleryDisposeProxy::DisposeOperation disposeOperation, int32_t err) -{ - switch (disposeOperation) { - case AppGalleryDisposeProxy::DisposeOperation::START_BACKUP: - AppRadar::GetInstance().RecordBackUpFuncResWithBundle("AppGalleryDisposeProxy::StartBackup", - bundleName, AppRadar::GetInstance().GetUserId(), - BizStage::BIZ_STAGE_APPLICATION, err); - break; - case AppGalleryDisposeProxy::DisposeOperation::END_BACKUP: - AppRadar::GetInstance().RecordBackUpFuncResWithBundle("AppGalleryDisposeProxy::EndBackup", - bundleName, AppRadar::GetInstance().GetUserId(), - BizStage::BIZ_STAGE_APPLICATION, err); - break; - case AppGalleryDisposeProxy::DisposeOperation::START_RESTORE: - AppRadar::GetInstance().RecordRestoreFuncResWithBundle(bundleName, AppRadar::GetInstance().GetUserId(), - "AppGalleryDisposeProxy::StartRestore", - BizStageRestore::BIZ_STAGE_STATUS_CLEAR, err); - break; - case AppGalleryDisposeProxy::DisposeOperation::END_RESTORE: - AppRadar::GetInstance().RecordRestoreFuncResWithBundle(bundleName, AppRadar::GetInstance().GetUserId(), - "AppGalleryDisposeProxy::EndRestore", - BizStageRestore::BIZ_STAGE_STATUS_CLEAR, err); - break; - default: - break; - } -} - DisposeErr AppGalleryDisposeProxy::DoDispose(const std::string &bundleName, DisposeOperation disposeOperation) { HILOGI("DoDispose, app %{public}s, operation %{public}d", bundleName.c_str(), disposeOperation); @@ -143,7 +113,6 @@ DisposeErr AppGalleryDisposeProxy::DoDispose(const std::string &bundleName, Disp MessageOption option(MessageOption::TF_ASYNC); int32_t ret = appRemoteObj_->SendRequest(static_cast(disposeOperation), data, reply, option); if (ret != ERR_NONE) { - RecordDoDisposeRes(bundleName, disposeOperation, ret); HILOGI("SendRequest error, code=%{public}d, bundleName=%{public}s", ret, bundleName.c_str()); return DisposeErr::REQUEST_FAIL; } diff --git a/services/backup_sa/src/module_ipc/service.cpp b/services/backup_sa/src/module_ipc/service.cpp index fab10321c..6e834db31 100644 --- a/services/backup_sa/src/module_ipc/service.cpp +++ b/services/backup_sa/src/module_ipc/service.cpp @@ -47,7 +47,6 @@ #include "b_jsonutil/b_jsonutil.h" #include "b_ohos/startup/backup_para.h" #include "b_process/b_multiuser.h" -#include "b_radar/b_radar.h" #include "b_resources/b_constants.h" #include "b_sa/b_sa_utils.h" #include "bundle_mgr_client.h" @@ -139,14 +138,6 @@ void Service::OnStop() HILOGI("SA OnStop End."); } -void Service::GetLocalCapabilitiesRadar(const std::string &func, int32_t resultCode, - const std::string &info) -{ - std::string funcPos = "Service::"; - Backup::AppRadar::GetInstance().RecordBackUpFuncResWithoutBundle(funcPos.append(func), - GetUserIdDefault(), BizStage::BIZ_STAGE_GET_LOCAL_CAPABILITIES, resultCode, info); -} - UniqueFd Service::GetLocalCapabilities() { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); @@ -158,7 +149,6 @@ UniqueFd Service::GetLocalCapabilities() HILOGI("Begin"); if (session_ == nullptr) { HILOGE("GetLocalCapabilities error, session is empty."); - GetLocalCapabilitiesRadar("GetLocalCapabilities", EPERM, "{\"reason\":\"session empty\"}"); return UniqueFd(-EPERM); } session_->IncreaseSessionCnt(); @@ -170,8 +160,6 @@ UniqueFd Service::GetLocalCapabilities() if (fd < 0) { HILOGE("Failed to open config file = %{private}s, err = %{public}d", path.c_str(), errno); session_->DecreaseSessionCnt(); - GetLocalCapabilitiesRadar("GetLocalCapabilities", EPERM, - "{\"reason\":\"failed to open config file\"}"); return UniqueFd(-EPERM); } BJsonCachedEntity cachedEntity(std::move(fd)); @@ -189,17 +177,14 @@ UniqueFd Service::GetLocalCapabilities() } catch (const BError &e) { session_->DecreaseSessionCnt(); HILOGE("GetLocalCapabilities failed, errCode = %{public}d", e.GetCode()); - GetLocalCapabilitiesRadar("GetLocalCapabilities", e.GetCode(), "{\"reason\":\"failed\"}"); return UniqueFd(-e.GetCode()); } catch (const exception &e) { session_->DecreaseSessionCnt(); HILOGI("Catched an unexpected low-level exception %{public}s", e.what()); - GetLocalCapabilitiesRadar("GetLocalCapabilities", EPERM, "{\"reason\":\"exception\"}"); return UniqueFd(-EPERM); } catch (...) { session_->DecreaseSessionCnt(); HILOGI("Unexpected exception"); - GetLocalCapabilitiesRadar("GetLocalCapabilities", EPERM, "{\"reason\":\"exception\"}"); return UniqueFd(-EPERM); } } @@ -218,10 +203,6 @@ string Service::VerifyCallerAndGetCallerName() if (tokenType == Security::AccessToken::ATokenTypeEnum::TOKEN_HAP) { Security::AccessToken::HapTokenInfo hapTokenInfo; if (Security::AccessToken::AccessTokenKit::GetHapTokenInfo(tokenCaller, hapTokenInfo) != 0) { - Backup::AppRadar::GetInstance().RecordBackUpFuncResWithoutBundle("Service::VerifyCallerAndGetCallerName", - GetUserIdDefault(), BizStage::BIZ_STAGE_PERMISSION_CHECK, - static_cast(BError::Codes::SA_REFUSED_ACT), - "{\"reason\":\"Get hap token info failed\"}"); throw BError(BError::Codes::SA_INVAL_ARG, "Get hap token info failed"); } std::string bundleNameIndexInfo = BJsonUtil::BuildBundleNameIndexInfo(hapTokenInfo.bundleName, @@ -231,21 +212,10 @@ string Service::VerifyCallerAndGetCallerName() } else { string str = to_string(tokenCaller); HILOGE("tokenID = %{private}s", GetAnonyString(str).c_str()); - Backup::AppRadar::GetInstance().RecordBackUpFuncResWithoutBundle("Service::VerifyCallerAndGetCallerName", - GetUserIdDefault(), BizStage::BIZ_STAGE_PERMISSION_CHECK, - static_cast(BError::Codes::SA_REFUSED_ACT), - string("{\"reason\":\"Invalid token type ").append(to_string(tokenType)).append(string("\"}"))); throw BError(BError::Codes::SA_INVAL_ARG, string("Invalid token type ").append(to_string(tokenType))); } } -void Service::PermissionCheckFailRadar(const std::string &info) -{ - Backup::AppRadar::GetInstance().RecordBackUpFuncResWithoutBundle("Service::VerifyCaller", - GetUserIdDefault(), BizStage::BIZ_STAGE_PERMISSION_CHECK, - static_cast(BError::Codes::SA_REFUSED_ACT), info); -} - void Service::VerifyCaller() { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); @@ -255,8 +225,6 @@ void Service::VerifyCaller() case Security::AccessToken::ATokenTypeEnum::TOKEN_NATIVE: { /* Update Service */ if (Security::AccessToken::AccessTokenKit::VerifyAccessToken(tokenCaller, BACKUP_PERMISSION) != Security::AccessToken::PermissionState::PERMISSION_GRANTED) { - std::string info = "{\"reason\":\"Permission denied, token type is " + to_string(tokenType) + "\"}"; - PermissionCheckFailRadar(info); throw BError(BError::Codes::SA_REFUSED_ACT, string("Permission denied, token type is ").append(to_string(tokenType))); } @@ -265,15 +233,11 @@ void Service::VerifyCaller() case Security::AccessToken::ATokenTypeEnum::TOKEN_HAP: { if (Security::AccessToken::AccessTokenKit::VerifyAccessToken(tokenCaller, BACKUP_PERMISSION) != Security::AccessToken::PermissionState::PERMISSION_GRANTED) { - std::string info = "{\"reason\":\"Permission denied, token type is " + to_string(tokenType) + "\"}"; - PermissionCheckFailRadar(info); throw BError(BError::Codes::SA_REFUSED_ACT, string("Permission denied, token type is ").append(to_string(tokenType))); } uint64_t fullTokenId = OHOS::IPCSkeleton::GetCallingFullTokenID(); if (!Security::AccessToken::TokenIdKit::IsSystemAppByFullTokenID(fullTokenId)) { - std::string info = "{\"reason\":\"Permission denied, token type is " + to_string(tokenType) + "\"}"; - PermissionCheckFailRadar(info); throw BError(BError::Codes::SA_REFUSED_ACT, string("Permission denied, token type is ").append(to_string(tokenType))); } @@ -281,14 +245,10 @@ void Service::VerifyCaller() } case Security::AccessToken::ATokenTypeEnum::TOKEN_SHELL: if (IPCSkeleton::GetCallingUid() != BConstants::SYSTEM_UID) { - std::string info = "{\"reason\":\"invalid calling uid\"}"; - PermissionCheckFailRadar(info); throw BError(BError::Codes::SA_REFUSED_ACT, "Calling uid is invalid"); } break; default: - std::string info = "{\"reason\":\"Permission denied, token type is " + to_string(tokenType) + "\"}"; - PermissionCheckFailRadar(info); throw BError(BError::Codes::SA_REFUSED_ACT, string("Invalid token type ").append(to_string(tokenType))); break; } @@ -486,9 +446,6 @@ ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, const vectorDecreaseSessionCnt(); return e.GetCode(); @@ -554,9 +511,6 @@ ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, return BError(BError::Codes::OK); } catch (const BError &e) { HILOGE("Catch exception"); - AppRadar::GetInstance().RecordRestoreFuncResWithBundle("bundlename", GetUserIdDefault(), - "Service::AppendBundlesRestoreSession", - BizStageRestore::BIZ_STAGE_APPEND_BUNDLES, e.GetCode()); HandleExceptionOnAppendBundles(session_, bundleNames, {}); session_->DecreaseSessionCnt(); return e.GetCode(); @@ -976,9 +930,6 @@ ErrCode Service::LaunchBackupExtension(const BundleName &bundleName) } return BError(BError::Codes::OK); } catch (const BError &e) { - AppRadar::GetInstance().RecordGetFileHandleRes(bundleName, GetUserIdDefault(), - static_cast(e.GetCode()), - "{\"reason\":\"catch error\"}"); return e.GetCode(); } catch (const exception &e) { HILOGI("Catched an unexpected low-level exception %{public}s", e.what()); @@ -1024,17 +975,11 @@ ErrCode Service::GetFileHandle(const string &bundleName, const string &fileName) auto backUpConnection = session_->GetExtConnection(bundleName); if (backUpConnection == nullptr) { HILOGE("GetFileHandle error, backUpConnection is empty"); - AppRadar::GetInstance().RecordGetFileHandleRes(bundleName, GetUserIdDefault(), - static_cast(BError::Codes::SA_INVAL_ARG), - "{\"reason\":\"backUpConnection is empty\"}"); return BError(BError::Codes::SA_INVAL_ARG); } auto proxy = backUpConnection->GetBackupExtProxy(); if (!proxy) { HILOGE("GetFileHandle error, Extension backup Proxy is empty"); - AppRadar::GetInstance().RecordGetFileHandleRes(bundleName, GetUserIdDefault(), - static_cast(BError::Codes::SA_INVAL_ARG), - "{\"reason\":\"Extension backup Proxy is empty\"}"); return BError(BError::Codes::SA_INVAL_ARG); } int32_t errCode = 0; @@ -1058,14 +1003,6 @@ ErrCode Service::GetFileHandle(const string &bundleName, const string &fileName) void Service::OnBackupExtensionDied(const string &&bundleName) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - int32_t errCode = static_cast(BError::Codes::EXT_ABILITY_DIED); - if (session_->GetScenario() == IServiceReverse::Scenario::BACKUP) { - Backup::AppRadar::GetInstance().RecordBackUpFuncResWithBundle("Service::OnBackupExtensionDied", - bundleName, GetUserIdDefault(), BizStage::BIZ_STAGE_EXTENSION_STATUS, errCode); - } else if (session_->GetScenario() == IServiceReverse::Scenario::RESTORE) { - AppRadar::GetInstance().RecordRestoreFuncResWithBundle(bundleName, GetUserIdDefault(), "OnBackupExtensionDied", - BizStageRestore::BIZ_STAGE_EXTENSION_STATUS, errCode); - } try { string callName = move(bundleName); HILOGE("Backup <%{public}s> Extension Process Died", callName.c_str()); @@ -1199,13 +1136,6 @@ void Service::ExtConnectFailed(const string &bundleName, ErrCode ret) try { HILOGE("begin %{public}s", bundleName.data()); IServiceReverse::Scenario scenario = session_->GetScenario(); - if (scenario == IServiceReverse::Scenario::BACKUP) { - Backup::AppRadar::GetInstance().RecordBackUpFuncResWithBundle("Service::ExtConnectFailed", - bundleName, GetUserIdDefault(), BizStage::BIZ_STAGE_APPLICATION, ret); - } else if (scenario == IServiceReverse::Scenario::RESTORE) { - AppRadar::GetInstance().RecordRestoreFuncResWithBundle(bundleName, GetUserIdDefault(), - "Service::ExtConnectFailed", BizStageRestore::BIZ_STAGE_CONNECT_BACKUP_EXTENSION, ret); - } if (scenario == IServiceReverse::Scenario::BACKUP && session_->GetIsIncrementalBackup()) { session_->GetServiceReverseProxy()->IncrementalBackupOnBundleStarted(ret, bundleName); } else if (scenario == IServiceReverse::Scenario::RESTORE && @@ -1495,16 +1425,6 @@ void Service::UnloadService() void Service::SessionDeactive() { - IServiceReverse::Scenario scenario = session_->GetScenario(); - if (scenario == IServiceReverse::Scenario::BACKUP) { - AppRadar::GetInstance().RecordBackUpFuncResWithoutBundle("Service::SessionDeactive", - AppRadar::GetInstance().GetUserId(), BizStage::BIZ_STAGE_CLIENT_STATUS, - static_cast(BError::Codes::SA_BROKEN_IPC), "cloud_clone"); - } else if (scenario == IServiceReverse::Scenario::RESTORE) { - AppRadar::GetInstance().RecordRestoreFuncRes(AppRadar::GetInstance().GetUserId(), - "Service::SessionDeactive", BizStageRestore::BIZ_STAGE_CLIENT_STATUS, - static_cast(BError::Codes::SA_BROKEN_IPC)); - } HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); try { HILOGI("Begin"); @@ -1600,8 +1520,6 @@ ErrCode Service::GetBackupInfoCmdHandle(BundleName &bundleName, std::string &res backupConnection->DisconnectBackupExtAbility(); if (ret != ERR_OK) { HILOGE("Call Ext GetBackupInfo faild."); - Backup::AppRadar::GetInstance().RecordBackUpFuncResWithBundle("Service::GetBackupInfoCmdHandle", - bundleName, GetUserIdDefault(), BizStage::BIZ_STAGE_GET_BACKUP_INFO, ret); return BError(BError::Codes::SA_INVAL_ARG); } @@ -1910,15 +1828,6 @@ std::function Service::TimeOutCallback(wptr ptr, std::string bu HILOGE("SessionPtr is nullptr."); return; } - IServiceReverse::Scenario scenario = sessionPtr->GetScenario(); - int32_t errCode = static_cast(BError::Codes::EXT_ABILITY_TIMEOUT); - if (scenario == IServiceReverse::Scenario::BACKUP) { - AppRadar::GetInstance().RecordBackUpFuncResWithBundle("TimeOutCallback", bundleName, GetUserIdDefault(), - BizStage::BIZ_STAGE_ON_BACKUP, errCode); - } else if (scenario == IServiceReverse::Scenario::RESTORE) { - AppRadar::GetInstance().RecordRestoreFuncResWithBundle(bundleName, GetUserIdDefault(), "TimeOutCallback", - BizStageRestore::BIZ_STAGE_EXEC_ON_RESTORE, errCode); - } try { if (SAUtils::IsSABundleName(bundleName)) { auto sessionConnection = sessionPtr->GetSAExtConnection(bundleName); diff --git a/services/backup_sa/src/module_ipc/service_incremental.cpp b/services/backup_sa/src/module_ipc/service_incremental.cpp index 0f5f29345..deb63ff3c 100644 --- a/services/backup_sa/src/module_ipc/service_incremental.cpp +++ b/services/backup_sa/src/module_ipc/service_incremental.cpp @@ -38,7 +38,6 @@ #include "b_json/b_json_entity_caps.h" #include "b_ohos/startup/backup_para.h" #include "b_process/b_multiuser.h" -#include "b_radar/b_radar.h" #include "b_resources/b_constants.h" #include "b_sa/b_sa_utils.h" #include "filemgmt_libhilog.h" @@ -96,7 +95,6 @@ UniqueFd Service::GetLocalCapabilitiesIncremental(const std::vectorIncreaseSessionCnt(); @@ -108,7 +106,6 @@ UniqueFd Service::GetLocalCapabilitiesIncremental(const std::vectorDecreaseSessionCnt(); - GetLocalCapabilitiesRadar("GetLocalCapabilitiesIncremental", ENOENT, "{\"reason\":\"open file failed\"}"); return UniqueFd(-ENOENT); } BJsonCachedEntity cachedEntity(move(fd)); @@ -126,17 +123,14 @@ UniqueFd Service::GetLocalCapabilitiesIncremental(const std::vectorDecreaseSessionCnt(); HILOGE("GetLocalCapabilitiesIncremental failed, errCode = %{public}d", e.GetCode()); - GetLocalCapabilitiesRadar("GetLocalCapabilitiesIncremental", e.GetCode(), "{\"reason\":\"fail\"}"); return UniqueFd(-e.GetCode()); } catch (const exception &e) { session_->DecreaseSessionCnt(); HILOGI("Catched an unexpected low-level exception %{public}s", e.what()); - GetLocalCapabilitiesRadar("GetLocalCapabilitiesIncremental", EPERM, "{\"reason\":\"exception\"}"); return UniqueFd(-EPERM); } catch (...) { session_->DecreaseSessionCnt(); HILOGI("Unexpected exception"); - GetLocalCapabilitiesRadar("GetLocalCapabilitiesIncremental", EPERM, "{\"reason\":\"exception\"}"); return UniqueFd(-EPERM); } } 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 d22b1a5e8..4ad667a9f 100644 --- a/services/backup_sa/src/module_ipc/svc_session_manager.cpp +++ b/services/backup_sa/src/module_ipc/svc_session_manager.cpp @@ -26,7 +26,6 @@ #include "b_file_info.h" #include "b_json/b_json_entity_caps.h" #include "b_json/b_json_entity_ext_manage.h" -#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" @@ -43,19 +42,9 @@ void SvcSessionManager::VerifyCallerAndScenario(uint32_t clientToken, IServiceRe shared_lock lock(lock_); if (impl_.scenario != scenario) { HILOGE("Inconsistent scenario, impl scenario:%{public}d", impl_.scenario); - Backup::AppRadar::GetInstance().RecordBackUpFuncResWithoutBundle( - "SvcSessionManager::VerifyCallerAndScenario", - impl_.userId, BizStage::BIZ_STAGE_PERMISSION_CHECK, - static_cast(BError::Codes::SDK_MIXED_SCENARIO), - "{\"reason\":\"Inconsistent scenario\"}"); throw BError(BError::Codes::SDK_MIXED_SCENARIO); } if (impl_.clientToken != clientToken) { - Backup::AppRadar::GetInstance().RecordBackUpFuncResWithoutBundle( - "SvcSessionManager::VerifyCallerAndScenario", - impl_.userId, BizStage::BIZ_STAGE_PERMISSION_CHECK, - static_cast(BError::Codes::SA_REFUSED_ACT), - "{\"reason\":\"Caller mismatched\"}"); throw BError(BError::Codes::SA_REFUSED_ACT, "Caller mismatched"); } HILOGD("Succeed to verify the caller"); diff --git a/utils/BUILD.gn b/utils/BUILD.gn index 90126bd99..1ff282364 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -74,7 +74,6 @@ ohos_shared_library("backup_utils") { "src/b_process/b_guard_cwd.cpp", "src/b_process/b_guard_signal.cpp", "src/b_process/b_process.cpp", - "src/b_radar/b_radar.cpp", "src/b_sa/b_sa_utils.cpp", "src/b_tarball/b_tarball_cmdline.cpp", "src/b_tarball/b_tarball_factory.cpp", @@ -91,7 +90,6 @@ ohos_shared_library("backup_utils") { "c_utils:utils", "faultloggerd:libdfx_dumpcatcher", "hilog:libhilog", - "hisysevent:libhisysevent", "hitrace:hitrace_meter", "init:libbegetutil", "ipc:ipc_core", @@ -100,7 +98,6 @@ ohos_shared_library("backup_utils") { include_dirs = [ "${path_init}/interfaces/innerkits/include/syspara", "${path_backup}/interfaces/inner_api/native/backup_kit_inner/impl", - "${path_backup}/utils/include", ] deps = [ diff --git a/utils/include/b_radar/b_radar.h b/utils/include/b_radar/b_radar.h deleted file mode 100644 index c6eb1c168..000000000 --- a/utils/include/b_radar/b_radar.h +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_FILEMGMT_BACKUP_B_RADAR_H -#define OHOS_FILEMGMT_BACKUP_B_RADAR_H -#include -#include - -namespace OHOS::FileManagement::Backup { -static std::chrono::time_point g_onBackUpStart; -static std::chrono::time_point g_onRestoreStart; - -enum class BizScene : int32_t { - BACKUP = 1, - RESTORE = 2 -}; - -enum class BizStage : int32_t { - BIZ_STAGE_GET_LOCAL_CAPABILITIES = 1, - BIZ_STAGE_GET_BACKUP_INFO, - BIZ_STAGE_CREATE_SESSION_BACKUP, - BIZ_STAGE_BACKUP_SA, - BIZ_STAGE_APPEND_BUNDLES, - BIZ_STAGE_BACKUP_EXTENSION, - BIZ_STAGE_APPLICATION, - BIZ_STAGE_EXTENSION_STATUS, - BIZ_STAGE_ON_BACKUP, - BIZ_STAGE_DO_BACKUP, - BIZ_STAGE_DATA_CONSISTENCY, - BIZ_STAGE_STATUS_CLEAR, - BIZ_STAGE_CLIENT_STATUS, - BIZ_STAGE_PERMISSION_CHECK -}; - -enum class BizStageRestore : int32_t { - BIZ_STAGE_GET_LOCAL_CAPABILITIES = 1, - BIZ_STAGE_CREATE_SESSION_RESTORE, - BIZ_STAGE_BACKUP_SA, - BIZ_STAGE_APPEND_BUNDLES, - BIZ_STAGE_CONNECT_BACKUP_EXTENSION, - BIZ_STAGE_APPLICATION, - BIZ_STAGE_EXTENSION_STATUS, - BIZ_STAGE_GET_FILE_HANDLE, - BIZ_STAGE_DO_RESTORE, - BIZ_STAGE_DATA_CONSISTENCY, - BIZ_STAGE_EXEC_ON_RESTORE, - BIZ_STAGE_STATUS_CLEAR, - BIZ_STAGE_CLIENT_STATUS, - BIZ_STAGE_PERMISSION_CHECK -}; - -class AppRadar { -public: - static AppRadar &GetInstance() - { - static AppRadar instance; - return instance; - } - -public: - int32_t GetUserId(); - void RecordBackUpFuncResWithBundle(const std::string &func, const std::string &bundleName, int32_t userId, - enum BizStage bizStage, int32_t resultCode, - const std::string &resultInfo = "{\"reason\":\"failed\"}"); - void RecordBackUpFuncResWithoutBundle(const std::string &func, int32_t userId, - enum BizStage bizStage, int32_t resultCode, - const std::string &resultInfo = "{\"reason\":\"failed\"}"); - void RecordDoBackUpRes(const std::string &func, int32_t userId, int32_t resultCode, int32_t exportDuration); - void RecordRestoreFuncRes(int32_t userId, const std::string &func, enum BizStageRestore bizStage, - int32_t resultCode); - void RecordRestoreFuncResWithBundle(const std::string &bundleName, int32_t userId, const std::string &func, - enum BizStageRestore bizStage, int32_t resultCode); - void RecordRestoreFuncResWithResult(const std::string &bundleName, int32_t userId, const std::string &func, - enum BizStageRestore bizStage, int32_t resultCode, - const std::string &resultInfo); - void RecordRestoreFuncResWithStatus(const std::string &bundleName, int32_t userId, const std::string &func, - enum BizStageRestore bizStage, const std::string &execStatus, - int32_t resultCode); - void RecordGetFileHandleRes(const std::string &bundleName, int32_t userId, int32_t resultCode, - const std::string &resultInfo); - void RecordOnRestoreRes(const std::string &bundleName, int32_t userId, const std::string &func, - const std::string &execStatus, int32_t resultCode); - void RecordBackupSARes(int32_t userId, const std::string &func, int32_t resultCode, const std::string &resultInfo); -private: - AppRadar() = default; - ~AppRadar() = default; - AppRadar(const AppRadar &) = delete; - AppRadar &operator=(const AppRadar &) = delete; - AppRadar(AppRadar &&) = delete; - AppRadar &operator=(AppRadar &&) = delete; -}; -} // namespace OHOS::FileManagement::AppRadar -#endif // OHOS_FILEMGMT_BACKUP_B_RADAR_H diff --git a/utils/src/b_radar/b_radar.cpp b/utils/src/b_radar/b_radar.cpp deleted file mode 100644 index 0f4e314d2..000000000 --- a/utils/src/b_radar/b_radar.cpp +++ /dev/null @@ -1,228 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "b_radar/b_radar.h" - -#include -#include -#include - -#include "b_process/b_multiuser.h" -#include "b_resources/b_constants.h" -#include "hisysevent.h" - -namespace { -constexpr uint8_t INDEX = 3; -constexpr int32_t MS_1000 = 1000; -const std::string FILE_BACKUP_EVENTS = "FILE_BACKUP_EVENTS"; -} -namespace OHOS::FileManagement::Backup { -static std::string GetCurrentTime() -{ - 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()); - std::stringstream strTime; - strTime << (std::put_time(std::localtime(&time), "%Y-%m-%d %H:%M:%S:")) << (std::setfill('0')) - << (std::setw(INDEX)) << (ms.count() % MS_1000); - return strTime.str(); -} - -int32_t AppRadar::GetUserId() -{ - auto multiuser = BMultiuser::ParseUid(getuid()); - if ((multiuser.userId == BConstants::SYSTEM_UID) || (multiuser.userId == BConstants::XTS_UID)) { - return BConstants::DEFAULT_USER_ID; - } - return multiuser.userId; -} - -void AppRadar::RecordBackUpFuncResWithBundle(const std::string &func, const std::string &bundleName, - int32_t userId, enum BizStage bizStage, int32_t resultCode, - const std::string &resultInfo) -{ - HiSysEventWrite( - OHOS::HiviewDFX::HiSysEvent::Domain::FILEMANAGEMENT, - FILE_BACKUP_EVENTS, - OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, - "BUNDLE_NAME", bundleName, - "USER_ID", userId, - "PID", getpid(), - "FUNC", func, - "TIME", GetCurrentTime(), - "BIZ_SCENE", static_cast(BizScene::BACKUP), - "BIZ_STAGE", static_cast(bizStage), - "RESULT_CODE", resultCode, - "RESULT_INFO", resultInfo); -} - -void AppRadar::RecordBackUpFuncResWithoutBundle(const std::string &func, int32_t userId, enum BizStage bizStage, - int32_t resultCode, const std::string &resultInfo) -{ - HiSysEventWrite( - OHOS::HiviewDFX::HiSysEvent::Domain::FILEMANAGEMENT, - FILE_BACKUP_EVENTS, - OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, - "USER_ID", userId, - "PID", getpid(), - "FUNC", func, - "TIME", GetCurrentTime(), - "BIZ_SCENE", static_cast(BizScene::BACKUP), - "BIZ_STAGE", static_cast(bizStage), - "RESULT_CODE", resultCode, - "RESULT_INFO", resultInfo); -} - -void AppRadar::RecordDoBackUpRes(const std::string &func, int32_t userId, int32_t resultCode, - int32_t exportDuration) -{ - HiSysEventWrite( - OHOS::HiviewDFX::HiSysEvent::Domain::FILEMANAGEMENT, - FILE_BACKUP_EVENTS, - OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, - "USER_ID", userId, - "PID", getpid(), - "FUNC", func, - "TIME", GetCurrentTime(), - "BIZ_SCENE", static_cast(BizScene::BACKUP), - "BIZ_STAGE", static_cast(BizStage::BIZ_STAGE_DO_BACKUP), - "EXEC_STATUS", "{\"spend_time\":" + std::to_string(exportDuration) + "ms\"}", - "RESULT_CODE", resultCode); -} - -void AppRadar::RecordRestoreFuncRes(int32_t userId, const std::string &func, enum BizStageRestore bizStage, - int32_t resultCode) -{ - HiSysEventWrite( - OHOS::HiviewDFX::HiSysEvent::Domain::FILEMANAGEMENT, - FILE_BACKUP_EVENTS, - OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, - "USER_ID", userId, - "PID", getpid(), - "FUNC", func, - "TIME", GetCurrentTime(), - "BIZ_SCENE", static_cast(BizScene::RESTORE), - "BIZ_STAGE", static_cast(bizStage), - "RESULT_CODE", resultCode); -} - -void AppRadar::RecordRestoreFuncResWithBundle(const std::string &bundleName, int32_t userId, const std::string &func, - enum BizStageRestore bizStage, int32_t resultCode) -{ - HiSysEventWrite( - OHOS::HiviewDFX::HiSysEvent::Domain::FILEMANAGEMENT, - FILE_BACKUP_EVENTS, - OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, - "BUNDLE_NAME", bundleName, - "USER_ID", userId, - "PID", getpid(), - "FUNC", func, - "TIME", GetCurrentTime(), - "BIZ_SCENE", static_cast(BizScene::RESTORE), - "BIZ_STAGE", static_cast(bizStage), - "RESULT_CODE", resultCode); -} - -void AppRadar::RecordRestoreFuncResWithResult(const std::string &bundleName, int32_t userId, const std::string &func, - enum BizStageRestore bizStage, int32_t resultCode, - const std::string &resultInfo) -{ - HiSysEventWrite( - OHOS::HiviewDFX::HiSysEvent::Domain::FILEMANAGEMENT, - FILE_BACKUP_EVENTS, - OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, - "BUNDLE_NAME", bundleName, - "USER_ID", userId, - "PID", getpid(), - "FUNC", func, - "TIME", GetCurrentTime(), - "BIZ_SCENE", static_cast(BizScene::RESTORE), - "BIZ_STAGE", static_cast(bizStage), - "RESULT_CODE", resultCode, - "RESULT_INFO", resultInfo); -} - -void AppRadar::RecordRestoreFuncResWithStatus(const std::string &bundleName, int32_t userId, const std::string &func, - enum BizStageRestore bizStage, const std::string &execStatus, - int32_t resultCode) -{ - HiSysEventWrite( - OHOS::HiviewDFX::HiSysEvent::Domain::FILEMANAGEMENT, - FILE_BACKUP_EVENTS, - OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, - "BUNDLE_NAME", bundleName, - "USER_ID", userId, - "PID", getpid(), - "FUNC", func, - "TIME", GetCurrentTime(), - "BIZ_SCENE", static_cast(BizScene::RESTORE), - "BIZ_STAGE", static_cast(bizStage), - "EXEC_STATUS", execStatus, - "RESULT_CODE", resultCode); -} - -void AppRadar::RecordGetFileHandleRes(const std::string &bundleName, int32_t userId, int32_t resultCode, - const std::string &resultInfo) -{ - HiSysEventWrite( - OHOS::HiviewDFX::HiSysEvent::Domain::FILEMANAGEMENT, - FILE_BACKUP_EVENTS, - OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, - "BUNDLE_NAME", bundleName, - "USER_ID", userId, - "PID", getpid(), - "FUNC", "GetFileHandle", - "TIME", GetCurrentTime(), - "BIZ_SCENE", static_cast(BizScene::RESTORE), - "BIZ_STAGE", static_cast(BizStageRestore::BIZ_STAGE_GET_FILE_HANDLE), - "RESULT_CODE", resultCode, - "RESULT_INFO", resultInfo); -} - -void AppRadar::RecordOnRestoreRes(const std::string &bundleName, int32_t userId, const std::string &func, - const std::string &execStatus, int32_t resultCode) -{ - HiSysEventWrite( - OHOS::HiviewDFX::HiSysEvent::Domain::FILEMANAGEMENT, - FILE_BACKUP_EVENTS, - OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, - "BUNDLE_NAME", bundleName, - "USER_ID", userId, - "PID", getpid(), - "FUNC", func, - "TIME", GetCurrentTime(), - "BIZ_SCENE", static_cast(BizScene::RESTORE), - "BIZ_STAGE", static_cast(BizStageRestore::BIZ_STAGE_EXEC_ON_RESTORE), - "EXEC_STATUS", execStatus, - "RESULT_CODE", resultCode); -} - -void AppRadar::RecordBackupSARes(int32_t userId, const std::string &func, int32_t resultCode, - const std::string &resultInfo) -{ - HiSysEventWrite( - OHOS::HiviewDFX::HiSysEvent::Domain::FILEMANAGEMENT, - FILE_BACKUP_EVENTS, - OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, - "USER_ID", userId, - "PID", getpid(), - "FUNC", func, - "TIME", GetCurrentTime(), - "BIZ_SCENE", static_cast(BizScene::RESTORE), - "BIZ_STAGE", static_cast(BizStageRestore::BIZ_STAGE_BACKUP_SA), - "RESULT_CODE", resultCode, - "RESULT_INFO", resultInfo); -} -} // namespace OHOS::FileManagement::Backup \ No newline at end of file -- Gitee From 3058b496d0462c6d414b481605a06a1a60cc14bb Mon Sep 17 00:00:00 2001 From: zhangyaomaggie Date: Tue, 27 Aug 2024 11:19:01 +0800 Subject: [PATCH 3/3] add radar for backup Signed-off-by: zhangyaomaggie --- .../native/backup_ext/include/ext_extension.h | 4 + .../native/backup_ext/src/ext_extension.cpp | 23 +++++ .../backup_ext/src/sub_ext_extension.cpp | 41 ++++++++ .../src/b_incremental_backup_session.cpp | 28 +++++- .../backup_kit_inner/src/b_session_backup.cpp | 28 +++++- .../backup_kit_inner/src/service_proxy.cpp | 17 +++- .../native/backup_kit_inner/BUILD.gn | 1 + .../backup_sa/include/module_ipc/service.h | 2 + .../app_gallery_dispose_proxy.cpp | 9 +- services/backup_sa/src/module_ipc/service.cpp | 56 +++++++++++ .../src/module_ipc/service_incremental.cpp | 6 ++ .../src/module_ipc/svc_session_manager.cpp | 7 ++ utils/BUILD.gn | 3 + utils/include/b_radar/b_radar.h | 93 +++++++++++++++++++ utils/include/b_resources/b_constants.h | 5 + utils/include/b_utils/b_time.h | 1 + utils/src/b_radar/b_radar.cpp | 93 +++++++++++++++++++ utils/src/b_utils/b_time.cpp | 15 +++ 18 files changed, 419 insertions(+), 13 deletions(-) create mode 100644 utils/include/b_radar/b_radar.h create mode 100644 utils/src/b_radar/b_radar.cpp diff --git a/frameworks/native/backup_ext/include/ext_extension.h b/frameworks/native/backup_ext/include/ext_extension.h index 9556c8c29..cd342d93a 100644 --- a/frameworks/native/backup_ext/include/ext_extension.h +++ b/frameworks/native/backup_ext/include/ext_extension.h @@ -256,6 +256,8 @@ private: void SyncCallJsOnProcessTask(wptr obj, BackupRestoreScenario scenario); void StartOnProcessTimeOutTimer(wptr obj, BackupRestoreScenario scenario); void CloseOnProcessTimeOutTimer(); + void UpdateOnBackUpTime(); + int32_t GetOnBackupTimeCost(); private: std::shared_mutex lock_; @@ -283,6 +285,8 @@ private: std::condition_variable execOnProcessCon_; std::mutex onProcessLock_; std::atomic onProcessTimeout_ {false}; + std::chrono::time_point g_onBackUpStart; + std::mutex onBackupTimeLock_; }; } // namespace OHOS::FileManagement::Backup diff --git a/frameworks/native/backup_ext/src/ext_extension.cpp b/frameworks/native/backup_ext/src/ext_extension.cpp index 2d836e2b9..587dfa95d 100644 --- a/frameworks/native/backup_ext/src/ext_extension.cpp +++ b/frameworks/native/backup_ext/src/ext_extension.cpp @@ -47,6 +47,7 @@ #include "b_json/b_json_cached_entity.h" #include "b_jsonutil/b_jsonutil.h" #include "b_ohos/startup/backup_para.h" +#include "b_radar/b_radar.h" #include "b_tarball/b_tarball_factory.h" #include "filemgmt_libhilog.h" #include "hitrace_meter.h" @@ -126,10 +127,18 @@ void BackupExtExtension::VerifyCaller() uint32_t tokenCaller = IPCSkeleton::GetCallingTokenID(); int tokenType = Security::AccessToken::AccessTokenKit::GetTokenType(tokenCaller); if (tokenType != Security::AccessToken::ATokenTypeEnum::TOKEN_NATIVE) { + AppRadar::Info info("", "", "{\"reason\":\"Calling tokenType error\"}"); + AppRadar::GetInstance().RecordDefaultFuncRes( + info, "BackupExtExtension::VerifyCaller", AppRadar::GetInstance().GetUserId(), + BizStageBackup::BIZ_STAGE_PERMISSION_CHECK, static_cast(BError::Codes::SA_REFUSED_ACT)); throw BError(BError::Codes::EXT_BROKEN_IPC, string("Calling tokenType is error, token type is ").append(to_string(tokenType))); } if (IPCSkeleton::GetCallingUid() != BConstants::BACKUP_UID) { + AppRadar::Info info("", "", "{\"reason\":\"Calling uid invalid\"}"); + AppRadar::GetInstance().RecordDefaultFuncRes( + info, "BackupExtExtension::VerifyCaller", AppRadar::GetInstance().GetUserId(), + BizStageBackup::BIZ_STAGE_PERMISSION_CHECK, static_cast(BError::Codes::SA_REFUSED_ACT)); throw BError(BError::Codes::EXT_BROKEN_IPC, string("Calling uid is invalid, calling uid is ").append(to_string(IPCSkeleton::GetCallingUid()))); } @@ -826,7 +835,13 @@ void BackupExtExtension::AsyncTaskBackup(const string config) HILOGI("Do backup, start fwk timer end."); BJsonCachedEntity cachedEntity(config); auto cache = cachedEntity.Structuralize(); + auto start = std::chrono::system_clock::now(); auto ret = ptr->DoBackup(cache); + auto end = std::chrono::system_clock::now(); + auto cost = to_string(std::chrono::duration_cast(end - start).count()); + AppRadar::Info info(ptr->bundleName_, "", string("{\"spend_time\":").append(cost).append(string("ms\"}"))); + AppRadar::GetInstance().RecordBackupFuncRes(info, "BackupExtExtension::AsyncTaskBackup", + AppRadar::GetInstance().GetUserId(), BizStageBackup::BIZ_STAGE_DO_BACKUP, static_cast(ret)); // REM: 处理返回结果 ret ptr->AppDone(ret); HILOGI("backup app done %{public}d", ret); @@ -1483,6 +1498,12 @@ void BackupExtExtension::StartFwkTimer(bool &isFwkStart) } } +void BackupExtExtension::UpdateOnBackUpTime() +{ + std::lock_guard lock(onBackupTimeLock_); + g_onBackUpStart = std::chrono::system_clock::now(); +} + void BackupExtExtension::AsyncTaskOnBackup() { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); @@ -1494,6 +1515,7 @@ void BackupExtExtension::AsyncTaskOnBackup() ptr->StartOnProcessTaskThread(obj, BackupRestoreScenario::FULL_BACKUP); auto callBackup = ptr->OnBackupCallback(obj); auto callBackupEx = ptr->OnBackupExCallback(obj); + ptr->UpdateOnBackUpTime(); ErrCode err = ptr->extension_->OnBackup(callBackup, callBackupEx); if (err != ERR_OK) { HILOGE("OnBackup done, err = %{pubilc}d", err); @@ -1879,6 +1901,7 @@ void BackupExtExtension::AsyncTaskOnIncrementalBackup() ptr->StartOnProcessTaskThread(obj, BackupRestoreScenario::INCREMENTAL_BACKUP); auto callBackup = ptr->IncOnBackupCallback(obj); auto callBackupEx = ptr->IncOnBackupExCallback(obj); + ptr->UpdateOnBackUpTime(); ErrCode err = ptr->extension_->OnBackup(callBackup, callBackupEx); if (err != ERR_OK) { HILOGE("OnBackup done, err = %{pubilc}d", err); diff --git a/frameworks/native/backup_ext/src/sub_ext_extension.cpp b/frameworks/native/backup_ext/src/sub_ext_extension.cpp index 55ed437d3..e6e93ca2a 100644 --- a/frameworks/native/backup_ext/src/sub_ext_extension.cpp +++ b/frameworks/native/backup_ext/src/sub_ext_extension.cpp @@ -47,6 +47,7 @@ #include "b_json/b_json_cached_entity.h" #include "b_jsonutil/b_jsonutil.h" #include "b_ohos/startup/backup_para.h" +#include "b_radar/b_radar.h" #include "b_tarball/b_tarball_factory.h" #include "filemgmt_libhilog.h" #include "hitrace_meter.h" @@ -365,6 +366,14 @@ std::function BackupExtExtension::IncreOnRestoreCall }; } +int32_t BackupExtExtension::GetOnBackupTimeCost() +{ + auto onBackUpEnd = std::chrono::system_clock::now(); + std::lock_guard lock(onBackupTimeLock_); + auto ms = std::chrono::duration_cast(onBackUpEnd - g_onBackUpStart).count(); + return ms; +} + std::function BackupExtExtension::OnBackupCallback(wptr obj) { HILOGI("Begin get HandleFullBackupCallbackEx"); @@ -379,6 +388,14 @@ std::function BackupExtExtension::OnBackupCall HILOGE("Extension handle have been released"); return; } + if (errCode == ERR_OK) { + auto ms = extensionPtr->GetOnBackupTimeCost(); + AppRadar::Info info(extensionPtr->bundleName_, "", string("{\"spend_time\":\" "). + append(to_string(ms)).append(string("ms\"}"))); + AppRadar::GetInstance().RecordBackupFuncRes(info, "BackupExtExtension::OnBackupCallback", + AppRadar::GetInstance().GetUserId(), BizStageBackup::BIZ_STAGE_ON_BACKUP, + static_cast(ERR_OK)); + } extensionPtr->FinishOnProcessTask(); extensionPtr->AsyncTaskBackup(extensionPtr->extension_->GetUsrConfig()); }; @@ -398,6 +415,14 @@ std::function BackupExtExtension::OnBackupExCa HILOGE("Extension handle have been released"); return; } + if (errCode == ERR_OK && !backupExRetInfo.empty()) { + auto ms = extensionPtr->GetOnBackupTimeCost(); + AppRadar::Info info(extensionPtr->bundleName_, "", string("{\"spend_time\":\" "). + append(to_string(ms)).append(string("ms\"}"))); + AppRadar::GetInstance().RecordBackupFuncRes(info, "BackupExtExtension::OnBackupExCallback", + AppRadar::GetInstance().GetUserId(), BizStageBackup::BIZ_STAGE_ON_BACKUP, + static_cast(ERR_OK)); + } extensionPtr->extension_->InvokeAppExtMethod(errCode, backupExRetInfo); if (backupExRetInfo.size()) { HILOGI("Will notify backup result report"); @@ -423,6 +448,14 @@ std::function BackupExtExtension::IncOnBackupC return; } HILOGI("Start GetAppLocalListAndDoIncrementalBackup"); + if (errCode == ERR_OK) { + auto ms = extPtr->GetOnBackupTimeCost(); + AppRadar::Info info(extPtr->bundleName_, "", string("{\"spend_time\":\" "). + append(to_string(ms)).append(string("ms\"}"))); + AppRadar::GetInstance().RecordBackupFuncRes(info, "BackupExtExtension::IncOnBackupCallback", + AppRadar::GetInstance().GetUserId(), BizStageBackup::BIZ_STAGE_ON_BACKUP, + static_cast(ERR_OK)); + } extPtr->FinishOnProcessTask(); proxy->GetAppLocalListAndDoIncrementalBackup(); }; @@ -445,6 +478,14 @@ std::function BackupExtExtension::IncOnBackupE HILOGE("Extension handle have been released"); return; } + if (errCode == ERR_OK && !backupExRetInfo.empty()) { + auto ms = extensionPtr->GetOnBackupTimeCost(); + AppRadar::Info info(extensionPtr->bundleName_, "", string("{\"spend_time\":\" "). + append(to_string(ms)).append(string("ms\"}"))); + AppRadar::GetInstance().RecordBackupFuncRes(info, "BackupExtExtension::IncOnBackupExCallback", + AppRadar::GetInstance().GetUserId(), BizStageBackup::BIZ_STAGE_ON_BACKUP, + static_cast(ERR_OK)); + } extensionPtr->extension_->InvokeAppExtMethod(errCode, backupExRetInfo); if (backupExRetInfo.size()) { HILOGI("Start GetAppLocalListAndDoIncrementalBackup"); 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 f747d28c7..f1911b97d 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 @@ -16,6 +16,7 @@ #include "b_incremental_backup_session.h" #include "b_error/b_error.h" +#include "b_radar/b_radar.h" #include "filemgmt_libhilog.h" #include "service_proxy.h" #include "service_reverse.h" @@ -55,6 +56,9 @@ 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_SESSION_BACKUP, res); return nullptr; } @@ -93,7 +97,17 @@ ErrCode BIncrementalBackupSession::AppendBundles(vector bundle return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } - return proxy->AppendBundlesIncrementalBackupSession(bundlesToBackup); + int32_t 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::GetInstance().RecordBackupFuncRes(info, "BIncrementalBackupSession::AppendBundles", + AppRadar::GetInstance().GetUserId(), BizStageBackup::BIZ_STAGE_APPEND_BUNDLES, res); + } + return res; } ErrCode BIncrementalBackupSession::AppendBundles(vector bundlesToBackup, @@ -104,7 +118,17 @@ ErrCode BIncrementalBackupSession::AppendBundles(vector bundle return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } - return proxy->AppendBundlesIncrementalBackupSession(bundlesToBackup, infos); + 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::GetInstance().RecordBackupFuncRes(info, "BIncrementalBackupSession::AppendBundles", + AppRadar::GetInstance().GetUserId(), BizStageBackup::BIZ_STAGE_APPEND_BUNDLES, res); + } + return res; } ErrCode BIncrementalBackupSession::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 04176686b..f8884df77 100644 --- a/frameworks/native/backup_kit_inner/src/b_session_backup.cpp +++ b/frameworks/native/backup_kit_inner/src/b_session_backup.cpp @@ -16,6 +16,7 @@ #include "b_session_backup.h" #include "b_error/b_error.h" +#include "b_radar/b_radar.h" #include "filemgmt_libhilog.h" #include "service_proxy.h" #include "service_reverse.h" @@ -55,6 +56,9 @@ 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_SESSION_BACKUP, res); return nullptr; } @@ -103,7 +107,17 @@ ErrCode BSessionBackup::AppendBundles(vector bundlesToBackup) return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } - return proxy->AppendBundlesBackupSession(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::GetInstance().RecordBackUpFunc(info, "BSessionBackup::AppendBundles", + AppRadar::GetInstance().GetUserId(), BizStageBackup::BIZ_STAGE_APPEND_BUNDLES, res); + } + return res; } ErrCode BSessionBackup::AppendBundles(vector bundlesToBackup, vector detailInfos) @@ -113,7 +127,17 @@ ErrCode BSessionBackup::AppendBundles(vector bundlesToBackup, vector return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } - return proxy->AppendBundlesDetailsBackupSession(bundlesToBackup, detailInfos); + 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::GetInstance().RecordBackupFuncRes(info, "BSessionBackup::AppendBundles", + AppRadar::GetInstance().GetUserId(), BizStageBackup::BIZ_STAGE_APPEND_BUNDLES, res); + } + return res; } ErrCode BSessionBackup::Finish() diff --git a/frameworks/native/backup_kit_inner/src/service_proxy.cpp b/frameworks/native/backup_kit_inner/src/service_proxy.cpp index 1870448e3..9c1acf11e 100644 --- a/frameworks/native/backup_kit_inner/src/service_proxy.cpp +++ b/frameworks/native/backup_kit_inner/src/service_proxy.cpp @@ -13,15 +13,16 @@ * limitations under the License. */ -#include "service_proxy.h" - -#include "iservice_registry.h" -#include "system_ability_definition.h" +#include #include "b_error/b_error.h" #include "b_error/b_excep_utils.h" +#include "b_radar/b_radar.h" #include "b_resources/b_constants.h" #include "filemgmt_libhilog.h" +#include "iservice_registry.h" +#include "service_proxy.h" +#include "system_ability_definition.h" #include "svc_death_recipient.h" #include "hitrace_meter.h" @@ -446,6 +447,10 @@ sptr ServiceProxy::GetInstance() [loadCallback]() { return loadCallback->isLoadSuccess_.load(); }); if (!waitStatus) { HILOGE("Load backup sa timeout"); + AppRadar::Info info("", "", "{\"reason\":\"Load backup sa timeout\"}"); + AppRadar::GetInstance().RecordBackupFuncRes(info, "ServiceProxy::GetInstance", + AppRadar::GetInstance().GetUserId(), BizStageBackup::BIZ_STAGE_BACKUP_SA, + static_cast(BError::Codes::SA_INVAL_ARG)); return nullptr; } return serviceProxy_; @@ -502,6 +507,10 @@ void ServiceProxy::ServiceProxyLoadCallback::OnLoadSystemAbilityFail(int32_t sys unique_lock lock(proxyMutex_); serviceProxy_ = nullptr; isLoadSuccess_.store(false); + AppRadar::Info info("", "", "{\"reason\":\"Load backup sa fail\"}"); + AppRadar::GetInstance().RecordBackupFuncRes(info, "ServiceProxyLoadCallback::OnLoadSystemAbilityFail", + AppRadar::GetInstance().GetUserId(), BizStageBackup::BIZ_STAGE_BACKUP_SA, + static_cast(BError::Codes::SA_INVAL_ARG)); proxyConVar_.notify_one(); } diff --git a/interfaces/inner_api/native/backup_kit_inner/BUILD.gn b/interfaces/inner_api/native/backup_kit_inner/BUILD.gn index c84d227f2..2ee1a876d 100644 --- a/interfaces/inner_api/native/backup_kit_inner/BUILD.gn +++ b/interfaces/inner_api/native/backup_kit_inner/BUILD.gn @@ -27,6 +27,7 @@ config("private_config") { "${path_backup}/frameworks/native/backup_kit_inner/include", "${path_backup}/interfaces/inner_api/native/backup_kit_inner", "${path_backup}/interfaces/inner_api/native/backup_kit_inner/impl", + "${path_backup}/utils/include", ] } diff --git a/services/backup_sa/include/module_ipc/service.h b/services/backup_sa/include/module_ipc/service.h index fa1da2e93..1ac323e09 100644 --- a/services/backup_sa/include/module_ipc/service.h +++ b/services/backup_sa/include/module_ipc/service.h @@ -91,6 +91,8 @@ public: void OnStop() override; void StopAll(const wptr &obj, bool force = false); int Dump(int fd, const std::vector &args) override; + void GetLocalCapabilitiesRadar(const std::string &func, int32_t resultCode, + const std::string &info); /** * @brief 执行启动 backup extension 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 f49ed5bd3..f9436fb51 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 @@ -13,15 +13,14 @@ * limitations under the License. */ -#include "module_app_gallery/app_gallery_dispose_proxy.h" - #include +#include "b_radar/b_radar.h" +#include "filemgmt_libhilog.h" #include "message_parcel.h" -#include "want.h" - +#include "module_app_gallery/app_gallery_dispose_proxy.h" #include "module_app_gallery/app_gallery_service_connection.h" -#include "filemgmt_libhilog.h" +#include "want.h" namespace OHOS::FileManagement::Backup { using namespace std; diff --git a/services/backup_sa/src/module_ipc/service.cpp b/services/backup_sa/src/module_ipc/service.cpp index 6e834db31..dfa71c871 100644 --- a/services/backup_sa/src/module_ipc/service.cpp +++ b/services/backup_sa/src/module_ipc/service.cpp @@ -47,6 +47,7 @@ #include "b_jsonutil/b_jsonutil.h" #include "b_ohos/startup/backup_para.h" #include "b_process/b_multiuser.h" +#include "b_radar/b_radar.h" #include "b_resources/b_constants.h" #include "b_sa/b_sa_utils.h" #include "bundle_mgr_client.h" @@ -138,6 +139,15 @@ void Service::OnStop() HILOGI("SA OnStop End."); } +void Service::GetLocalCapabilitiesRadar(const std::string &func, int32_t resultCode, + const std::string &info) +{ + std::string funcPos = "Service::"; + AppRadar::Info resInfo("", "", info); + AppRadar::GetInstance().RecordDefaultFuncRes(resInfo, funcPos.append(func), GetUserIdDefault(), + BizStageBackup::BIZ_STAGE_GET_LOCAL_CAPABILITIES, resultCode); +} + UniqueFd Service::GetLocalCapabilities() { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); @@ -149,6 +159,7 @@ UniqueFd Service::GetLocalCapabilities() HILOGI("Begin"); if (session_ == nullptr) { HILOGE("GetLocalCapabilities error, session is empty."); + GetLocalCapabilitiesRadar("GetLocalCapabilities", EPERM, "{\"reason\":\"session empty\"}"); return UniqueFd(-EPERM); } session_->IncreaseSessionCnt(); @@ -160,6 +171,8 @@ UniqueFd Service::GetLocalCapabilities() if (fd < 0) { HILOGE("Failed to open config file = %{private}s, err = %{public}d", path.c_str(), errno); session_->DecreaseSessionCnt(); + GetLocalCapabilitiesRadar("GetLocalCapabilities", EPERM, + "{\"reason\":\"failed to open config file\"}"); return UniqueFd(-EPERM); } BJsonCachedEntity cachedEntity(std::move(fd)); @@ -177,14 +190,17 @@ UniqueFd Service::GetLocalCapabilities() } catch (const BError &e) { session_->DecreaseSessionCnt(); HILOGE("GetLocalCapabilities failed, errCode = %{public}d", e.GetCode()); + GetLocalCapabilitiesRadar("GetLocalCapabilities", e.GetCode(), "{\"reason\":\"failed\"}"); return UniqueFd(-e.GetCode()); } catch (const exception &e) { session_->DecreaseSessionCnt(); HILOGI("Catched an unexpected low-level exception %{public}s", e.what()); + GetLocalCapabilitiesRadar("GetLocalCapabilities", EPERM, "{\"reason\":\"exception\"}"); return UniqueFd(-EPERM); } catch (...) { session_->DecreaseSessionCnt(); HILOGI("Unexpected exception"); + GetLocalCapabilitiesRadar("GetLocalCapabilities", EPERM, "{\"reason\":\"exception\"}"); return UniqueFd(-EPERM); } } @@ -195,6 +211,15 @@ void Service::StopAll(const wptr &obj, bool force) session_->Deactive(obj, force); } +static inline void PermissionCheckFailRadar(const std::string &info, const std::string &func) +{ + std::string funcPos = "Service::"; + AppRadar::Info resInfo("", "", info); + AppRadar::GetInstance().RecordDefaultFuncRes(resInfo, funcPos.append(func), + GetUserIdDefault(), BizStageBackup::BIZ_STAGE_PERMISSION_CHECK, + static_cast(BError::Codes::SA_REFUSED_ACT)); +} + string Service::VerifyCallerAndGetCallerName() { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); @@ -203,6 +228,7 @@ string Service::VerifyCallerAndGetCallerName() if (tokenType == Security::AccessToken::ATokenTypeEnum::TOKEN_HAP) { Security::AccessToken::HapTokenInfo hapTokenInfo; if (Security::AccessToken::AccessTokenKit::GetHapTokenInfo(tokenCaller, hapTokenInfo) != 0) { + PermissionCheckFailRadar("{\"reason\":\"Get hap token info failed\"}", "VerifyCallerAndGetCallerName"); throw BError(BError::Codes::SA_INVAL_ARG, "Get hap token info failed"); } std::string bundleNameIndexInfo = BJsonUtil::BuildBundleNameIndexInfo(hapTokenInfo.bundleName, @@ -212,6 +238,9 @@ string Service::VerifyCallerAndGetCallerName() } else { string str = to_string(tokenCaller); HILOGE("tokenID = %{private}s", GetAnonyString(str).c_str()); + PermissionCheckFailRadar( + string("{\"reason\":\"Invalid token type ").append(to_string(tokenType)).append(string("\"}")), + "VerifyCallerAndGetCallerName"); throw BError(BError::Codes::SA_INVAL_ARG, string("Invalid token type ").append(to_string(tokenType))); } } @@ -225,6 +254,8 @@ void Service::VerifyCaller() case Security::AccessToken::ATokenTypeEnum::TOKEN_NATIVE: { /* Update Service */ if (Security::AccessToken::AccessTokenKit::VerifyAccessToken(tokenCaller, BACKUP_PERMISSION) != Security::AccessToken::PermissionState::PERMISSION_GRANTED) { + std::string info = "{\"reason\":\"Permission denied, token type is " + to_string(tokenType) + "\"}"; + PermissionCheckFailRadar(info, "VerifyCaller"); throw BError(BError::Codes::SA_REFUSED_ACT, string("Permission denied, token type is ").append(to_string(tokenType))); } @@ -233,11 +264,15 @@ void Service::VerifyCaller() case Security::AccessToken::ATokenTypeEnum::TOKEN_HAP: { if (Security::AccessToken::AccessTokenKit::VerifyAccessToken(tokenCaller, BACKUP_PERMISSION) != Security::AccessToken::PermissionState::PERMISSION_GRANTED) { + std::string info = "{\"reason\":\"Permission denied, token type is " + to_string(tokenType) + "\"}"; + PermissionCheckFailRadar(info, "VerifyCaller"); throw BError(BError::Codes::SA_REFUSED_ACT, string("Permission denied, token type is ").append(to_string(tokenType))); } uint64_t fullTokenId = OHOS::IPCSkeleton::GetCallingFullTokenID(); if (!Security::AccessToken::TokenIdKit::IsSystemAppByFullTokenID(fullTokenId)) { + std::string info = "{\"reason\":\"Permission denied, token type is " + to_string(tokenType) + "\"}"; + PermissionCheckFailRadar(info, "VerifyCaller"); throw BError(BError::Codes::SA_REFUSED_ACT, string("Permission denied, token type is ").append(to_string(tokenType))); } @@ -245,10 +280,14 @@ void Service::VerifyCaller() } case Security::AccessToken::ATokenTypeEnum::TOKEN_SHELL: if (IPCSkeleton::GetCallingUid() != BConstants::SYSTEM_UID) { + std::string info = "{\"reason\":\"invalid calling uid\"}"; + PermissionCheckFailRadar(info, "VerifyCaller"); throw BError(BError::Codes::SA_REFUSED_ACT, "Calling uid is invalid"); } break; default: + std::string info = "{\"reason\":\"Permission denied, token type is " + to_string(tokenType) + "\"}"; + PermissionCheckFailRadar(info, "VerifyCaller"); throw BError(BError::Codes::SA_REFUSED_ACT, string("Invalid token type ").append(to_string(tokenType))); break; } @@ -1426,6 +1465,13 @@ void Service::UnloadService() void Service::SessionDeactive() { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + IServiceReverse::Scenario scenario = session_->GetScenario(); + if (scenario == IServiceReverse::Scenario::BACKUP) { + AppRadar::Info info("", "", "cloud_clone"); + AppRadar::GetInstance().RecordBackupFuncRes(info, "Service::SessionDeactive", + AppRadar::GetInstance().GetUserId(), BizStageBackup::BIZ_STAGE_CLIENT_STATUS, + static_cast(BError::Codes::SA_BROKEN_IPC)); + } try { HILOGI("Begin"); //清理处置状态 @@ -1520,6 +1566,9 @@ ErrCode Service::GetBackupInfoCmdHandle(BundleName &bundleName, std::string &res backupConnection->DisconnectBackupExtAbility(); if (ret != ERR_OK) { HILOGE("Call Ext GetBackupInfo faild."); + AppRadar::Info info(bundleName); + Backup::AppRadar::GetInstance().RecordBackupFuncRes(info, "Service::GetBackupInfoCmdHandle", + GetUserIdDefault(), BizStageBackup::BIZ_STAGE_GET_BACKUP_INFO, ret); return BError(BError::Codes::SA_INVAL_ARG); } @@ -1828,6 +1877,13 @@ std::function Service::TimeOutCallback(wptr ptr, std::string bu HILOGE("SessionPtr is nullptr."); return; } + IServiceReverse::Scenario scenario = sessionPtr->GetScenario(); + int32_t errCode = static_cast(BError::Codes::EXT_ABILITY_TIMEOUT); + if (scenario == IServiceReverse::Scenario::BACKUP) { + AppRadar::Info info(bundleName); + AppRadar::GetInstance().RecordBackupFuncRes(info, "TimeOutCallback", + GetUserIdDefault(), BizStageBackup::BIZ_STAGE_ON_BACKUP, errCode); + } try { if (SAUtils::IsSABundleName(bundleName)) { auto sessionConnection = sessionPtr->GetSAExtConnection(bundleName); diff --git a/services/backup_sa/src/module_ipc/service_incremental.cpp b/services/backup_sa/src/module_ipc/service_incremental.cpp index deb63ff3c..0f5f29345 100644 --- a/services/backup_sa/src/module_ipc/service_incremental.cpp +++ b/services/backup_sa/src/module_ipc/service_incremental.cpp @@ -38,6 +38,7 @@ #include "b_json/b_json_entity_caps.h" #include "b_ohos/startup/backup_para.h" #include "b_process/b_multiuser.h" +#include "b_radar/b_radar.h" #include "b_resources/b_constants.h" #include "b_sa/b_sa_utils.h" #include "filemgmt_libhilog.h" @@ -95,6 +96,7 @@ UniqueFd Service::GetLocalCapabilitiesIncremental(const std::vectorIncreaseSessionCnt(); @@ -106,6 +108,7 @@ UniqueFd Service::GetLocalCapabilitiesIncremental(const std::vectorDecreaseSessionCnt(); + GetLocalCapabilitiesRadar("GetLocalCapabilitiesIncremental", ENOENT, "{\"reason\":\"open file failed\"}"); return UniqueFd(-ENOENT); } BJsonCachedEntity cachedEntity(move(fd)); @@ -123,14 +126,17 @@ UniqueFd Service::GetLocalCapabilitiesIncremental(const std::vectorDecreaseSessionCnt(); HILOGE("GetLocalCapabilitiesIncremental failed, errCode = %{public}d", e.GetCode()); + GetLocalCapabilitiesRadar("GetLocalCapabilitiesIncremental", e.GetCode(), "{\"reason\":\"fail\"}"); return UniqueFd(-e.GetCode()); } catch (const exception &e) { session_->DecreaseSessionCnt(); HILOGI("Catched an unexpected low-level exception %{public}s", e.what()); + GetLocalCapabilitiesRadar("GetLocalCapabilitiesIncremental", EPERM, "{\"reason\":\"exception\"}"); return UniqueFd(-EPERM); } catch (...) { session_->DecreaseSessionCnt(); HILOGI("Unexpected exception"); + GetLocalCapabilitiesRadar("GetLocalCapabilitiesIncremental", EPERM, "{\"reason\":\"exception\"}"); return UniqueFd(-EPERM); } } 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 4ad667a9f..45803f6ae 100644 --- a/services/backup_sa/src/module_ipc/svc_session_manager.cpp +++ b/services/backup_sa/src/module_ipc/svc_session_manager.cpp @@ -26,6 +26,7 @@ #include "b_file_info.h" #include "b_json/b_json_entity_caps.h" #include "b_json/b_json_entity_ext_manage.h" +#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" @@ -42,9 +43,15 @@ void SvcSessionManager::VerifyCallerAndScenario(uint32_t clientToken, IServiceRe shared_lock lock(lock_); if (impl_.scenario != scenario) { HILOGE("Inconsistent scenario, impl scenario:%{public}d", impl_.scenario); + AppRadar::Info info("", "", "{\"reason\":\"Inconsistent scenario\"}"); + AppRadar::GetInstance().RecordDefaultFuncRes(info, "SvcSessionManager::VerifyCallerAndScenario", impl_.userId, + BizStageBackup::BIZ_STAGE_PERMISSION_CHECK, static_cast(BError::Codes::SDK_MIXED_SCENARIO)); throw BError(BError::Codes::SDK_MIXED_SCENARIO); } if (impl_.clientToken != clientToken) { + AppRadar::Info info2("", "", "{\"reason\":\"Caller mismatched\"}"); + AppRadar::GetInstance().RecordDefaultFuncRes(info2, "SvcSessionManager::VerifyCallerAndScenario", impl_.userId, + BizStageBackup::BIZ_STAGE_PERMISSION_CHECK, static_cast(BError::Codes::SDK_MIXED_SCENARIO)); throw BError(BError::Codes::SA_REFUSED_ACT, "Caller mismatched"); } HILOGD("Succeed to verify the caller"); diff --git a/utils/BUILD.gn b/utils/BUILD.gn index 1ff282364..90126bd99 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -74,6 +74,7 @@ ohos_shared_library("backup_utils") { "src/b_process/b_guard_cwd.cpp", "src/b_process/b_guard_signal.cpp", "src/b_process/b_process.cpp", + "src/b_radar/b_radar.cpp", "src/b_sa/b_sa_utils.cpp", "src/b_tarball/b_tarball_cmdline.cpp", "src/b_tarball/b_tarball_factory.cpp", @@ -90,6 +91,7 @@ ohos_shared_library("backup_utils") { "c_utils:utils", "faultloggerd:libdfx_dumpcatcher", "hilog:libhilog", + "hisysevent:libhisysevent", "hitrace:hitrace_meter", "init:libbegetutil", "ipc:ipc_core", @@ -98,6 +100,7 @@ ohos_shared_library("backup_utils") { include_dirs = [ "${path_init}/interfaces/innerkits/include/syspara", "${path_backup}/interfaces/inner_api/native/backup_kit_inner/impl", + "${path_backup}/utils/include", ] deps = [ diff --git a/utils/include/b_radar/b_radar.h b/utils/include/b_radar/b_radar.h new file mode 100644 index 000000000..fc87dca33 --- /dev/null +++ b/utils/include/b_radar/b_radar.h @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_FILEMGMT_BACKUP_B_RADAR_H +#define OHOS_FILEMGMT_BACKUP_B_RADAR_H +#include +#include + +namespace OHOS::FileManagement::Backup { +enum class BizStageBackup : int32_t { + BIZ_STAGE_DEFAULT = 0, + BIZ_STAGE_BACKUP_SA, + BIZ_STAGE_GET_LOCAL_CAPABILITIES, + BIZ_STAGE_CREATE_SESSION_BACKUP, + BIZ_STAGE_APPEND_BUNDLES, + BIZ_STAGE_BACKUP_EXTENSION, + BIZ_STAGE_APPLICATION, + BIZ_STAGE_EXTENSION_STATUS, + BIZ_STAGE_GET_BACKUP_INFO, + BIZ_STAGE_ON_BACKUP, + BIZ_STAGE_DO_BACKUP, + BIZ_STAGE_DATA_CONSISTENCY, + BIZ_STAGE_STATUS_CLEAR, + BIZ_STAGE_CLIENT_STATUS, + BIZ_STAGE_PERMISSION_CHECK +}; + +enum class BizStageRestore : int32_t { + BIZ_STAGE_DEFAULT = 0, + BIZ_STAGE_BACKUP_SA, + BIZ_STAGE_GET_LOCAL_CAPABILITIES, + BIZ_STAGE_CREATE_SESSION_RESTORE, + BIZ_STAGE_APPEND_BUNDLES, + BIZ_STAGE_CONNECT_BACKUP_EXTENSION, + BIZ_STAGE_APPLICATION, + BIZ_STAGE_EXTENSION_STATUS, + BIZ_STAGE_GET_FILE_HANDLE, + BIZ_STAGE_DO_RESTORE, + BIZ_STAGE_DATA_CONSISTENCY, + BIZ_STAGE_EXEC_ON_RESTORE, + BIZ_STAGE_STATUS_CLEAR, + BIZ_STAGE_CLIENT_STATUS, + BIZ_STAGE_PERMISSION_CHECK +}; + +class AppRadar { +public: + static AppRadar &GetInstance() + { + static AppRadar instance; + return instance; + } + +public: + struct Info { + std::string bundleName; + std::string status; + std::string resInfo; + + Info(const std::string &bundleName, const std::string &status, const std::string &resInfo) + : bundleName(bundleName), status(status), resInfo(resInfo) {} + }; + +public: + int32_t GetUserId(); + void RecordDefaultFuncRes(Info &info, const std::string &func, int32_t userId, + enum BizStageBackup bizStage, int32_t resultCode); + void RecordBackupFuncRes(Info &info, const std::string &func, int32_t userId, + enum BizStageBackup bizStage, int32_t resultCode); + void RecordRestoreFuncRes(Info &info, const std::string &func, int32_t userId, + enum BizStageRestore bizStage, int32_t resultCode); +private: + AppRadar() = default; + ~AppRadar() = default; + AppRadar(const AppRadar &) = delete; + AppRadar &operator=(const AppRadar &) = delete; + AppRadar(AppRadar &&) = delete; + AppRadar &operator=(AppRadar &&) = delete; +}; +} // namespace OHOS::FileManagement::AppRadar +#endif // OHOS_FILEMGMT_BACKUP_B_RADAR_H diff --git a/utils/include/b_resources/b_constants.h b/utils/include/b_resources/b_constants.h index 6d168b70b..f50e544dd 100644 --- a/utils/include/b_resources/b_constants.h +++ b/utils/include/b_resources/b_constants.h @@ -214,6 +214,11 @@ static inline std::string MANIFEST_FD = "manifestFd"; static inline std::string LAST_INCREMENTAL_TIME = "lastIncrementalTime"; static inline std::string PARAMETERS = "parameters"; static inline std::string PRIORITY = "priority"; + +// 雷达打点引用到的常量 +constexpr int32_t MS_1000 = 1000; +constexpr uint8_t INDEX = 3; +static inline std::string FILE_BACKUP_RESTORE_EVENTS = "FILE_BACKUP_RESTORE_EVENTS"; } // namespace OHOS::FileManagement::Backup::BConstants #endif // OHOS_FILEMGMT_BACKUP_B_CONSTANTS_H diff --git a/utils/include/b_utils/b_time.h b/utils/include/b_utils/b_time.h index 77560a7b4..840e5e5b7 100644 --- a/utils/include/b_utils/b_time.h +++ b/utils/include/b_utils/b_time.h @@ -23,6 +23,7 @@ public: static int64_t GetTimeS(); static int64_t GetTimeMS(); static int64_t GetTimeUS(); + static std::string GetCurrentTime(); }; } // namespace OHOS::FileManagement::TimeUtils #endif // OHOS_FILEMGMT_BACKUP_B_TIME_H \ No newline at end of file diff --git a/utils/src/b_radar/b_radar.cpp b/utils/src/b_radar/b_radar.cpp new file mode 100644 index 000000000..68760b777 --- /dev/null +++ b/utils/src/b_radar/b_radar.cpp @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include "b_process/b_multiuser.h" +#include "b_radar/b_radar.h" +#include "b_resources/b_constants.h" +#include "b_utils/b_time.h" +#include "hisysevent.h" +#include "i_service_reverse.h" + +namespace OHOS::FileManagement::Backup { +int32_t AppRadar::GetUserId() +{ + auto multiuser = BMultiuser::ParseUid(getuid()); + if ((multiuser.userId == BConstants::SYSTEM_UID) || (multiuser.userId == BConstants::XTS_UID)) { + return BConstants::DEFAULT_USER_ID; + } + return multiuser.userId; +} + +void AppRadar::RecordDefaultFuncRes(Info &info, const std::string &func, int32_t userId, + enum BizStageBackup bizStage, int32_t resultCode) +{ + 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(IServiceReverse::Scenario::UNDEFINED), + "BIZ_STAGE", static_cast(bizStage), + "EXEC_STATUS", info.status, + "RESULT_CODE", resultCode, + "RESULT_INFO", info.resInfo); +} + +void AppRadar::RecordBackupFuncRes(Info &info, const std::string &func, int32_t userId, + enum BizStageBackup bizStage, int32_t resultCode) +{ + 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(IServiceReverse::Scenario::BACKUP), + "BIZ_STAGE", static_cast(bizStage), + "EXEC_STATUS", info.status, + "RESULT_CODE", resultCode, + "RESULT_INFO", info.resInfo); +} + +void AppRadar::RecordRestoreFuncRes(Info &info, const std::string &func, int32_t userId, + enum BizStageRestore bizStage, int32_t resultCode) +{ + 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(IServiceReverse::Scenario::RESTORE), + "BIZ_STAGE", static_cast(bizStage), + "EXEC_STATUS", info.status, + "RESULT_CODE", resultCode, + "RESULT_INFO", info.resInfo); +} +} // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/utils/src/b_utils/b_time.cpp b/utils/src/b_utils/b_time.cpp index 6656cf582..e6f49f7ce 100644 --- a/utils/src/b_utils/b_time.cpp +++ b/utils/src/b_utils/b_time.cpp @@ -13,8 +13,12 @@ * limitations under the License. */ +#include "b_resources/b_constants.h" #include "b_utils/b_time.h" #include +#include +#include +#include namespace OHOS::FileManagement::Backup { int64_t TimeUtils::GetTimeS() @@ -37,4 +41,15 @@ int64_t TimeUtils::GetTimeUS() std::chrono::system_clock::now().time_since_epoch()); return nowUs.count(); } + +std::string TimeUtils::GetCurrentTime() +{ + 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()); + std::stringstream strTime; + strTime << (std::put_time(std::localtime(&time), "%Y-%m-%d %H:%M:%S:")) << (std::setfill('0')) + << (std::setw(BConstants::INDEX)) << (ms.count() % BConstants::MS_1000); + return strTime.str(); +} } // namespace OHOS::FileManagement::Backup \ No newline at end of file -- Gitee