From f1b46220ac975dce373d70ab5577ae5c5b4e3b04 Mon Sep 17 00:00:00 2001 From: dwx1282457 Date: Wed, 22 Nov 2023 19:03:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=89=E8=A3=85=E5=8A=9F=E8=83=BD=E4=B8=8B?= =?UTF-8?q?=E6=9E=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: dwx1282457 --- backup.gni | 1 - services/backup_sa/BUILD.gn | 1 - .../include/module_external/bms_adapter.h | 10 +-- .../module_external/inner_receiver_impl.h | 44 ------------ .../include/module_ipc/svc_session_manager.h | 35 ---------- .../include/module_sched/sched_scheduler.h | 16 ----- .../src/module_external/bms_adapter.cpp | 33 +-------- .../module_external/inner_receiver_impl.cpp | 44 ------------ .../src/module_external/sms_adapter.cpp | 4 ++ services/backup_sa/src/module_ipc/service.cpp | 16 ----- .../src/module_ipc/svc_session_manager.cpp | 50 +------------- .../src/module_sched/sched_scheduler.cpp | 67 +------------------ .../mock/module_external/bms_adapter_mock.cpp | 2 +- .../inner_receiver_impl_mock.cpp | 2 - .../module_ipc/svc_session_manager_mock.cpp | 14 ---- .../module_sched/sched_scheduler_mock.cpp | 2 - .../module_ipc/svc_session_manager_test.cpp | 46 ------------- tools/backup_tool/src/tools_op_restore.cpp | 30 +-------- .../src/tools_op_restore_async.cpp | 19 +----- utils/include/b_json/b_json_entity_caps.h | 4 +- utils/src/b_json/b_json_entity_ext_manage.cpp | 6 -- 21 files changed, 17 insertions(+), 429 deletions(-) delete mode 100644 services/backup_sa/include/module_external/inner_receiver_impl.h delete mode 100644 services/backup_sa/src/module_external/inner_receiver_impl.cpp diff --git a/backup.gni b/backup.gni index bfe01b0c1..3b07587da 100644 --- a/backup.gni +++ b/backup.gni @@ -49,7 +49,6 @@ backup_mock_scheduler_src = [ "$path_backup_mock/module_sched/sched_scheduler_mock.cpp" ] backup_mock_module_external_src = [ "$path_backup_mock/module_external/bms_adapter_mock.cpp", - "$path_backup_mock/module_external/inner_receiver_impl_mock.cpp", "$path_backup_mock/module_external/sms_adapter_mock.cpp", ] backup_mock_service_src = [ "$path_backup_mock/module_ipc/service_mock.cpp" ] diff --git a/services/backup_sa/BUILD.gn b/services/backup_sa/BUILD.gn index cf8de03ca..4edee6b28 100644 --- a/services/backup_sa/BUILD.gn +++ b/services/backup_sa/BUILD.gn @@ -18,7 +18,6 @@ ohos_shared_library("backup_sa") { sources = [ "src/module_app_gallery/app_gallery_dispose_proxy.cpp", "src/module_external/bms_adapter.cpp", - "src/module_external/inner_receiver_impl.cpp", "src/module_external/sms_adapter.cpp", "src/module_ipc/service.cpp", "src/module_ipc/service_reverse_proxy.cpp", diff --git a/services/backup_sa/include/module_external/bms_adapter.h b/services/backup_sa/include/module_external/bms_adapter.h index e96aab688..48ac79706 100644 --- a/services/backup_sa/include/module_external/bms_adapter.h +++ b/services/backup_sa/include/module_external/bms_adapter.h @@ -45,15 +45,7 @@ public: static std::vector GetBundleInfos( const std::vector &bundleNames, int32_t userId); - /** - * @brief Install bundle - * - * @param bundleName bundle name - * @param bundleFilePath bundle file path - * @param userId User ID - */ - static ErrCode Install(wptr statusReceiver, const std::string &bundleFilePath, int32_t userId); - + /** * @brief Get app gallery bundle name */ diff --git a/services/backup_sa/include/module_external/inner_receiver_impl.h b/services/backup_sa/include/module_external/inner_receiver_impl.h deleted file mode 100644 index 933603f9d..000000000 --- a/services/backup_sa/include/module_external/inner_receiver_impl.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2023 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_INNERRECEIVER_H -#define OHOS_FILEMGMT_BACKUP_INNERRECEIVER_H - -#include - -#include - -#include "status_receiver_host.h" - -namespace OHOS::FileManagement::Backup { -class SchedScheduler; - -class InnerReceiverImpl : public AppExecFwk::StatusReceiverHost { -public: - virtual void OnStatusNotify(const int progress) override; - virtual void OnFinished(const int32_t resultCode, const std::string &resultMsg) override; - - std::string GetBundleName(); - -public: - InnerReceiverImpl(const std::string &bundleName, wptr sched) - : bundleName_(bundleName), sched_(sched) {}; - -private: - std::string bundleName_; - wptr sched_; -}; -} // namespace OHOS::FileManagement::Backup -#endif // OHOS_FILEMGMT_BACKUP_INNERRECEIVER_H \ No newline at end of file diff --git a/services/backup_sa/include/module_ipc/svc_session_manager.h b/services/backup_sa/include/module_ipc/svc_session_manager.h index 5050bbc23..eaf0a23c8 100644 --- a/services/backup_sa/include/module_ipc/svc_session_manager.h +++ b/services/backup_sa/include/module_ipc/svc_session_manager.h @@ -46,8 +46,6 @@ struct BackupExtInfo { sptr backUpConnection; std::set fileNameInfo; BConstants::ServiceSchedAction schedAction {BConstants::ServiceSchedAction::WAIT}; - bool bNeedToInstall {false}; - std::string installState; /* [RESTORE] Record whether data backup is required during the app exec restore proceess. */ RestoreTypeEnum restoreType; /* Clone App: old device app versionCode */ @@ -279,39 +277,6 @@ public: */ bool IsOnOnStartSched(); - /** - * @brief Set the Install State object - * - * @param bundleName - * @param state - */ - void SetInstallState(const std::string &bundleName, const std::string &state); - - /** - * @brief Get the Install State object - * - * @param bundleName - * @return std::string - */ - std::string GetInstallState(const std::string &bundleName); - - /** - * @brief Set the Need To Install object - * - * @param bundleName - * @param needToInstall - */ - void SetNeedToInstall(const std::string &bundleName, bool needToInstall); - - /** - * @brief Get the Need To Install object - * - * @param bundleName - * @return true - * @return false - */ - bool GetNeedToInstall(const std::string &bundleName); - /** * @brief Whether to unload the service * diff --git a/services/backup_sa/include/module_sched/sched_scheduler.h b/services/backup_sa/include/module_sched/sched_scheduler.h index 30415c6c1..24bba99e5 100644 --- a/services/backup_sa/include/module_sched/sched_scheduler.h +++ b/services/backup_sa/include/module_sched/sched_scheduler.h @@ -54,14 +54,6 @@ public: */ void RemoveExtConn(const std::string &bundleName); - /** - * @brief install success - * - * @param bundleName - * @param resultCode - */ - void InstallSuccess(const std::string &bundleName, const int32_t resultCode); - /** * @brief try unload service timer * @@ -89,14 +81,6 @@ public: bundleTimeVec_.clear(); } -private: - /** - * @brief install state - * - * @param bundleName - */ - void InstallingState(const std::string &bundleName); - private: mutable std::shared_mutex lock_; OHOS::ThreadPool threadPool_; diff --git a/services/backup_sa/src/module_external/bms_adapter.cpp b/services/backup_sa/src/module_external/bms_adapter.cpp index 2e2a25e94..1e0506012 100644 --- a/services/backup_sa/src/module_external/bms_adapter.cpp +++ b/services/backup_sa/src/module_external/bms_adapter.cpp @@ -25,7 +25,6 @@ #include "filemgmt_libhilog.h" #include "install_param.h" #include "iservice_registry.h" -#include "module_external/inner_receiver_impl.h" #include "module_external/sms_adapter.h" #include "module_ipc/service.h" #include "module_ipc/svc_session_manager.h" @@ -121,7 +120,7 @@ vector BundleMgrAdapter::GetBundleInfos(int32_t use auto dataSize = GetBundleStats(installedBundle.name, userId); bundleInfos.emplace_back(BJsonEntityCaps::BundleInfo {installedBundle.name, installedBundle.versionCode, installedBundle.versionName, dataSize, allToBackup, - extName, false, restoreDeps}); + extName, restoreDeps}); } return bundleInfos; } @@ -145,39 +144,11 @@ vector BundleMgrAdapter::GetBundleInfos(const vecto auto dataSize = GetBundleStats(installedBundle.name, userId); bundleInfos.emplace_back(BJsonEntityCaps::BundleInfo {installedBundle.name, installedBundle.versionCode, installedBundle.versionName, dataSize, allToBackup, - extName, false, restoreDeps}); + extName, restoreDeps}); } return bundleInfos; } -ErrCode BundleMgrAdapter::Install(wptr statusReceiver, const string &bundleFilePath, int32_t userId) -{ - HILOGI("Begin"); - auto bms = GetBundleManager(); - AppExecFwk::BundleInfo bundleInfo; - if (!bms->GetBundleArchiveInfo(bundleFilePath, AppExecFwk::BundleFlag::GET_BUNDLE_WITH_ABILITIES, bundleInfo)) { - return BError(BError::Codes::SA_BROKEN_IPC, "Failed to get bundle archive info").GetCode(); - } - auto receiver = statusReceiver.promote(); - if (receiver == nullptr) { - return BError(BError::Codes::SA_BROKEN_IPC, "Failed to get receiver").GetCode(); - } - // check bundle name - if (bundleInfo.name != receiver->GetBundleName()) { - return BError(BError::Codes::SA_INVAL_ARG, "Bundle name is not match").GetCode(); - } - - auto install = bms->GetBundleInstaller(); - if (!install) { - return BError(BError::Codes::SA_BROKEN_IPC, "Failed to get bundle installer").GetCode(); - } - - AppExecFwk::InstallParam installParam; - installParam.installFlag = AppExecFwk::InstallFlag::REPLACE_EXISTING; - installParam.userId = userId; - return install->StreamInstall({bundleFilePath}, installParam, receiver); -} - string BundleMgrAdapter::GetAppGalleryBundleName() { auto bms = GetBundleManager(); diff --git a/services/backup_sa/src/module_external/inner_receiver_impl.cpp b/services/backup_sa/src/module_external/inner_receiver_impl.cpp deleted file mode 100644 index 039159798..000000000 --- a/services/backup_sa/src/module_external/inner_receiver_impl.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2023 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 "module_external/inner_receiver_impl.h" - -#include "b_error/b_error.h" -#include "filemgmt_libhilog.h" -#include "module_ipc/svc_session_manager.h" -#include "module_sched/sched_scheduler.h" -#include "module_ipc/service.h" - -namespace OHOS::FileManagement::Backup { -void InnerReceiverImpl::OnStatusNotify(const int progress) -{ - HILOGI("OnStatusNotify %{public}d", progress); -} -void InnerReceiverImpl::OnFinished(const int32_t resultCode, const std::string &resultMsg) -{ - HILOGI("Finished to install %{public}s, resultCode = %{public}d resultMsg = %{public}s", bundleName_.c_str(), - resultCode, resultMsg.c_str()); - - auto sched = sched_.promote(); - if (sched == nullptr) { - throw BError(BError::Codes::SA_INVAL_ARG, std::string("Failed to promote bundleContext")); - } - sched->InstallSuccess(bundleName_, resultCode); -} -std::string InnerReceiverImpl::GetBundleName() -{ - return bundleName_; -} -} // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/services/backup_sa/src/module_external/sms_adapter.cpp b/services/backup_sa/src/module_external/sms_adapter.cpp index e6613ed2c..d74b3930d 100644 --- a/services/backup_sa/src/module_external/sms_adapter.cpp +++ b/services/backup_sa/src/module_external/sms_adapter.cpp @@ -37,6 +37,8 @@ static sptr GetStorageManager() throw BError(BError::Codes::SA_BROKEN_IPC, "Failed to get system ability manager"); } + + auto storageObj = saMgr->GetSystemAbility(STORAGE_MANAGER_MANAGER_ID); if (storageObj == nullptr) { throw BError(BError::Codes::SA_BROKEN_IPC, "Failed to get storage manager service"); @@ -70,3 +72,5 @@ int64_t StorageMgrAdapter::GetUserStorageStats(const std::string &bundleName, in return 0; } } // namespace OHOS::FileManagement::Backup + + diff --git a/services/backup_sa/src/module_ipc/service.cpp b/services/backup_sa/src/module_ipc/service.cpp index d33611279..2fd94c395 100644 --- a/services/backup_sa/src/module_ipc/service.cpp +++ b/services/backup_sa/src/module_ipc/service.cpp @@ -252,7 +252,6 @@ static bool GetRestoreBundleNames(const vector &bun .spaceOccupied = (*it).spaceOccupied, .allToBackup = (*it).allToBackup, .extensionName = restoreInfo.extensionName, - .needToInstall = (*it).needToInstall, .restoreDeps = (*it).restoreDeps}; restoreBundleInfos.emplace_back(info); } @@ -292,7 +291,6 @@ ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, if (bundleInfo.name != bundleName) { continue; } - session_->SetNeedToInstall(bundleInfo.name, bundleInfo.needToInstall); session_->SetBundleRestoreType(bundleInfo.name, restoreType); session_->SetBundleVersionCode(bundleInfo.name, bundleInfo.versionCode); session_->SetBundleVersionName(bundleInfo.name, bundleInfo.versionName); @@ -348,11 +346,6 @@ ErrCode Service::PublishFile(const BFileInfo &fileInfo) HILOGI("Begin"); VerifyCaller(IServiceReverse::Scenario::RESTORE); - if (fileInfo.fileName == BConstants::RESTORE_INSTALL_PATH) { - session_->SetInstallState(fileInfo.owner, "OK"); - sched_->Sched(fileInfo.owner); - return BError(BError::Codes::OK); - } if (fileInfo.fileName.find('/') != string::npos) { throw BError(BError::Codes::SA_INVAL_ARG, "Filename is not valid"); } @@ -510,14 +503,6 @@ ErrCode Service::GetFileHandle(const string &bundleName, const string &fileName) try { HILOGI("Begin"); VerifyCaller(IServiceReverse::Scenario::RESTORE); - if (fileName == BConstants::RESTORE_INSTALL_PATH && bundleName.find('/') == string::npos) { - session_->SetInstallState(bundleName, string(BConstants::RESTORE_INSTALL_PATH)); - auto action = session_->GetServiceSchedAction(bundleName); - if (action == BConstants::ServiceSchedAction::INSTALLING) { - sched_->Sched(bundleName); - } - return BError(BError::Codes::OK); - } if (fileName.find('/') != string::npos) { throw BError(BError::Codes::SA_INVAL_ARG, "Filename is not valid"); } @@ -748,7 +733,6 @@ void Service::HandleRestoreDepsBundle(const string &bundleName) continue; } SvcRestoreDepsManager::RestoreInfo info = bundle.second; - session_->SetNeedToInstall(bundleInfo.name, bundleInfo.needToInstall); session_->SetBundleRestoreType(bundleInfo.name, info.restoreType_); session_->SetBundleVersionCode(bundleInfo.name, bundleInfo.versionCode); session_->SetBundleVersionName(bundleInfo.name, bundleInfo.versionName); 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..7729f3af4 100644 --- a/services/backup_sa/src/module_ipc/svc_session_manager.cpp +++ b/services/backup_sa/src/module_ipc/svc_session_manager.cpp @@ -354,7 +354,7 @@ void SvcSessionManager::SetServiceSchedAction(const string &bundleName, BConstan auto it = GetBackupExtNameMap(bundleName); it->second.schedAction = action; - if (it->second.schedAction == BConstants::ServiceSchedAction::INSTALLING) { + if (it->second.schedAction == BConstants::ServiceSchedAction::START) { extConnectNum_++; } } @@ -451,54 +451,6 @@ bool SvcSessionManager::IsOnOnStartSched() return false; } -void SvcSessionManager::SetInstallState(const string &bundleName, const string &state) -{ - HILOGI("Begin"); - unique_lock lock(lock_); - if (!impl_.clientToken) { - throw BError(BError::Codes::SA_INVAL_ARG, "No caller token was specified"); - } - - auto it = GetBackupExtNameMap(bundleName); - it->second.installState = state; -} - -string SvcSessionManager::GetInstallState(const string &bundleName) -{ - HILOGI("Begin"); - shared_lock lock(lock_); - if (!impl_.clientToken) { - throw BError(BError::Codes::SA_INVAL_ARG, "No caller token was specified"); - } - - auto it = GetBackupExtNameMap(bundleName); - return it->second.installState; -} - -void SvcSessionManager::SetNeedToInstall(const std::string &bundleName, bool needToInstall) -{ - HILOGI("Begin"); - unique_lock lock(lock_); - if (!impl_.clientToken) { - throw BError(BError::Codes::SA_INVAL_ARG, "No caller token was specified"); - } - - auto it = GetBackupExtNameMap(bundleName); - it->second.bNeedToInstall = needToInstall; -} - -bool SvcSessionManager::GetNeedToInstall(const std::string &bundleName) -{ - HILOGI("Begin"); - shared_lock lock(lock_); - if (!impl_.clientToken) { - throw BError(BError::Codes::SA_INVAL_ARG, "No caller token was specified"); - } - - auto it = GetBackupExtNameMap(bundleName); - return it->second.bNeedToInstall; -} - bool SvcSessionManager::NeedToUnloadService() { unique_lock lock(lock_); diff --git a/services/backup_sa/src/module_sched/sched_scheduler.cpp b/services/backup_sa/src/module_sched/sched_scheduler.cpp index 696d3539e..88cd89698 100644 --- a/services/backup_sa/src/module_sched/sched_scheduler.cpp +++ b/services/backup_sa/src/module_sched/sched_scheduler.cpp @@ -31,7 +31,6 @@ #include "filemgmt_libhilog.h" #include "iservice_registry.h" #include "module_external/bms_adapter.h" -#include "module_external/inner_receiver_impl.h" #include "module_ipc/service.h" #include "module_ipc/svc_session_manager.h" #include "system_ability_definition.h" @@ -47,7 +46,7 @@ void SchedScheduler::Sched(string bundleName) } BConstants::ServiceSchedAction action = sessionPtr_->GetServiceSchedAction(bundleName); if (action == BConstants::ServiceSchedAction::WAIT) { - sessionPtr_->SetServiceSchedAction(bundleName, BConstants::ServiceSchedAction::INSTALLING); + sessionPtr_->SetServiceSchedAction(bundleName, BConstants::ServiceSchedAction::START); } } HILOGE("Sched bundleName %{public}s", bundleName.data()); @@ -69,7 +68,6 @@ void SchedScheduler::Sched(string bundleName) void SchedScheduler::ExecutingQueueTasks(const string &bundleName) { HILOGE("start"); - InstallingState(bundleName); BConstants::ServiceSchedAction action = sessionPtr_->GetServiceSchedAction(bundleName); if (action == BConstants::ServiceSchedAction::START) { // 注册启动定时器 @@ -119,54 +117,6 @@ void SchedScheduler::RemoveExtConn(const string &bundleName) } } -static bool GetRealPath(string &path) -{ - unique_ptr absPath = make_unique(PATH_MAX + 1); - if (realpath(path.c_str(), absPath.get()) == nullptr) { - return false; - } - path = absPath.get(); - return true; -} - -void SchedScheduler::InstallingState(const string &bundleName) -{ - BConstants::ServiceSchedAction action = sessionPtr_->GetServiceSchedAction(bundleName); - if (action == BConstants::ServiceSchedAction::INSTALLING) { - IServiceReverse::Scenario scenario = sessionPtr_->GetScenario(); - if (scenario == IServiceReverse::Scenario::BACKUP || !sessionPtr_->GetNeedToInstall(bundleName)) { - sessionPtr_->SetServiceSchedAction(bundleName, BConstants::ServiceSchedAction::START); - return; - } - string state = sessionPtr_->GetInstallState(bundleName); - string path = BConstants::GetSaBundleBackupRootDir(sessionPtr_->GetSessionUserId()).append(bundleName); - string filePath = path + "/bundle.hap"; - - if (state == BConstants::RESTORE_INSTALL_PATH) { - if (!ForceCreateDirectory(path)) { - throw BError(BError::Codes::SA_INVAL_ARG, string("Failed to create directory")); - } - auto ret = GetRealPath(filePath); - HILOGE("ret = %{public}d", ret); - sessionPtr_->GetServiceReverseProxy()->RestoreOnFileReady( - bundleName, state, - UniqueFd(open(filePath.data(), O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IROTH))); - } else if (state == "OK") { - if (!GetRealPath(filePath)) { - throw BError(BError::Codes::SA_INVAL_ARG, string("File path is invalid")); - } - if (access(filePath.data(), F_OK) != 0) { - throw BError(BError::Codes::SA_INVAL_ARG, string("File already exists")); - } - sptr statusReceiver = sptr(new InnerReceiverImpl(bundleName, wptr(this))); - ErrCode err = BundleMgrAdapter::Install(statusReceiver, filePath, sessionPtr_->GetSessionUserId()); - if (err != ERR_OK) { - InstallSuccess(bundleName, err); - } - } - } -} - void SchedScheduler::TryUnloadServiceTimer(bool force) { auto tryUnload = [sessionPtr {sessionPtr_}]() { @@ -209,19 +159,4 @@ void SchedScheduler::TryUnloadServiceTimer(bool force) } tryUnload(); } - -void SchedScheduler::InstallSuccess(const std::string &bundleName, const int32_t resultCode) -{ - if (!resultCode) { - sessionPtr_->SetServiceSchedAction(bundleName, BConstants::ServiceSchedAction::START); - Sched(bundleName); - } else { - sessionPtr_->GetServiceReverseProxy()->RestoreOnBundleStarted(resultCode, bundleName); - sessionPtr_->RemoveExtInfo(bundleName); - } - string path = BConstants::GetSaBundleBackupRootDir(sessionPtr_->GetSessionUserId()).append(bundleName); - if (!ForceRemoveDirectory(path)) { - HILOGE("RemoveDirectory failed"); - } -} }; // namespace OHOS::FileManagement::Backup diff --git a/tests/mock/module_external/bms_adapter_mock.cpp b/tests/mock/module_external/bms_adapter_mock.cpp index 60b632d10..66ccd3a39 100644 --- a/tests/mock/module_external/bms_adapter_mock.cpp +++ b/tests/mock/module_external/bms_adapter_mock.cpp @@ -21,7 +21,7 @@ #include "b_json/b_json_entity_extension_config.h" #include "bundle_mgr_client.h" -#include "module_external/inner_receiver_impl.h" + #include "module_ipc/service.h" #include "module_ipc/svc_session_manager.h" #include "module_sched/sched_scheduler.h" diff --git a/tests/mock/module_external/inner_receiver_impl_mock.cpp b/tests/mock/module_external/inner_receiver_impl_mock.cpp index 4d1d6a349..1c41d4c00 100644 --- a/tests/mock/module_external/inner_receiver_impl_mock.cpp +++ b/tests/mock/module_external/inner_receiver_impl_mock.cpp @@ -13,8 +13,6 @@ * limitations under the License. */ -#include "module_external/inner_receiver_impl.h" - #include #include diff --git a/tests/mock/module_ipc/svc_session_manager_mock.cpp b/tests/mock/module_ipc/svc_session_manager_mock.cpp index 519646b28..b73500606 100644 --- a/tests/mock/module_ipc/svc_session_manager_mock.cpp +++ b/tests/mock/module_ipc/svc_session_manager_mock.cpp @@ -223,20 +223,6 @@ bool SvcSessionManager::IsOnOnStartSched() return true; } -void SvcSessionManager::SetInstallState(const string &bundleName, const string &state) {} - -string SvcSessionManager::GetInstallState(const string &bundleName) -{ - return "OK"; -} - -void SvcSessionManager::SetNeedToInstall(const std::string &bundleName, bool needToInstall) {} - -bool SvcSessionManager::GetNeedToInstall(const std::string &bundleName) -{ - return false; -} - bool SvcSessionManager::NeedToUnloadService() { return false; diff --git a/tests/mock/module_sched/sched_scheduler_mock.cpp b/tests/mock/module_sched/sched_scheduler_mock.cpp index b44f94ebd..6a504fd06 100644 --- a/tests/mock/module_sched/sched_scheduler_mock.cpp +++ b/tests/mock/module_sched/sched_scheduler_mock.cpp @@ -30,8 +30,6 @@ void SchedScheduler::ExecutingQueueTasks(const string &bundleName) {} void SchedScheduler::RemoveExtConn(const string &bundleName) {} -void SchedScheduler::InstallingState(const string &bundleName) {} - void SchedScheduler::TryUnloadServiceTimer(bool force) {} void SchedScheduler::InstallSuccess(const std::string &bundleName, const int32_t resultCode) {} diff --git a/tests/unittests/backup_sa/module_ipc/svc_session_manager_test.cpp b/tests/unittests/backup_sa/module_ipc/svc_session_manager_test.cpp index f3e04a938..3bab966c6 100644 --- a/tests/unittests/backup_sa/module_ipc/svc_session_manager_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/svc_session_manager_test.cpp @@ -349,52 +349,6 @@ HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_GetBackupExtName_0100, tes GTEST_LOG_(INFO) << "SvcSessionManagerTest-end SUB_backup_sa_session_GetBackupExtName_0100"; } -/** - * @tc.number: SUB_backup_sa_session_GetInstallState_0100 - * @tc.name: SUB_backup_sa_session_GetInstallState_0100 - * @tc.desc: 测试 GetInstallState 接口 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6VA38 - */ -HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_GetInstallState_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "SvcSessionManagerTest-begin SUB_backup_sa_session_GetInstallState_0100"; - try { - sessionManagerPtr_->SetInstallState(BUNDLE_NAME, "OK"); - auto ret = sessionManagerPtr_->GetInstallState(BUNDLE_NAME); - EXPECT_EQ(ret, "OK"); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "SvcSessionManagerTest-an exception occurred by GetInstallState."; - } - GTEST_LOG_(INFO) << "SvcSessionManagerTest-end SUB_backup_sa_session_GetInstallState_0100"; -} - -/** - * @tc.number: SUB_backup_sa_session_GetNeedToInstall_0100 - * @tc.name: SUB_backup_sa_session_GetNeedToInstall_0100 - * @tc.desc: 测试 GetNeedToInstall 接口 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I6VA38 - */ -HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_GetNeedToInstall_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "SvcSessionManagerTest-begin SUB_backup_sa_session_GetNeedToInstall_0100"; - try { - sessionManagerPtr_->SetNeedToInstall(BUNDLE_NAME, true); - auto ret = sessionManagerPtr_->GetNeedToInstall(BUNDLE_NAME); - EXPECT_EQ(ret, true); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "SvcSessionManagerTest-an exception occurred by GetNeedToInstall."; - } - GTEST_LOG_(INFO) << "SvcSessionManagerTest-end SUB_backup_sa_session_GetNeedToInstall_0100"; -} - /** * @tc.number: SUB_backup_sa_session_NeedToUnloadService_0100 * @tc.name: SUB_backup_sa_session_NeedToUnloadService_0100 diff --git a/tools/backup_tool/src/tools_op_restore.cpp b/tools/backup_tool/src/tools_op_restore.cpp index 90c3538c3..dcaeb6725 100644 --- a/tools/backup_tool/src/tools_op_restore.cpp +++ b/tools/backup_tool/src/tools_op_restore.cpp @@ -54,13 +54,6 @@ public: bundleStatusMap_[bundleName].sendFile.insert(fileName); } - void UpdateBundleSentFiles(const BundleName &bundleName, const string &fileName) - { - lock_guard lk(lock_); - bundleStatusMap_[bundleName].sentFile.insert(fileName); - TryClearBundleOfMap(bundleName); - } - void ClearBundleOfMap(const BundleName &bundleName) { lock_guard lk(lock_); @@ -131,17 +124,10 @@ static void OnFileReady(shared_ptr ctx, const BFileInfo &fileInfo, Uniq { printf("FileReady owner = %s, fileName = %s, sn = %u, fd = %d\n", fileInfo.owner.c_str(), fileInfo.fileName.c_str(), fileInfo.sn, fd.Get()); - if (fileInfo.fileName.find('/') != string::npos && - fileInfo.fileName != BConstants::RESTORE_INSTALL_PATH) { + if (fileInfo.fileName.find('/') != string::npos ) { throw BError(BError::Codes::TOOL_INVAL_ARG, "Filename is not valid"); } - string tmpPath; - if (fileInfo.fileName == BConstants::RESTORE_INSTALL_PATH) { - printf("OnFileReady bundle hap\n"); - tmpPath = string(BConstants::BACKUP_TOOL_INSTALL_DIR) + fileInfo.owner + ".hap"; - } else { - tmpPath = string(BConstants::BACKUP_TOOL_RECEIVE_DIR) + fileInfo.owner + "/" + fileInfo.fileName; - } + string tmpPath = string(BConstants::BACKUP_TOOL_RECEIVE_DIR) + fileInfo.owner + "/" + fileInfo.fileName; if (access(tmpPath.data(), F_OK) != 0) { throw BError(BError::Codes::TOOL_INVAL_ARG, generic_category().message(errno)); } @@ -154,9 +140,6 @@ static void OnFileReady(shared_ptr ctx, const BFileInfo &fileInfo, Uniq if (ret != 0) { throw BError(BError::Codes::TOOL_INVAL_ARG, "PublishFile error"); } - if (fileInfo.fileName != BConstants::RESTORE_INSTALL_PATH) { - ctx->UpdateBundleSentFiles(fileInfo.owner, fileInfo.fileName); - } ctx->TryNotify(); } @@ -219,12 +202,6 @@ static void RestoreApp(shared_ptr restore, vector &bundleNa if (err != 0) { throw BError(BError::Codes::TOOL_INVAL_ARG, "error path"); } - // install bundle.hap - string installPath = string(BConstants::BACKUP_TOOL_INSTALL_DIR) + bundleName + ".hap"; - if (access(installPath.data(), F_OK) == 0) { - printf("install bundle hap %s\n", installPath.c_str()); - restore->session_->GetFileHandle(bundleName, string(BConstants::RESTORE_INSTALL_PATH)); - } for (auto &filePath : filePaths) { string fileName = filePath.substr(filePath.rfind("/") + 1); restore->session_->GetFileHandle(bundleName, fileName); @@ -263,8 +240,7 @@ static int32_t InitFd(UniqueFd &fd, const vector &bundleNames) for (auto name : bundleNames) { string installPath = string(BConstants::BACKUP_TOOL_INSTALL_DIR) + name + ".hap"; if (access(installPath.data(), F_OK) == 0) { - bool needToInstall = true; - bundleInfos.emplace_back(BJsonEntityCaps::BundleInfo {.name = name, .needToInstall = needToInstall}); + bundleInfos.emplace_back(BJsonEntityCaps::BundleInfo {.name = name}); } } cache.SetBundleInfos(bundleInfos); diff --git a/tools/backup_tool/src/tools_op_restore_async.cpp b/tools/backup_tool/src/tools_op_restore_async.cpp index 6869963ec..0ca9dab71 100644 --- a/tools/backup_tool/src/tools_op_restore_async.cpp +++ b/tools/backup_tool/src/tools_op_restore_async.cpp @@ -81,17 +81,10 @@ static void OnFileReady(shared_ptr ctx, const BFileInfo &fileInfo, { printf("FileReady owner = %s, fileName = %s, sn = %u, fd = %d\n", fileInfo.owner.c_str(), fileInfo.fileName.c_str(), fileInfo.sn, fd.Get()); - if (fileInfo.fileName.find('/') != string::npos && - fileInfo.fileName != BConstants::RESTORE_INSTALL_PATH) { + if (fileInfo.fileName.find('/') != string::npos) { throw BError(BError::Codes::TOOL_INVAL_ARG, "Filename is not valid"); } - string tmpPath; - if (fileInfo.fileName == BConstants::RESTORE_INSTALL_PATH) { - printf("OnFileReady bundle hap\n"); - tmpPath = string(BConstants::BACKUP_TOOL_INSTALL_DIR) + fileInfo.owner + ".hap"; - } else { - tmpPath = string(BConstants::BACKUP_TOOL_RECEIVE_DIR) + fileInfo.owner + "/" + fileInfo.fileName; - } + string tmpPath = string(BConstants::BACKUP_TOOL_RECEIVE_DIR) + fileInfo.owner + "/" + fileInfo.fileName; if (access(tmpPath.data(), F_OK) != 0) { throw BError(BError::Codes::TOOL_INVAL_ARG, generic_category().message(errno)); } @@ -155,12 +148,6 @@ static void RestoreApp(shared_ptr restore, vector &bun if (err != 0) { throw BError(BError::Codes::TOOL_INVAL_ARG, "error path"); } - // install bundle.hap - string installPath = string(BConstants::BACKUP_TOOL_INSTALL_DIR) + bundleName + ".hap"; - if (access(installPath.data(), F_OK) == 0) { - printf("install bundle hap %s\n", installPath.c_str()); - restore->session_->GetFileHandle(bundleName, string(BConstants::RESTORE_INSTALL_PATH)); - } for (auto &filePath : filePaths) { string fileName = filePath.substr(filePath.rfind("/") + 1); restore->session_->GetFileHandle(bundleName, fileName); @@ -192,7 +179,7 @@ static int32_t ChangeBundleInfo(const string &pathCapFile, const vector bundleInfos.emplace_back(BJsonEntityCaps::BundleInfo { .name = name, .versionCode = versionCode, .versionName = versionName, .spaceOccupied = bundleInfo.spaceOccupied, .allToBackup = bundleInfo.allToBackup, - .extensionName = bundleInfo.extensionName, .needToInstall = false}); + .extensionName = bundleInfo.extensionName}); } } cache.SetBundleInfos(bundleInfos); diff --git a/utils/include/b_json/b_json_entity_caps.h b/utils/include/b_json/b_json_entity_caps.h index db51d4270..5a1110ed1 100644 --- a/utils/include/b_json/b_json_entity_caps.h +++ b/utils/include/b_json/b_json_entity_caps.h @@ -29,7 +29,6 @@ public: int64_t spaceOccupied; bool allToBackup; std::string extensionName; - bool needToInstall {false}; std::string restoreDeps; }; @@ -57,7 +56,6 @@ public: arrObj["spaceOccupied"] = item.spaceOccupied; arrObj["allToBackup"] = item.allToBackup; arrObj["extensionName"] = item.extensionName; - arrObj["needToInstall"] = item.needToInstall; arrObj["restoreDeps"] = item.restoreDeps; obj_["bundleInfos"].append(arrObj); } @@ -115,7 +113,7 @@ public: bundleInfos.emplace_back(BundleInfo {item["name"].asString(), item["versionCode"].asUInt(), item["versionName"].asString(), item["spaceOccupied"].asInt64(), item["allToBackup"].asBool(), item["extensionName"].asString(), - item["needToInstall"].asBool(), restoreDeps}); + restoreDeps}); } return bundleInfos; } diff --git a/utils/src/b_json/b_json_entity_ext_manage.cpp b/utils/src/b_json/b_json_entity_ext_manage.cpp index bff04e1d7..6a0aa92b1 100644 --- a/utils/src/b_json/b_json_entity_ext_manage.cpp +++ b/utils/src/b_json/b_json_entity_ext_manage.cpp @@ -133,9 +133,6 @@ void BJsonEntityExtManage::SetExtManage(const mapfirst; - if (std::get<0>(item->second) == BConstants::RESTORE_INSTALL_PATH) { - throw BError(BError::Codes::UTILS_INVAL_JSON_ENTITY, "Failed to set ext manage, invalid path"); - } auto [path, sta, isBeforeTar] = item->second; value["information"]["path"] = path; value["information"]["stat"] = Stat2JsonValue(sta); @@ -192,9 +189,6 @@ std::vector BJsonEntityExtManage::GetExtManageInfo() const string path = item["information"].isMember("path") && item["information"]["path"].isString() ? item["information"]["path"].asString() : ""; - if (path == BConstants::RESTORE_INSTALL_PATH) { - throw BError(BError::Codes::UTILS_INVAL_JSON_ENTITY, "Failed to get ext manage info, invalid path"); - } if (item["information"].isMember("stat")) { sta = JsonValue2Stat(item["information"]["stat"]); } -- Gitee