From eec19b82fa3b4deec27219256b62ef657f08b73b Mon Sep 17 00:00:00 2001 From: huaqingsimeng <1004904143@qq.com> Date: Thu, 6 Apr 2023 01:31:33 +0000 Subject: [PATCH] =?UTF-8?q?=E5=A4=87=E4=BB=BD=E6=81=A2=E5=A4=8D=E6=8C=89?= =?UTF-8?q?=E9=9C=80=E5=81=9C=E6=AD=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huaqingsimeng --- .../include/module_ipc/svc_session_manager.h | 8 ++++++ .../include/module_sched/sched_scheduler.h | 7 +++++ .../src/module_ipc/svc_session_manager.cpp | 11 +++++++- .../src/module_sched/sched_scheduler.cpp | 26 +++++++++++++++++++ 4 files changed, 51 insertions(+), 1 deletion(-) 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 82308a60c..1c0dc1d6c 100644 --- a/services/backup_sa/include/module_ipc/svc_session_manager.h +++ b/services/backup_sa/include/module_ipc/svc_session_manager.h @@ -272,6 +272,14 @@ public: */ bool GetNeedToInstall(const std::string &bundleName); + /** + * @brief Whether to unload the service + * + * @return true + * @return false + */ + bool NeedToUnloadService(); + private: /** * @brief 获取backup extension ability diff --git a/services/backup_sa/include/module_sched/sched_scheduler.h b/services/backup_sa/include/module_sched/sched_scheduler.h index 63dfd299d..cf9a086d1 100644 --- a/services/backup_sa/include/module_sched/sched_scheduler.h +++ b/services/backup_sa/include/module_sched/sched_scheduler.h @@ -65,6 +65,7 @@ public: void StartTimer() { extTime_.Setup(); + UnloadServiceTimer(); } public: @@ -90,6 +91,12 @@ private: */ void InstallingState(const std::string &bundleName); + /** + * @brief unload service timer + * + */ + void UnloadServiceTimer(); + private: mutable std::shared_mutex lock_; OHOS::ThreadPool threadPool_; 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 93bed6437..f40291e69 100644 --- a/services/backup_sa/src/module_ipc/svc_session_manager.cpp +++ b/services/backup_sa/src/module_ipc/svc_session_manager.cpp @@ -376,7 +376,7 @@ void SvcSessionManager::AppendBundles(const vector &bundleNames) if (!impl_.clientToken) { throw BError(BError::Codes::SA_INVAL_ARG, "No caller token was specified"); } - + for (auto &&bundleName : bundleNames) { BackupExtInfo info {}; info.backUpConnection = GetBackupExtAbility(bundleName); @@ -478,4 +478,13 @@ bool SvcSessionManager::GetNeedToInstall(const std::string &bundleName) auto it = GetBackupExtNameMap(bundleName); return it->second.bNeedToInstall; } + +bool SvcSessionManager::NeedToUnloadService() +{ + unique_lock lock(lock_); + if (!impl_.clientToken || !impl_.clientToken || !impl_.clientProxy || !impl_.backupExtNameMap.size()) { + return true; + } + return false; +} } // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/services/backup_sa/src/module_sched/sched_scheduler.cpp b/services/backup_sa/src/module_sched/sched_scheduler.cpp index e54e26a23..557539e4d 100644 --- a/services/backup_sa/src/module_sched/sched_scheduler.cpp +++ b/services/backup_sa/src/module_sched/sched_scheduler.cpp @@ -27,10 +27,12 @@ #include "b_error/b_error.h" #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" namespace OHOS::FileManagement::Backup { using namespace std; @@ -147,6 +149,30 @@ void SchedScheduler::InstallingState(const string &bundleName) } } +void SchedScheduler::UnloadServiceTimer() +{ + auto tryUnload = [sessionPtr {sessionPtr_}]() { + auto ptr = sessionPtr.promote(); + if (ptr && !ptr->NeedToUnloadService()) { + return; + } + HILOGI("Unload system ability"); + sptr saManager = + OHOS::SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (saManager == nullptr) { + HILOGE("UnloadSA, GetSystemAbilityManager is null."); + return; + } + int32_t result = saManager->UnloadSystemAbility(FILEMANAGEMENT_BACKUP_SERVICE_SA_ID); + if (result != ERR_OK) { + HILOGE("UnloadSA, UnloadSystemAbility result: %{public}d", result); + return; + } + }; + int checkingIntervalInMs = 30000; + extTime_.Register(tryUnload, checkingIntervalInMs); +} + void SchedScheduler::InstallSuccess(const std::string &bundleName, const int32_t resultCode) { if (!resultCode) { -- Gitee