From 71b0ba8103a15f7ee2529f2436872c1de2596aac Mon Sep 17 00:00:00 2001 From: chensihan Date: Mon, 11 Nov 2024 10:07:32 +0800 Subject: [PATCH 1/5] codecheck Signed-off-by: chensihan --- .../src/module_ipc/sa_backup_connection.cpp | 16 +++++------ services/backup_sa/src/module_ipc/service.cpp | 4 +++ .../src/module_ipc/service_incremental.cpp | 28 +++++++++++++------ .../backup_sa/src/module_ipc/sub_service.cpp | 8 ++++++ 4 files changed, 39 insertions(+), 17 deletions(-) diff --git a/services/backup_sa/src/module_ipc/sa_backup_connection.cpp b/services/backup_sa/src/module_ipc/sa_backup_connection.cpp index 13f2cb779..041f4626b 100644 --- a/services/backup_sa/src/module_ipc/sa_backup_connection.cpp +++ b/services/backup_sa/src/module_ipc/sa_backup_connection.cpp @@ -70,12 +70,12 @@ sptr SABackupConnection::GetBackupSAExtProxy() ErrCode SABackupConnection::LoadBackupSAExt() { if (proxy_ && isConnected_.load()) { - HILOGI("SA %{public}d is running.", saId_); + HILOGI("SA %{private}d is running.", saId_); callConnected_(move(bundleName_)); return BError(BError::Codes::OK); } if (reloadNum_.load() >= BConstants::BACKUP_SA_RELOAD_MAX) { - HILOGI("SA %{public}d reload done and return", saId_); + HILOGI("SA %{private}d reload done and return", saId_); callDied_(move(bundleName_)); return BError(BError::Codes::SA_EXT_RELOAD_FAIL); } @@ -127,7 +127,7 @@ ErrCode SABackupConnection::LoadBackupSAExtInner() loadCallback->proxyConVar_.wait_for(lock, std::chrono::milliseconds(BConstants::BACKUP_LOADSA_TIMEOUT_MS), [loadCallback]() { return loadCallback->isLoadSuccess_.load(); }); if (!waitStatus) { - HILOGE("Load sa %{public}d timeout", saId_); + HILOGE("Load sa %{private}d timeout", saId_); lock.unlock(); isConnected_.store(false); return LoadBackupSAExt(); @@ -141,21 +141,21 @@ bool SABackupConnection::InputParaSet(MessageParcel &data) { if (extension_ == BConstants::EXTENSION_BACKUP) { if (!data.WriteString(extInfo_)) { - HILOGE("InputParaSet WriteString failed sa: %{public}d, extInfo: %{public}s, extension: %{public}s", + HILOGE("InputParaSet WriteString failed sa: %{private}d, extInfo: %{public}s, extension: %{public}s", saId_, extInfo_.c_str(), extension_.c_str()); return false; } return true; } else if (extension_ == BConstants::EXTENSION_RESTORE) { if (!data.WriteFileDescriptor(fd_) || !data.WriteString(extInfo_)) { - HILOGE("InputParaSet WriteString failed sa: %{public}d, extension: %{public}s", + HILOGE("InputParaSet WriteString failed sa: %{private}d, extension: %{public}s", saId_, extension_.c_str()); return false; } return true; } - HILOGD("SABackupExtentionPara InFunc sa: %{public}d, extension: %{public}s", saId_, extension_.c_str()); + HILOGD("SABackupExtentionPara InFunc sa: %{private}d, extension: %{public}s", saId_, extension_.c_str()); return false; } @@ -163,10 +163,10 @@ bool SABackupConnection::OutputParaGet(MessageParcel &reply) { parcel_.ClearFileDescriptor(); if (!parcel_.Append(reply)) { - HILOGE("OutputParaGet append failed sa is %{public}d, extension: %{public}s", saId_, extension_.c_str()); + HILOGE("OutputParaGet append failed sa is %{private}d, extension: %{public}s", saId_, extension_.c_str()); return false; } - HILOGD("SABackupExtentionPara OutFunc sa is %{public}d, extension: %{public}s", saId_, extension_.c_str()); + HILOGD("SABackupExtentionPara OutFunc sa is %{private}d, extension: %{public}s", saId_, extension_.c_str()); return true; } diff --git a/services/backup_sa/src/module_ipc/service.cpp b/services/backup_sa/src/module_ipc/service.cpp index 5ba1614be..b8fd85bd6 100644 --- a/services/backup_sa/src/module_ipc/service.cpp +++ b/services/backup_sa/src/module_ipc/service.cpp @@ -992,6 +992,10 @@ ErrCode Service::GetFileHandle(const string &bundleName, const string &fileName) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); try { + if (session_ == nullptr) { + HILOGE("GetFileHandle error, session is empty"); + return BError(BError::Codes::SA_INVAL_ARG); + } VerifyCaller(IServiceReverse::Scenario::RESTORE); bool updateRes = SvcRestoreDepsManager::GetInstance().UpdateToRestoreBundleMap(bundleName, fileName); diff --git a/services/backup_sa/src/module_ipc/service_incremental.cpp b/services/backup_sa/src/module_ipc/service_incremental.cpp index 0e1592367..21beb4505 100644 --- a/services/backup_sa/src/module_ipc/service_incremental.cpp +++ b/services/backup_sa/src/module_ipc/service_incremental.cpp @@ -81,15 +81,17 @@ ErrCode Service::Release() { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); HILOGI("KILL"); - IServiceReverse::Scenario scenario = session_->GetScenario(); - VerifyCaller(scenario); - AppRadar::Info info("", "", "call release"); - if (scenario == IServiceReverse::Scenario::RESTORE) { - AppRadar::GetInstance().RecordRestoreFuncRes(info, "Service::Release", session_->GetSessionUserId(), - BizStageRestore::BIZ_STAGE_RELEASE, ERR_OK); - } else if (scenario == IServiceReverse::Scenario::BACKUP) { - AppRadar::GetInstance().RecordBackupFuncRes(info, "Service::Release", session_->GetSessionUserId(), - BizStageBackup::BIZ_STAGE_RELEASE, ERR_OK); + if (session_ != nullptr) { + IServiceReverse::Scenario scenario = session_->GetScenario(); + VerifyCaller(scenario); + AppRadar::Info info("", "", "call release"); + if (scenario == IServiceReverse::Scenario::RESTORE) { + AppRadar::GetInstance().RecordRestoreFuncRes(info, "Service::Release", session_->GetSessionUserId(), + BizStageRestore::BIZ_STAGE_RELEASE, ERR_OK); + } else if (scenario == IServiceReverse::Scenario::BACKUP) { + AppRadar::GetInstance().RecordBackupFuncRes(info, "Service::Release", session_->GetSessionUserId(), + BizStageBackup::BIZ_STAGE_RELEASE, ERR_OK); + } } SessionDeactive(); return BError(BError::Codes::OK); @@ -462,6 +464,10 @@ ErrCode Service::AppIncrementalFileReady(const std::string &fileName, UniqueFd f { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); try { + if (session_ == nullptr) { + HILOGE("AppIncrementalFileReady error, session is empty"); + return BError(BError::Codes::SA_INVAL_ARG); + } string callerName = VerifyCallerAndGetCallerName(); if (session_->GetScenario() == IServiceReverse::Scenario::RESTORE) { session_->GetServiceReverseProxy()->IncrementalRestoreOnFileReady(callerName, fileName, move(fd), @@ -564,6 +570,10 @@ ErrCode Service::GetIncrementalFileHandle(const std::string &bundleName, const s { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); try { + if (session_ == nullptr) { + HILOGE("GetIncrementalFileHandle error, session is empty"); + return BError(BError::Codes::SA_INVAL_ARG); + } VerifyCaller(IServiceReverse::Scenario::RESTORE); auto action = session_->GetServiceSchedAction(bundleName); if (action == BConstants::ServiceSchedAction::RUNNING) { diff --git a/services/backup_sa/src/module_ipc/sub_service.cpp b/services/backup_sa/src/module_ipc/sub_service.cpp index b269ace2a..d497d26cb 100644 --- a/services/backup_sa/src/module_ipc/sub_service.cpp +++ b/services/backup_sa/src/module_ipc/sub_service.cpp @@ -93,6 +93,10 @@ ErrCode Service::PublishFile(const BFileInfo &fileInfo) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); try { + if (session_ == nullptr) { + HILOGE("PublishFile error, session is empty"); + return BError(BError::Codes::SA_INVAL_ARG); + } VerifyCaller(IServiceReverse::Scenario::RESTORE); if (!fileInfo.fileName.empty()) { HILOGE("Forbit to use publishFile with fileName for App"); @@ -128,6 +132,10 @@ ErrCode Service::AppFileReady(const string &fileName, UniqueFd fd, int32_t errCo { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); try { + if (session_ == nullptr) { + HILOGE("AppFileReady error, session is empty"); + return BError(BError::Codes::SA_INVAL_ARG); + } string callerName = VerifyCallerAndGetCallerName(); if (fileName.find('/') != string::npos) { throw BError(BError::Codes::SA_INVAL_ARG, "Filename is not valid"); -- Gitee From 9df78e8d1c91bbbcec91e7a0f07b560cdd988e7f Mon Sep 17 00:00:00 2001 From: chensihan Date: Tue, 12 Nov 2024 01:24:30 +0000 Subject: [PATCH 2/5] update services/backup_sa/src/module_ipc/service_incremental.cpp. Signed-off-by: chensihan --- services/backup_sa/src/module_ipc/service_incremental.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/services/backup_sa/src/module_ipc/service_incremental.cpp b/services/backup_sa/src/module_ipc/service_incremental.cpp index 21beb4505..268de3873 100644 --- a/services/backup_sa/src/module_ipc/service_incremental.cpp +++ b/services/backup_sa/src/module_ipc/service_incremental.cpp @@ -464,10 +464,6 @@ ErrCode Service::AppIncrementalFileReady(const std::string &fileName, UniqueFd f { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); try { - if (session_ == nullptr) { - HILOGE("AppIncrementalFileReady error, session is empty"); - return BError(BError::Codes::SA_INVAL_ARG); - } string callerName = VerifyCallerAndGetCallerName(); if (session_->GetScenario() == IServiceReverse::Scenario::RESTORE) { session_->GetServiceReverseProxy()->IncrementalRestoreOnFileReady(callerName, fileName, move(fd), -- Gitee From 23939ded26aa3b0dff3e3f1e9fe02f43cfb07676 Mon Sep 17 00:00:00 2001 From: chensihan Date: Mon, 18 Nov 2024 02:35:40 +0000 Subject: [PATCH 3/5] =?UTF-8?q?=E6=97=A5=E5=BF=97=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chensihan --- utils/src/b_filesystem/b_dir.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/src/b_filesystem/b_dir.cpp b/utils/src/b_filesystem/b_dir.cpp index 1d8f3d41b..b37901395 100644 --- a/utils/src/b_filesystem/b_dir.cpp +++ b/utils/src/b_filesystem/b_dir.cpp @@ -85,7 +85,7 @@ static uint32_t CheckOverLongPath(const string &path) if (len >= PATH_MAX_LEN) { size_t found = path.find_last_of(BConstants::FILE_SEPARATOR_CHAR); string sub = path.substr(found + 1); - HILOGE("Path over long, length:%{public}d, fileName:%{public}s.", len, sub.c_str()); + HILOGE("Path over long, length:%{public}d, fileName:%{private}s.", len, sub.c_str()); } return len; } -- Gitee From 3d6ed449268d01702a5801617b461ac2a69f43ba Mon Sep 17 00:00:00 2001 From: chensihan Date: Tue, 19 Nov 2024 11:59:57 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9=20Signed-off-by:=20chens?= =?UTF-8?q?ihan=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/module_ipc/sa_backup_connection.cpp | 22 ++++++++--------- .../src/module_ipc/service_incremental.cpp | 24 ++++++++++--------- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/services/backup_sa/src/module_ipc/sa_backup_connection.cpp b/services/backup_sa/src/module_ipc/sa_backup_connection.cpp index 041f4626b..231389520 100644 --- a/services/backup_sa/src/module_ipc/sa_backup_connection.cpp +++ b/services/backup_sa/src/module_ipc/sa_backup_connection.cpp @@ -70,12 +70,12 @@ sptr SABackupConnection::GetBackupSAExtProxy() ErrCode SABackupConnection::LoadBackupSAExt() { if (proxy_ && isConnected_.load()) { - HILOGI("SA %{private}d is running.", saId_); + HILOGI("SA %{public}d is running.", saId_); callConnected_(move(bundleName_)); return BError(BError::Codes::OK); } if (reloadNum_.load() >= BConstants::BACKUP_SA_RELOAD_MAX) { - HILOGI("SA %{private}d reload done and return", saId_); + HILOGI("SA %{public}d reload done and return", saId_); callDied_(move(bundleName_)); return BError(BError::Codes::SA_EXT_RELOAD_FAIL); } @@ -117,7 +117,7 @@ ErrCode SABackupConnection::LoadBackupSAExtInner() } int32_t ret = samgrProxy->LoadSystemAbility(saId_, loadCallback); if (ret != ERR_OK) { - HILOGE("Failed to Load systemAbility, systemAbility:%{private}d. ret code:%{public}d", saId_, ret); + HILOGE("Failed to Load systemAbility, systemAbility:%{public}d. ret code:%{public}d", saId_, ret); return BError(BError::Codes::SA_EXT_ERR_SAMGR); } isLoaded_.store(true); @@ -127,7 +127,7 @@ ErrCode SABackupConnection::LoadBackupSAExtInner() loadCallback->proxyConVar_.wait_for(lock, std::chrono::milliseconds(BConstants::BACKUP_LOADSA_TIMEOUT_MS), [loadCallback]() { return loadCallback->isLoadSuccess_.load(); }); if (!waitStatus) { - HILOGE("Load sa %{private}d timeout", saId_); + HILOGE("Load sa %{public}d timeout", saId_); lock.unlock(); isConnected_.store(false); return LoadBackupSAExt(); @@ -141,21 +141,21 @@ bool SABackupConnection::InputParaSet(MessageParcel &data) { if (extension_ == BConstants::EXTENSION_BACKUP) { if (!data.WriteString(extInfo_)) { - HILOGE("InputParaSet WriteString failed sa: %{private}d, extInfo: %{public}s, extension: %{public}s", + HILOGE("InputParaSet WriteString failed sa: %{public}d, extInfo: %{public}s, extension: %{public}s", saId_, extInfo_.c_str(), extension_.c_str()); return false; } return true; } else if (extension_ == BConstants::EXTENSION_RESTORE) { if (!data.WriteFileDescriptor(fd_) || !data.WriteString(extInfo_)) { - HILOGE("InputParaSet WriteString failed sa: %{private}d, extension: %{public}s", + HILOGE("InputParaSet WriteString failed sa: %{public}d, extension: %{public}s", saId_, extension_.c_str()); return false; } return true; } - HILOGD("SABackupExtentionPara InFunc sa: %{private}d, extension: %{public}s", saId_, extension_.c_str()); + HILOGD("SABackupExtentionPara InFunc sa: %{public}d, extension: %{public}s", saId_, extension_.c_str()); return false; } @@ -163,10 +163,10 @@ bool SABackupConnection::OutputParaGet(MessageParcel &reply) { parcel_.ClearFileDescriptor(); if (!parcel_.Append(reply)) { - HILOGE("OutputParaGet append failed sa is %{private}d, extension: %{public}s", saId_, extension_.c_str()); + HILOGE("OutputParaGet append failed sa is %{public}d, extension: %{public}s", saId_, extension_.c_str()); return false; } - HILOGD("SABackupExtentionPara OutFunc sa is %{private}d, extension: %{public}s", saId_, extension_.c_str()); + HILOGD("SABackupExtentionPara OutFunc sa is %{public}d, extension: %{public}s", saId_, extension_.c_str()); return true; } @@ -221,7 +221,7 @@ ErrCode SABackupConnection::CallRestoreSA(UniqueFd fd) void SABackupConnection::SALoadCallback::OnLoadSystemAbilitySuccess(int32_t systemAbilityId, const OHOS::sptr &remoteObject) { - HILOGI("Load backup sa success, systemAbilityId: %{private}d, remoteObject result:%{private}s", systemAbilityId, + HILOGI("Load backup sa success, systemAbilityId: %{public}d, remoteObject result:%{public}s", systemAbilityId, (remoteObject != nullptr) ? "true" : "false"); if (remoteObject == nullptr) { isLoadSuccess_.store(false); @@ -234,7 +234,7 @@ void SABackupConnection::SALoadCallback::OnLoadSystemAbilitySuccess(int32_t syst void SABackupConnection::SALoadCallback::OnLoadSystemAbilityFail(int32_t systemAbilityId) { - HILOGE("Load backup sa failed, systemAbilityId:%{private}d", systemAbilityId); + HILOGE("Load backup sa failed, systemAbilityId:%{public}d", systemAbilityId); isLoadSuccess_.store(false); proxyConVar_.notify_one(); } diff --git a/services/backup_sa/src/module_ipc/service_incremental.cpp b/services/backup_sa/src/module_ipc/service_incremental.cpp index 268de3873..e8e84d105 100644 --- a/services/backup_sa/src/module_ipc/service_incremental.cpp +++ b/services/backup_sa/src/module_ipc/service_incremental.cpp @@ -81,17 +81,19 @@ ErrCode Service::Release() { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); HILOGI("KILL"); - if (session_ != nullptr) { - IServiceReverse::Scenario scenario = session_->GetScenario(); - VerifyCaller(scenario); - AppRadar::Info info("", "", "call release"); - if (scenario == IServiceReverse::Scenario::RESTORE) { - AppRadar::GetInstance().RecordRestoreFuncRes(info, "Service::Release", session_->GetSessionUserId(), - BizStageRestore::BIZ_STAGE_RELEASE, ERR_OK); - } else if (scenario == IServiceReverse::Scenario::BACKUP) { - AppRadar::GetInstance().RecordBackupFuncRes(info, "Service::Release", session_->GetSessionUserId(), - BizStageBackup::BIZ_STAGE_RELEASE, ERR_OK); - } + if (session_ == nullptr) { + HILOGE("Release error, session is empty"); + return BError(BError::Codes::SA_INVAL_ARG); + } + IServiceReverse::Scenario scenario = session_->GetScenario(); + VerifyCaller(scenario); + AppRadar::Info info("", "", "call release"); + if (scenario == IServiceReverse::Scenario::RESTORE) { + AppRadar::GetInstance().RecordRestoreFuncRes(info, "Service::Release", session_->GetSessionUserId(), + BizStageRestore::BIZ_STAGE_RELEASE, ERR_OK); + } else if (scenario == IServiceReverse::Scenario::BACKUP) { + AppRadar::GetInstance().RecordBackupFuncRes(info, "Service::Release", session_->GetSessionUserId(), + BizStageBackup::BIZ_STAGE_RELEASE, ERR_OK); } SessionDeactive(); return BError(BError::Codes::OK); -- Gitee From e7d618b1ec855d82cdcaf0debb762d47ce89e8ca Mon Sep 17 00:00:00 2001 From: chensihan Date: Tue, 19 Nov 2024 04:05:16 +0000 Subject: [PATCH 5/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chensihan --- services/backup_sa/src/module_ipc/service_incremental.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/backup_sa/src/module_ipc/service_incremental.cpp b/services/backup_sa/src/module_ipc/service_incremental.cpp index e8e84d105..72b8e60c7 100644 --- a/services/backup_sa/src/module_ipc/service_incremental.cpp +++ b/services/backup_sa/src/module_ipc/service_incremental.cpp @@ -90,10 +90,10 @@ ErrCode Service::Release() AppRadar::Info info("", "", "call release"); if (scenario == IServiceReverse::Scenario::RESTORE) { AppRadar::GetInstance().RecordRestoreFuncRes(info, "Service::Release", session_->GetSessionUserId(), - BizStageRestore::BIZ_STAGE_RELEASE, ERR_OK); + BizStageRestore::BIZ_STAGE_RELEASE, ERR_OK); } else if (scenario == IServiceReverse::Scenario::BACKUP) { AppRadar::GetInstance().RecordBackupFuncRes(info, "Service::Release", session_->GetSessionUserId(), - BizStageBackup::BIZ_STAGE_RELEASE, ERR_OK); + BizStageBackup::BIZ_STAGE_RELEASE, ERR_OK); } SessionDeactive(); return BError(BError::Codes::OK); -- Gitee