From 136ff5d755d6c1579737d7e11cedca1bc7612101 Mon Sep 17 00:00:00 2001 From: z30054037 Date: Thu, 30 Nov 2023 10:14:35 +0000 Subject: [PATCH] =?UTF-8?q?=E7=BB=9F=E4=B8=80backupService=E7=9A=84?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E9=94=99=E8=AF=AF=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: z30054037 Change-Id: I00aaa37c7b85b833128f0ccc81f0aed5179cc897 --- .../native/backup_ext/src/ext_extension.cpp | 6 +++-- .../backup_sa/include/module_ipc/service.h | 2 +- services/backup_sa/src/module_ipc/service.cpp | 18 +++++++-------- .../src/module_ipc/service_reverse_proxy.cpp | 3 ++- .../src/module_ipc/svc_session_manager.cpp | 4 ++-- .../src/module_sched/sched_scheduler.cpp | 2 +- tests/mock/module_ipc/service_mock.cpp | 2 +- .../backup_sa/module_ipc/service_test.cpp | 4 ++-- utils/include/b_error/b_error.h | 23 +++++++++++++++++-- 9 files changed, 43 insertions(+), 21 deletions(-) diff --git a/frameworks/native/backup_ext/src/ext_extension.cpp b/frameworks/native/backup_ext/src/ext_extension.cpp index 0ce8b4065..1c15f7c6f 100644 --- a/frameworks/native/backup_ext/src/ext_extension.cpp +++ b/frameworks/native/backup_ext/src/ext_extension.cpp @@ -270,7 +270,8 @@ ErrCode BackupExtExtension::HandleBackup() auto cache = cachedEntity.Structuralize(); if (!cache.GetAllowToBackupRestore()) { HILOGI("Application does not allow backup or restore"); - return BError(BError::Codes::EXT_INVAL_ARG, "Application does not allow backup or restore").GetCode(); + return BError(BError::Codes::SA_FORBID_BACKUP_RESTORE, "Application does not allow backup or restore") + .GetCode(); } AsyncTaskOnBackup(); return 0; @@ -726,7 +727,8 @@ ErrCode BackupExtExtension::HandleRestore() // read backup_config is allow to backup or restore if (!extension_->AllowToBackupRestore()) { HILOGI("Application does not allow backup or restore"); - return BError(BError::Codes::EXT_INVAL_ARG, "Application does not allow backup or restore").GetCode(); + return BError(BError::Codes::SA_FORBID_BACKUP_RESTORE, "Application does not allow backup or restore") + .GetCode(); } // async do restore. diff --git a/services/backup_sa/include/module_ipc/service.h b/services/backup_sa/include/module_ipc/service.h index aefde85e1..ba9538812 100644 --- a/services/backup_sa/include/module_ipc/service.h +++ b/services/backup_sa/include/module_ipc/service.h @@ -67,7 +67,7 @@ public: * * @param bundleName 应用名称 */ - void OnBackupExtensionDied(const std::string &&bundleName, ErrCode ret); + void OnBackupExtensionDied(const std::string &&bundleName); /** * @brief extension启动连接成功 diff --git a/services/backup_sa/src/module_ipc/service.cpp b/services/backup_sa/src/module_ipc/service.cpp index 7b1613e0d..83c7dcba7 100644 --- a/services/backup_sa/src/module_ipc/service.cpp +++ b/services/backup_sa/src/module_ipc/service.cpp @@ -264,7 +264,7 @@ static vector GetRestoreBundleNames(UniqueFd fd, auto it = find_if(bundleInfos.begin(), bundleInfos.end(), [&restoreInfo](auto &obj) { return obj.name == restoreInfo.name; }); if (it == bundleInfos.end()) { - session->GetServiceReverseProxy()->RestoreOnBundleStarted(BError(BError::Codes::SA_INVAL_ARG), + session->GetServiceReverseProxy()->RestoreOnBundleStarted(BError(BError::Codes::SA_BUNDLE_INFO_EMPTY), restoreInfo.name); continue; } @@ -304,13 +304,13 @@ ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, auto it = find_if(restoreBundleNames.begin(), restoreBundleNames.end(), [&restoreInfo](auto &bundleName) { return bundleName == restoreInfo.name; }); if (it == restoreBundleNames.end()) { - throw BError(BError::Codes::SA_INVAL_ARG, "Can't find bundle name"); + throw BError(BError::Codes::SA_BUNDLE_INFO_EMPTY, "Can't find bundle name"); } HILOGD("bundleName: %{public}s, extensionName: %{public}s", restoreInfo.name.c_str(), restoreInfo.extensionName.c_str()); if (restoreInfo.allToBackup == false && !SpeicalVersion(restoreInfo.versionName, restoreInfo.versionCode)) { - session_->GetServiceReverseProxy()->RestoreOnBundleStarted(BError(BError::Codes::SA_REFUSED_ACT), - restoreInfo.name); + session_->GetServiceReverseProxy()->RestoreOnBundleStarted( + BError(BError::Codes::SA_FORBID_BACKUP_RESTORE), restoreInfo.name); session_->RemoveExtInfo(restoreInfo.name); continue; } @@ -346,8 +346,8 @@ ErrCode Service::AppendBundlesBackupSession(const vector &bundleName session_->SetBundleDataSize(info.name, info.spaceOccupied); session_->SetBackupExtName(info.name, info.extensionName); if (info.allToBackup == false) { - session_->GetServiceReverseProxy()->BackupOnBundleStarted(BError(BError::Codes::SA_REFUSED_ACT), - info.name); + session_->GetServiceReverseProxy()->BackupOnBundleStarted( + BError(BError::Codes::SA_FORBID_BACKUP_RESTORE), info.name); session_->RemoveExtInfo(info.name); } } @@ -574,7 +574,7 @@ ErrCode Service::GetFileHandle(const string &bundleName, const string &fileName) } } -void Service::OnBackupExtensionDied(const string &&bundleName, ErrCode ret) +void Service::OnBackupExtensionDied(const string &&bundleName) { try { string callName = move(bundleName); @@ -673,7 +673,7 @@ void Service::ExtConnectFailed(const string &bundleName, ErrCode ret) session_->GetServiceReverseProxy()->RestoreOnBundleStarted(ret, bundleName); DisposeErr disposeErr = AppGalleryDisposeProxy::GetInstance()->EndRestore(bundleName); - HILOGI("AppGalleryDisposeProxy EndRestore, code=%{public}d, bundleName=%{public}s", disposeErr, + HILOGI("ExtConnectFailed EndRestore, code=%{public}d, bundleName=%{public}s", disposeErr, bundleName.c_str()); } ClearSessionAndSchedInfo(bundleName); @@ -822,7 +822,7 @@ void Service::SendAppGalleryNotify(const BundleName &bundleName) IServiceReverse::Scenario scenario = session_->GetScenario(); if (scenario == IServiceReverse::Scenario::RESTORE) { DisposeErr disposeErr = AppGalleryDisposeProxy::GetInstance()->StartRestore(bundleName); - HILOGI("AppGalleryDisposeProxy StartRestore, code=%{public}d, bundleName=%{public}s", disposeErr, + HILOGI("SendAppGalleryNotify StartRestore, code=%{public}d, bundleName=%{public}s", disposeErr, bundleName.c_str()); } } diff --git a/services/backup_sa/src/module_ipc/service_reverse_proxy.cpp b/services/backup_sa/src/module_ipc/service_reverse_proxy.cpp index d1846c8eb..b7e3a07eb 100644 --- a/services/backup_sa/src/module_ipc/service_reverse_proxy.cpp +++ b/services/backup_sa/src/module_ipc/service_reverse_proxy.cpp @@ -136,7 +136,8 @@ void ServiceReverseProxy::RestoreOnBundleFinished(int32_t errCode, string bundle } DisposeErr disposeErr = AppGalleryDisposeProxy::GetInstance()->EndRestore(bundleName); - HILOGI("AppGalleryDisposeProxy EndRestore, code=%{public}d, bundleName=%{public}s", disposeErr, bundleName.c_str()); + HILOGI("RestoreOnBundleFinished EndRestore, code=%{public}d, bundleName=%{public}s", disposeErr, + bundleName.c_str()); } void ServiceReverseProxy::RestoreOnAllBundlesFinished(int32_t errCode) 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 59d98db8e..f3a34e9fc 100644 --- a/services/backup_sa/src/module_ipc/svc_session_manager.cpp +++ b/services/backup_sa/src/module_ipc/svc_session_manager.cpp @@ -228,7 +228,7 @@ sptr SvcSessionManager::GetBackupExtAbility(const string &b HILOGW("It's curious that the backup sa dies before the backup client"); return; } - revPtrStrong->OnBackupExtensionDied(move(bundleName), ESRCH); + revPtrStrong->OnBackupExtensionDied(move(bundleName)); }; auto callConnDone = [revPtr {reversePtr_}](const string &&bundleName) { @@ -608,7 +608,7 @@ uint32_t SvcSessionManager::CalAppProcessTime(const std::string &bundleName) timeout = defaultTimeout; } resTimeoutMs = (uint32_t)(timeout * invertMillisecond % UINT_MAX); /* conver second to millisecond */ - HILOGI("Calculate App extension process run timeout=%{public}u(s), bundleName=%{public}s ", + HILOGI("Calculate App extension process run timeout=%{public}u(us), bundleName=%{public}s ", resTimeoutMs, bundleName.c_str()); return resTimeoutMs; } diff --git a/services/backup_sa/src/module_sched/sched_scheduler.cpp b/services/backup_sa/src/module_sched/sched_scheduler.cpp index 696d3539e..658fe501f 100644 --- a/services/backup_sa/src/module_sched/sched_scheduler.cpp +++ b/services/backup_sa/src/module_sched/sched_scheduler.cpp @@ -77,7 +77,7 @@ void SchedScheduler::ExecutingQueueTasks(const string &bundleName) HILOGE("Extension connect failed = %{public}s", bundleName.data()); auto ptr = reversePtr.promote(); if (ptr) { - ptr->ExtConnectFailed(bundleName, EPERM); + ptr->ExtConnectFailed(bundleName, BError(BError::Codes::SA_BOOT_TIMEOUT)); } }; auto iTime = extTime_.Register(callStart, BConstants::EXT_CONNECT_MAX_TIME); diff --git a/tests/mock/module_ipc/service_mock.cpp b/tests/mock/module_ipc/service_mock.cpp index 6c69ba3e7..372961277 100644 --- a/tests/mock/module_ipc/service_mock.cpp +++ b/tests/mock/module_ipc/service_mock.cpp @@ -100,7 +100,7 @@ ErrCode Service::GetFileHandle(const string &bundleName, const string &fileName) return BError(BError::Codes::OK); } -void Service::OnBackupExtensionDied(const string &&bundleName, ErrCode ret) {} +void Service::OnBackupExtensionDied(const string &&bundleName) {} void Service::ExtStart(const string &bundleName) {} diff --git a/tests/unittests/backup_sa/module_ipc/service_test.cpp b/tests/unittests/backup_sa/module_ipc/service_test.cpp index b3c4f11f6..902348812 100644 --- a/tests/unittests/backup_sa/module_ipc/service_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_test.cpp @@ -313,12 +313,12 @@ HWTEST_F(ServiceTest, SUB_Service_OnBackupExtensionDied_0100, testing::ext::Test ErrCode ret = Init(IServiceReverse::Scenario::RESTORE); EXPECT_EQ(ret, BError(BError::Codes::OK)); string bundleName = BUNDLE_NAME; - servicePtr_->OnBackupExtensionDied(move(bundleName), BError(BError::Codes::OK)); + servicePtr_->OnBackupExtensionDied(move(bundleName)); GTEST_LOG_(INFO) << "SUB_Service_OnBackupExtensionDied_0100 BACKUP"; ret = Init(IServiceReverse::Scenario::BACKUP); EXPECT_EQ(ret, BError(BError::Codes::OK)); bundleName = BUNDLE_NAME; - servicePtr_->OnBackupExtensionDied(move(bundleName), BError(BError::Codes::OK)); + servicePtr_->OnBackupExtensionDied(move(bundleName)); } catch (...) { EXPECT_TRUE(false); GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by GetFileHandle."; diff --git a/utils/include/b_error/b_error.h b/utils/include/b_error/b_error.h index 37bf19df9..5ad506a64 100644 --- a/utils/include/b_error/b_error.h +++ b/utils/include/b_error/b_error.h @@ -68,6 +68,9 @@ public: SA_BROKEN_IPC = 0x3001, SA_REFUSED_ACT = 0x3002, SA_BROKEN_ROOT_DIR = 0x3003, + SA_FORBID_BACKUP_RESTORE = 0x3004, + SA_BOOT_TIMEOUT = 0x3005, + SA_BUNDLE_INFO_EMPTY = 0x3006, // 0x4000~0x4999 backup_SDK错误 SDK_INVAL_ARG = 0x4000, @@ -91,6 +94,11 @@ public: E_INVAL = 13900020, E_NOSPC = 13900025, E_UKERR = 13900042, + E_FORBID = 13500001, + E_BTO = 13500002, + E_ETO = 13500003, + E_DIED = 13500004, + E_EMPTY = 13500005, }; public: @@ -198,6 +206,9 @@ private: {Codes::SA_BROKEN_IPC, "SA failed to issue a IPC"}, {Codes::SA_REFUSED_ACT, "SA refuse to act"}, {Codes::SA_BROKEN_ROOT_DIR, "SA failed to operate on the given root dir"}, + {Codes::SA_FORBID_BACKUP_RESTORE, "SA forbid backup or restore"}, + {Codes::SA_BOOT_TIMEOUT, "SA boot application extension time out"}, + {Codes::SA_BUNDLE_INFO_EMPTY, "SA the bundle info for backup/restore is empty"}, {Codes::SDK_INVAL_ARG, "SDK received invalid arguments"}, {Codes::SDK_BROKEN_IPC, "SDK failed to do IPC"}, {Codes::SDK_MIXED_SCENARIO, "SDK involed backup/restore when doing the contrary"}, @@ -221,6 +232,9 @@ private: {static_cast(Codes::SA_BROKEN_IPC), BackupErrorCode::E_IPCSS}, {static_cast(Codes::SA_REFUSED_ACT), BackupErrorCode::E_PERM}, {static_cast(Codes::SA_BROKEN_ROOT_DIR), BackupErrorCode::E_UKERR}, + {static_cast(Codes::SA_FORBID_BACKUP_RESTORE), BackupErrorCode::E_FORBID}, + {static_cast(Codes::SA_BOOT_TIMEOUT), BackupErrorCode::E_BTO}, + {static_cast(Codes::SA_BUNDLE_INFO_EMPTY), BackupErrorCode::E_EMPTY}, {static_cast(Codes::SDK_INVAL_ARG), BackupErrorCode::E_INVAL}, {static_cast(Codes::SDK_BROKEN_IPC), BackupErrorCode::E_IPCSS}, {static_cast(Codes::SDK_MIXED_SCENARIO), BackupErrorCode::E_INVAL}, @@ -228,8 +242,8 @@ private: {static_cast(Codes::EXT_BROKEN_FRAMEWORK), BackupErrorCode::E_UKERR}, {static_cast(Codes::EXT_BROKEN_BACKUP_SA), BackupErrorCode::E_IPCSS}, {static_cast(Codes::EXT_BROKEN_IPC), BackupErrorCode::E_IPCSS}, - {static_cast(Codes::EXT_ABILITY_DIED), BackupErrorCode::E_INVAL}, - {static_cast(Codes::EXT_ABILITY_TIMEOUT), BackupErrorCode::E_INVAL}, + {static_cast(Codes::EXT_ABILITY_DIED), BackupErrorCode::E_DIED}, + {static_cast(Codes::EXT_ABILITY_TIMEOUT), BackupErrorCode::E_ETO}, {BackupErrorCode::E_IPCSS, BackupErrorCode::E_IPCSS}, {BackupErrorCode::E_INVAL, BackupErrorCode::E_INVAL}, {BackupErrorCode::E_UKERR, BackupErrorCode::E_UKERR}, @@ -237,6 +251,11 @@ private: {BackupErrorCode::E_NOMEM, BackupErrorCode::E_NOMEM}, {BackupErrorCode::E_NOSPC, BackupErrorCode::E_NOSPC}, {BackupErrorCode::E_IO, BackupErrorCode::E_IO}, + {BackupErrorCode::E_FORBID, BackupErrorCode::E_FORBID}, + {BackupErrorCode::E_BTO, BackupErrorCode::E_BTO}, + {BackupErrorCode::E_ETO, BackupErrorCode::E_ETO}, + {BackupErrorCode::E_DIED, BackupErrorCode::E_DIED}, + {BackupErrorCode::E_EMPTY, BackupErrorCode::E_EMPTY}, }; private: -- Gitee