diff --git a/frameworks/native/backup_ext/include/ext_extension.h b/frameworks/native/backup_ext/include/ext_extension.h index b8b18735c4b701ec0492f59d704ee1af36dff17f..045bc71a9eebb8312aeef75777c119c84c50cc49 100644 --- a/frameworks/native/backup_ext/include/ext_extension.h +++ b/frameworks/native/backup_ext/include/ext_extension.h @@ -259,6 +259,10 @@ private: void SyncCallJsOnProcessTask(wptr obj, BackupRestoreScenario scenario); void StartOnProcessTimeOutTimer(wptr obj, BackupRestoreScenario scenario); void CloseOnProcessTimeOutTimer(); + void UpdateOnRestoreTime(); + void UpdateOnBackUpTime(); + int32_t GetOnBackupTimeCost(); + int32_t GetOnRestoreTimeCost(); private: std::shared_mutex lock_; @@ -286,6 +290,10 @@ private: std::condition_variable execOnProcessCon_; std::mutex onProcessLock_; std::atomic onProcessTimeout_ {false}; + std::chrono::time_point g_onBackUpStart; + std::chrono::time_point g_onRestoreStart; + std::mutex onBackupTimeLock_; + std::mutex onRestoreTimeLock_; }; } // 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 aadb30d53355996078355ebb55678a5a774a8f2e..a6fd878c15eb7d9fd0612504ae92e772ed8f20b6 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" @@ -128,10 +129,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()))); } @@ -828,7 +837,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); @@ -1152,6 +1167,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) { @@ -1161,6 +1186,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; @@ -1178,6 +1204,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 { @@ -1217,6 +1248,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并且非特殊场景 @@ -1226,6 +1260,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(); } @@ -1301,6 +1339,12 @@ void BackupExtExtension::AsyncTaskIncreRestoreSpecialVersion() }); } +void BackupExtExtension::UpdateOnRestoreTime() +{ + std::lock_guard lock(onRestoreTimeLock_); + g_onRestoreStart = std::chrono::system_clock::now(); +} + void BackupExtExtension::AsyncTaskRestoreForUpgrade() { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); @@ -1319,6 +1363,7 @@ void BackupExtExtension::AsyncTaskRestoreForUpgrade() ptr->StartOnProcessTaskThread(obj, BackupRestoreScenario::FULL_RESTORE); auto callBackup = ptr->OnRestoreCallback(obj); auto callBackupEx = ptr->OnRestoreExCallback(obj); + ptr->UpdateOnRestoreTime(); ErrCode err = ptr->extension_->OnRestore(callBackup, callBackupEx); if (err != ERR_OK) { ptr->AppDone(BError::GetCodeByErrno(err)); @@ -1369,6 +1414,7 @@ void BackupExtExtension::AsyncTaskIncrementalRestoreForUpgrade() ptr->StartOnProcessTaskThread(obj, BackupRestoreScenario::INCREMENTAL_RESTORE); auto callBackup = ptr->IncreOnRestoreCallback(obj); auto callBackupEx = ptr->IncreOnRestoreExCallback(obj); + ptr->UpdateOnRestoreTime(); ErrCode err = ptr->extension_->OnRestore(callBackup, callBackupEx); if (err != ERR_OK) { HILOGE("OnRestore done, err = %{pubilc}d", err); @@ -1498,6 +1544,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__); @@ -1509,6 +1561,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); @@ -1894,6 +1947,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 673958e3f234863d6cff726356332383df464155..bf32751d2e1d57d5799e4a985da35110371dd380 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" @@ -238,6 +239,14 @@ ErrCode BackupExtExtension::UpdateFdSendRate(std::string &bundleName, int32_t se } } +int32_t BackupExtExtension::GetOnRestoreTimeCost() +{ + auto endTime = std::chrono::system_clock::now(); + std::lock_guard lock(onRestoreTimeLock_); + auto ms = std::chrono::duration_cast(endTime - g_onRestoreStart).count(); + return ms; +} + std::function BackupExtExtension::OnRestoreCallback(wptr obj) { HILOGI("Begin get full restore onRestore callback"); @@ -248,6 +257,13 @@ std::function BackupExtExtension::OnRestoreCallback( return; } HILOGI("Current bundle will execute app done"); + if (errCode == ERR_OK) { + auto ms = extensionPtr->GetOnRestoreTimeCost(); + 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); @@ -273,6 +289,13 @@ std::function BackupExtExtension::OnRestoreExCallbac HILOGE("Extension handle have been released"); return; } + if (errCode == ERR_OK && !restoreRetInfo.empty()) { + auto ms = extensionPtr->GetOnRestoreTimeCost(); + 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) { @@ -323,6 +346,13 @@ std::function BackupExtExtension::IncreOnRestoreExCa HILOGE("Extension handle have been released"); return; } + if (errCode == ERR_OK && !restoreRetInfo.empty()) { + auto ms = extensionPtr->GetOnRestoreTimeCost(); + 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) { @@ -352,6 +382,13 @@ std::function BackupExtExtension::IncreOnRestoreCall return; } HILOGI("Current bundle will execute app done"); + if (errCode == ERR_OK) { + auto ms = extensionPtr->GetOnRestoreTimeCost(); + 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); @@ -364,6 +401,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"); @@ -378,6 +423,12 @@ std::function BackupExtExtension::OnBackupCall HILOGE("Extension handle have been released"); return; } + if (errCode == ERR_OK) { + auto ms = extensionPtr->GetOnBackupTimeCost(); + 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()); }; @@ -397,6 +448,12 @@ std::function BackupExtExtension::OnBackupExCa HILOGE("Extension handle have been released"); return; } + if (errCode == ERR_OK && !backupExRetInfo.empty()) { + auto ms = extensionPtr->GetOnBackupTimeCost(); + 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"); @@ -422,6 +479,12 @@ std::function BackupExtExtension::IncOnBackupC return; } HILOGI("Start GetAppLocalListAndDoIncrementalBackup"); + if (errCode == ERR_OK) { + auto ms = extPtr->GetOnBackupTimeCost(); + 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(); }; @@ -444,6 +507,12 @@ std::function BackupExtExtension::IncOnBackupE HILOGE("Extension handle have been released"); return; } + if (errCode == ERR_OK && !backupExRetInfo.empty()) { + auto ms = extensionPtr->GetOnBackupTimeCost(); + 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 bc4a6e687ed79e2eeb63ae8a5b2d59bd4ecb3ea7..cdec6797280c3ba3c1af454ad649662df01fb221 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 1b5b24c6a317fcc5adb90b87eab9be84b7e04a95..4dc3e5509a34756d8bd12a366978df97643680b2 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 67ed9f49b7e6277c6fa63cb306565c0d73b5f769..13079b8cb21463091bbeca9c8b58a262ab851e50 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 495e9d545c79ad57f64205e9d4bf90c8ce062350..f75fed7778e13446c2833b3cd4ef046de77481da 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 c284aa26fc911346bd980ac88e2786c08aa7bb27..0975fa832f5ebe390df33be8cbf2ae11e97c4e14 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 99ffa77eb9d2bee6835d504acba785ea2f275b20..e36f0dd36b41871cf7d7ffe1a1624801ff55abe6 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 9de0a9be73f1be143016f717887d44ec7dbe2dbc..e6ea4d168060c70540c3d32ef617091e8e0cc65f 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" @@ -452,6 +455,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_; @@ -487,6 +493,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; } @@ -505,6 +515,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 c84d227f23979db6436a0793c0b705f4ce0d7a81..2ee1a876dd7b91829c20172f45856f18b82206e9 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 b9a497ef337439a5da8a0dc277cca8ef09bb070b..2e5fc7fe05b5177e25b639294f3f62d38dd9dc93 100644 --- a/services/backup_sa/include/module_ipc/service.h +++ b/services/backup_sa/include/module_ipc/service.h @@ -92,6 +92,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 25de0559127d26e334b68c700db70592c1d1835f..ce3f8b7e4d5a32eeee4e9956ac18e25975687284 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" @@ -94,6 +95,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); @@ -122,6 +152,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 41a109b148499ce18142e4f26f518a045702ef63..e94be66132696466ef43bf20ad6dbd181e3f9f7a 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" @@ -149,6 +150,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__); @@ -160,6 +169,7 @@ UniqueFd Service::GetLocalCapabilities() HILOGI("Begin"); if (session_ == nullptr || isCleanService_.load()) { HILOGE("GetLocalCapabilities error, session is empty."); + GetLocalCapabilitiesRadar("GetLocalCapabilities", EPERM, "{\"reason\":\"session empty\"}"); return UniqueFd(-EPERM); } session_->IncreaseSessionCnt(__PRETTY_FUNCTION__); @@ -171,6 +181,8 @@ UniqueFd Service::GetLocalCapabilities() if (fd < 0) { HILOGE("Failed to open config file = %{private}s, err = %{public}d", path.c_str(), errno); session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); + GetLocalCapabilitiesRadar("GetLocalCapabilities", EPERM, + "{\"reason\":\"failed to open config file\"}"); return UniqueFd(-EPERM); } BJsonCachedEntity cachedEntity(std::move(fd)); @@ -188,14 +200,17 @@ UniqueFd Service::GetLocalCapabilities() } catch (const BError &e) { session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); HILOGE("GetLocalCapabilities failed, errCode = %{public}d", e.GetCode()); + GetLocalCapabilitiesRadar("GetLocalCapabilities", e.GetCode(), "{\"reason\":\"failed\"}"); return UniqueFd(-e.GetCode()); } catch (const exception &e) { session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); HILOGI("Catched an unexpected low-level exception %{public}s", e.what()); + GetLocalCapabilitiesRadar("GetLocalCapabilities", EPERM, "{\"reason\":\"exception\"}"); return UniqueFd(-EPERM); } catch (...) { session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); HILOGI("Unexpected exception"); + GetLocalCapabilitiesRadar("GetLocalCapabilities", EPERM, "{\"reason\":\"exception\"}"); return UniqueFd(-EPERM); } } @@ -214,6 +229,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, @@ -223,10 +242,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__); @@ -236,6 +266,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))); } @@ -244,11 +276,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))); } @@ -256,10 +292,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; } @@ -461,6 +501,9 @@ ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, const vectorDecreaseSessionCnt(__PRETTY_FUNCTION__); return e.GetCode(); @@ -530,6 +573,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(__PRETTY_FUNCTION__); return e.GetCode(); @@ -966,6 +1012,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()); @@ -1011,11 +1060,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; @@ -1039,6 +1094,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()); @@ -1150,6 +1213,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 && @@ -1453,6 +1523,16 @@ void Service::DeleteDisConfigFile() 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"); @@ -1581,6 +1661,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); } @@ -1924,6 +2006,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 3165e4ef215b17e5c5bbfac59ea9b39e6a745d3a..b27921d191c0857115f5703588349a590cdd0229 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(__PRETTY_FUNCTION__); @@ -106,6 +108,7 @@ UniqueFd Service::GetLocalCapabilitiesIncremental(const std::vectorDecreaseSessionCnt(__PRETTY_FUNCTION__); + GetLocalCapabilitiesRadar("GetLocalCapabilitiesIncremental", ENOENT, "{\"reason\":\"open file failed\"}"); return UniqueFd(-ENOENT); } BJsonCachedEntity cachedEntity(move(fd)); @@ -123,14 +126,17 @@ UniqueFd Service::GetLocalCapabilitiesIncremental(const std::vectorDecreaseSessionCnt(__PRETTY_FUNCTION__); HILOGE("GetLocalCapabilitiesIncremental failed, errCode = %{public}d", e.GetCode()); + GetLocalCapabilitiesRadar("GetLocalCapabilitiesIncremental", e.GetCode(), "{\"reason\":\"fail\"}"); return UniqueFd(-e.GetCode()); } catch (const exception &e) { session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); HILOGI("Catched an unexpected low-level exception %{public}s", e.what()); + GetLocalCapabilitiesRadar("GetLocalCapabilitiesIncremental", EPERM, "{\"reason\":\"exception\"}"); return UniqueFd(-EPERM); } catch (...) { session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); 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 dfdd81a850a030ac99a4fa7f762837ed03a2a185..ed1dd6b169cd2415129acd6d3689dc497e0c3948 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 5150ea00d5d6c8832f2ba0bf0074f60838622e65..bb735177f50a48d20285bcf95305d35d7abc34a3 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -75,6 +75,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", @@ -91,6 +92,7 @@ ohos_shared_library("backup_utils") { "c_utils:utils", "faultloggerd:libdfx_dumpcatcher", "hilog:libhilog", + "hisysevent:libhisysevent", "hitrace:hitrace_meter", "init:libbegetutil", "ipc:ipc_core", @@ -99,6 +101,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 0000000000000000000000000000000000000000..ac7f4549f3e18bec56f7e720021865cb03f04589 --- /dev/null +++ b/utils/include/b_radar/b_radar.h @@ -0,0 +1,102 @@ +/* + * 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 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 0000000000000000000000000000000000000000..0f4e314d2fcf6f280ad56c3a688528b88ebaebb2 --- /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