From d134fb2e7c18908f54482f046ce5447b5ec328bc Mon Sep 17 00:00:00 2001 From: xianghengliang Date: Mon, 7 Mar 2022 10:32:33 +0800 Subject: [PATCH] osaccountObserver destructing when subcribeosaccount failed bugfix Signed-off-by: xianghengliang Change-Id: I16fbb8eebd80a38a439801415b87014773da1379 --- services/distributedfiledaemon/include/ipc/daemon.h | 3 ++- services/distributedfiledaemon/src/ipc/daemon.cpp | 11 ++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/services/distributedfiledaemon/include/ipc/daemon.h b/services/distributedfiledaemon/include/ipc/daemon.h index a1a3ecc87..1ed72b23c 100644 --- a/services/distributedfiledaemon/include/ipc/daemon.h +++ b/services/distributedfiledaemon/include/ipc/daemon.h @@ -21,6 +21,7 @@ #include "daemon_stub.h" #include "i_daemon.h" #include "iremote_stub.h" +#include "multiuser/os_account_observer.h" #include "system_ability.h" namespace OHOS { @@ -50,7 +51,7 @@ private: static sptr instance_; static std::mutex instanceLock_; bool registerToService_ { false }; - + std::shared_ptr subScriber_; void PublishSA(); void RegisterOsAccount(); }; diff --git a/services/distributedfiledaemon/src/ipc/daemon.cpp b/services/distributedfiledaemon/src/ipc/daemon.cpp index f50c2d570..53c7ce5a2 100644 --- a/services/distributedfiledaemon/src/ipc/daemon.cpp +++ b/services/distributedfiledaemon/src/ipc/daemon.cpp @@ -16,7 +16,6 @@ #include "ipc/daemon.h" #include "mountpoint/mount_manager.h" -#include "multiuser/os_account_observer.h" #include "os_account_manager.h" #include "system_ability_definition.h" #include "utils_log.h" @@ -47,10 +46,11 @@ void Daemon::RegisterOsAccount() osAccountSubscribeInfo.SetOsAccountSubscribeType(OHOS::AccountSA::OS_ACCOUNT_SUBSCRIBE_TYPE::ACTIVED); osAccountSubscribeInfo.SetName("distributed_file_service"); - auto subScriber = std::make_shared(osAccountSubscribeInfo); - int ret = OHOS::AccountSA::OsAccountManager::SubscribeOsAccount(subScriber); + subScriber_ = std::make_shared(osAccountSubscribeInfo); + int ret = OHOS::AccountSA::OsAccountManager::SubscribeOsAccount(subScriber_); if (ret != 0) { LOGE("register os account fail ret %{public}d", ret); + return; } LOGI("register os account success, ret %{public}d", ret); } @@ -79,6 +79,11 @@ void Daemon::OnStop() LOGI("Begin to stop"); state_ = ServiceRunningState::STATE_NOT_START; registerToService_ = false; + int32_t ret = OHOS::AccountSA::OsAccountManager::UnsubscribeOsAccount(subScriber_); + if (ret != 0) { + LOGI("UnsubscribeOsAccount failed, ret %{public}d", ret); + } + subScriber_ = nullptr; LOGI("Stop finished successfully"); } -- Gitee