diff --git a/services/distributedfiledaemon/BUILD.gn b/services/distributedfiledaemon/BUILD.gn old mode 100755 new mode 100644 index bf933bc7585dcbbaa831a856ef98dfe769d8b6b4..cf2b26c6178f9d7301ca2b376628ab024282864c --- a/services/distributedfiledaemon/BUILD.gn +++ b/services/distributedfiledaemon/BUILD.gn @@ -44,6 +44,8 @@ ohos_shared_library("libdistributedfiledaemon") { "//foundation/distributedhardware/devicemanager/interfaces/inner_kits/native_cpp:devicemanagersdk", ] external_deps = [ + "ability_base:want", + "common_event_service:cesfwk_innerkits", "dataclassification:data_transit_mgr", "dsoftbus_standard:softbus_client", "ipc:ipc_core", diff --git a/services/distributedfiledaemon/include/multiuser/os_account_observer.h b/services/distributedfiledaemon/include/multiuser/os_account_observer.h index a7cc9e024fd60895517aab313934560e1d0cc0a6..719a5267cb98867035f24b5ab9535241149be7d3 100644 --- a/services/distributedfiledaemon/include/multiuser/os_account_observer.h +++ b/services/distributedfiledaemon/include/multiuser/os_account_observer.h @@ -20,20 +20,24 @@ #include #include +#include "common_event_manager.h" +#include "common_event_subscribe_info.h" +#include "common_event_subscriber.h" +#include "common_event_support.h" +#include "matching_skills.h" #include "mountpoint/mount_point.h" -#include "os_account_manager.h" namespace OHOS { namespace Storage { namespace DistributedFile { static constexpr int MOUNT_POINT_NUM = 2; -class OsAccountObserver final : public AccountSA::OsAccountSubscriber { +class OsAccountObserver final : public EventFwk::CommonEventSubscriber { public: OsAccountObserver() = default; ~OsAccountObserver(); - explicit OsAccountObserver(const AccountSA::OsAccountSubscribeInfo &subscribeInfo); + explicit OsAccountObserver(const EventFwk::CommonEventSubscribeInfo &subscribeInfo); - void OnAccountsChanged(const int &id) override; + virtual void OnReceiveEvent(const EventFwk::CommonEventData &eventData) override; private: void RemoveMPInfo(const int id); void AddMPInfo(const int id, const std::string &relativePath); diff --git a/services/distributedfiledaemon/src/ipc/daemon.cpp b/services/distributedfiledaemon/src/ipc/daemon.cpp index 8f9da6a61a85c810a2a58f1fecae8992bdb2b7c3..206b729944adb687b12aae4aa475ff08fd5ad8fe 100644 --- a/services/distributedfiledaemon/src/ipc/daemon.cpp +++ b/services/distributedfiledaemon/src/ipc/daemon.cpp @@ -15,8 +15,9 @@ #include "ipc/daemon.h" +#include "common_event_manager.h" +#include "common_event_support.h" #include "mountpoint/mount_manager.h" -#include "os_account_manager.h" #include "system_ability_definition.h" #include "utils_log.h" @@ -42,17 +43,15 @@ void Daemon::PublishSA() void Daemon::RegisterOsAccount() { - OHOS::AccountSA::OsAccountSubscribeInfo osAccountSubscribeInfo; - osAccountSubscribeInfo.SetOsAccountSubscribeType(OHOS::AccountSA::OS_ACCOUNT_SUBSCRIBE_TYPE::ACTIVED); - osAccountSubscribeInfo.SetName("distributed_file_service"); - - 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); + LOGI("register os account enter"); + EventFwk::MatchingSkills matchingSkills; + matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_USER_ADDED); + matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_USER_REMOVED); + matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_USER_SWITCHED); + EventFwk::CommonEventSubscribeInfo subscribeInfo(matchingSkills); + subScriber_ = std::make_shared(subscribeInfo); + bool subRet = EventFwk::CommonEventManager::SubscribeCommonEvent(subScriber_); + LOGI("register os account success %{public}d", subRet); } void Daemon::OnStart() @@ -79,10 +78,8 @@ 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); - } + bool subRet = EventFwk::CommonEventManager::UnSubscribeCommonEvent(subScriber_); + LOGI("unregister os account success %{public}d", subRet); subScriber_ = nullptr; LOGI("Stop finished successfully"); } diff --git a/services/distributedfiledaemon/src/multiuser/os_account_observer.cpp b/services/distributedfiledaemon/src/multiuser/os_account_observer.cpp index accf450405916ba5ee8052b5e37555a3db837cdf..592f432d3e5072077447f1aa180357b963b9804b 100644 --- a/services/distributedfiledaemon/src/multiuser/os_account_observer.cpp +++ b/services/distributedfiledaemon/src/multiuser/os_account_observer.cpp @@ -15,6 +15,8 @@ #include "multiuser/os_account_observer.h" +#include "common_event_manager.h" +#include "common_event_support.h" #include "device/device_manager_agent.h" #include "dfsu_mount_argument_descriptors.h" #include "utils_log.h" @@ -29,8 +31,8 @@ static const std::string ACCOUNT_LESS = "non_account"; static constexpr int DEFAULT_ACCOUNT = 100; } // namespace -OsAccountObserver::OsAccountObserver(const AccountSA::OsAccountSubscribeInfo &subscribeInfo) - : OsAccountSubscriber(subscribeInfo) +OsAccountObserver::OsAccountObserver(const EventFwk::CommonEventSubscribeInfo &subscribeInfo) + : EventFwk::CommonEventSubscriber(subscribeInfo) { LOGI("init first to create network of default user"); lock_guard lock(serializer_); @@ -52,20 +54,27 @@ void OsAccountObserver::AddMPInfo(const int id, const std::string &relativePath) mountPoints_[id].emplace_back(smp); } -void OsAccountObserver::OnAccountsChanged(const int &id) +void OsAccountObserver::OnReceiveEvent(const EventFwk::CommonEventData &eventData) { - LOGI("user id changed to %{public}d", id); - lock_guard lock(serializer_); - if (curUsrId != -1) { - // first stop curUsrId network - RemoveMPInfo(curUsrId); - } + const AAFwk::Want& want = eventData.GetWant(); + std::string action = want.GetAction(); + LOGI("AccountSubscriber: OnReceiveEvent action:%{public}s.", action.c_str()); + if (action == EventFwk::CommonEventSupport::COMMON_EVENT_USER_SWITCHED) { + int32_t id = eventData.GetCode(); + LOGI("user id changed to %{public}d", id); + lock_guard lock(serializer_); + if (curUsrId != -1) { + // first stop curUsrId network + RemoveMPInfo(curUsrId); + } - // then start new network - curUsrId = id; - AddMPInfo(id, SAME_ACCOUNT); - AddMPInfo(id, ACCOUNT_LESS); - LOGI("user id %{public}d, add network done", curUsrId); + // then start new network + curUsrId = id; + AddMPInfo(id, SAME_ACCOUNT); + AddMPInfo(id, ACCOUNT_LESS); + LOGI("user id %{public}d, add network done", curUsrId); + } + LOGI("user changed OnReceiveEvent"); } void OsAccountObserver::RemoveMPInfo(const int id)