diff --git a/services/distributedfiledaemon/include/ipc/daemon.h b/services/distributedfiledaemon/include/ipc/daemon.h index a1a3ecc87bd46d6782c8a00c964e9e98635ff188..1ed72b23cb1854ab4a861b6b6cc74ac6b1207524 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 f50c2d5701b7af4157adef38d079cbf2e3eeddf9..53c7ce5a24f2434ab42baf54f292f375a0fc8731 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"); }