diff --git a/services/distributeddataservice/adapter/account/BUILD.gn b/services/distributeddataservice/adapter/account/BUILD.gn index 0d290cb050ebac3c12f820a9213094576ada2b1a..27672a5bfb6fe5bc81b5de93c4cf565bebfaf4b7 100755 --- a/services/distributeddataservice/adapter/account/BUILD.gn +++ b/services/distributeddataservice/adapter/account/BUILD.gn @@ -44,20 +44,22 @@ ohos_static_library("distributeddata_account_static") { ] external_deps = [ - "bundle_framework:appexecfwk_base", - - # "ces:libcommonevent", "ability_base:want", + "bundle_framework:appexecfwk_base", "ces_standard:cesfwk_innerkits", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", ] + if (os_account_part_is_enabled) { + sources += [ "src/account_delegate_normal_impl.cpp" ] cflags_cc += [ "-DOS_ACCOUNT_PART_IS_ENABLED" ] external_deps += [ "os_account_standard:libaccountkits", "os_account_standard:os_account_innerkits", ] + } else { + sources += [ "src/account_delegate_default_impl.cpp" ] } subsystem_name = "distributeddatamgr" part_name = "distributeddatamgr" diff --git a/services/distributeddataservice/adapter/account/src/account_delegate_default_impl.cpp b/services/distributeddataservice/adapter/account/src/account_delegate_default_impl.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b855d79021431dda9f0f460eb244301ffe5d4c9b --- /dev/null +++ b/services/distributeddataservice/adapter/account/src/account_delegate_default_impl.cpp @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2022 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. + */ +#define LOG_TAG "AccountDelegateDefaultImpl" + +#include "account_delegate_default_impl.h" +#include "log_print.h" + +namespace OHOS { +namespace DistributedKv { +namespace { + const std::string DEFAULT_OHOS_ACCOUNT_UID = ""; // default UID +} + +AccountDelegate::BaseInstance AccountDelegate::getInstance_ = AccountDelegateDefaultImpl::GetBaseInstance; + +AccountDelegateDefaultImpl *AccountDelegateDefaultImpl::GetInstance() +{ + static AccountDelegateDefaultImpl accountDelegate; + return &accountDelegate; +} + +AccountDelegate *AccountDelegateDefaultImpl::GetBaseInstance() +{ + return AccountDelegateDefaultImpl::GetInstance(); +} + +std::string AccountDelegateDefaultImpl::GetCurrentAccountId(const std::string &bundleName) const +{ + ZLOGD("no account part, return default. bundlename:%s", bundleName.c_str()); + return DEFAULT_OHOS_ACCOUNT_UID; +} + +std::string AccountDelegateDefaultImpl::GetDeviceAccountIdByUID(int32_t uid) const +{ + ZLOGD("no account part, return default. uid:%d", uid); + return std::to_string(0); +} + +bool AccountDelegateDefaultImpl::QueryUsers(std::vector &users) +{ + ZLOGD("no account part."); + users.emplace_back(0); // default user + return true; +} + +void AccountDelegateDefaultImpl::SubscribeAccountEvent() +{ + ZLOGD("no account part."); +} + +AccountDelegateDefaultImpl::~AccountDelegateDefaultImpl() +{ + ZLOGD("destruct"); + observerMap_.Clear(); +} +} // namespace DistributedKv +} // namespace OHOS \ No newline at end of file diff --git a/services/distributeddataservice/adapter/account/src/account_delegate_default_impl.h b/services/distributeddataservice/adapter/account/src/account_delegate_default_impl.h new file mode 100644 index 0000000000000000000000000000000000000000..50a708566fef6334e5e8c29b9bb33171cf29bedd --- /dev/null +++ b/services/distributeddataservice/adapter/account/src/account_delegate_default_impl.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2022 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 DISTRIBUTEDDATAMGR_ACCOUNT_DELEGATE_DEFAULT_IMPL_H +#define DISTRIBUTEDDATAMGR_ACCOUNT_DELEGATE_DEFAULT_IMPL_H + +#include "account_delegate_impl.h" + +namespace OHOS { +namespace DistributedKv { +class AccountDelegateDefaultImpl final : public AccountDelegateImpl { +public: + static AccountDelegateDefaultImpl *GetInstance(); + static AccountDelegate *GetBaseInstance(); + std::string GetCurrentAccountId(const std::string &bundleName = "") const override; + std::string GetDeviceAccountIdByUID(int32_t uid) const override; + bool QueryUsers(std::vector &users) override; + void SubscribeAccountEvent() override; + +private: + ~AccountDelegateDefaultImpl(); +}; +} // namespace DistributedKv +} // namespace OHOS +#endif // DISTRIBUTEDDATAMGR_ACCOUNT_DELEGATE_DEFAULT_IMPL_H \ No newline at end of file diff --git a/services/distributeddataservice/adapter/account/src/account_delegate_impl.cpp b/services/distributeddataservice/adapter/account/src/account_delegate_impl.cpp index af7c857500c5bd4d7a92c68c8d2abc4545a95001..afe70d73dab6b43b709c3182cf6a4329eb532794 100644 --- a/services/distributeddataservice/adapter/account/src/account_delegate_impl.cpp +++ b/services/distributeddataservice/adapter/account/src/account_delegate_impl.cpp @@ -17,18 +17,10 @@ #include "account_delegate_impl.h" #include -#include -#include #include #include #include #include "constant.h" -#ifdef OS_ACCOUNT_PART_IS_ENABLED -#include "ohos_account_kits.h" -#include "os_account_manager.h" -#endif // OS_ACCOUNT_PART_IS_ENABLED -#include "permission_validator.h" -#include "utils/crypto.h" namespace OHOS { namespace DistributedKv { @@ -36,12 +28,6 @@ using namespace OHOS::EventFwk; using namespace OHOS::AAFwk; using namespace OHOS::DistributedData; -#ifndef OS_ACCOUNT_PART_IS_ENABLED -namespace { -const std::string DEFAULT_OHOS_ACCOUNT_UID = ""; // default UID -} -#endif // OS_ACCOUNT_PART_IS_ENABLED - EventSubscriber::EventSubscriber(const CommonEventSubscribeInfo &info) : CommonEventSubscriber(info) {} void EventSubscriber::OnReceiveEvent(const CommonEventData &event) @@ -73,100 +59,6 @@ void EventSubscriber::SetEventCallback(EventCallback callback) eventCallback_ = callback; } -AccountDelegate::BaseInstance AccountDelegate::getInstance_ = AccountDelegateImpl::GetBaseInstance; - -AccountDelegateImpl *AccountDelegateImpl::GetInstance() -{ - static AccountDelegateImpl accountDelegate; - return &accountDelegate; -} - -AccountDelegate *AccountDelegateImpl::GetBaseInstance() -{ - return AccountDelegateImpl::GetInstance(); -} - -AccountDelegateImpl::~AccountDelegateImpl() -{ - ZLOGE("destruct"); - observerMap_.Clear(); - const auto result = CommonEventManager::UnSubscribeCommonEvent(eventSubscriber_); - if (!result) { - ZLOGE("Fail to unregister account event listener!"); - } -} - -void AccountDelegateImpl::SubscribeAccountEvent() -{ - ZLOGI("Subscribe account event listener start."); - MatchingSkills matchingSkills; - matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_USER_REMOVED); - matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_USER_SWITCHED); - CommonEventSubscribeInfo info(matchingSkills); - eventSubscriber_ = std::make_shared(info); - eventSubscriber_->SetEventCallback([&](AccountEventInfo &account) { - account.harmonyAccountId = GetCurrentAccountId(); - NotifyAccountChanged(account); - }); - - std::thread th = std::thread([eventSubscriber = eventSubscriber_]() { - int tryTimes = 0; - constexpr int MAX_RETRY_TIME = 300; - constexpr int RETRY_WAIT_TIME_S = 1; - - // we use this method to make sure register success - while (tryTimes < MAX_RETRY_TIME) { - auto result = CommonEventManager::SubscribeCommonEvent(eventSubscriber); - if (result) { - break; - } - - ZLOGE("EventManager: Fail to register subscriber, error:%d", result); - sleep(RETRY_WAIT_TIME_S); - tryTimes++; - } - if (tryTimes == MAX_RETRY_TIME) { - ZLOGE("EventManager: Fail to register subscriber!"); - } - ZLOGI("EventManager: Success to register subscriber."); - }); - th.detach(); -} - -std::string AccountDelegateImpl::GetCurrentAccountId(const std::string &bundleName) const -{ - ZLOGD("start"); -#ifdef OS_ACCOUNT_PART_IS_ENABLED - auto ohosAccountInfo = AccountSA::OhosAccountKits::GetInstance().QueryOhosAccountInfo(); - if (!ohosAccountInfo.first) { - ZLOGE("get ohosAccountInfo from OhosAccountKits is null, return default"); - return AccountSA::DEFAULT_OHOS_ACCOUNT_UID; - } - if (ohosAccountInfo.second.uid_.empty()) { - ZLOGE("get ohosAccountInfo from OhosAccountKits is null, return default"); - return AccountSA::DEFAULT_OHOS_ACCOUNT_UID; - } - - return Sha256UserId(ohosAccountInfo.second.uid_); -#else // OS_ACCOUNT_PART_IS_ENABLED - ZLOGE("There is no account part, return default"); - return DEFAULT_OHOS_ACCOUNT_UID; -#endif // OS_ACCOUNT_PART_IS_ENABLED -} - -std::string AccountDelegateImpl::GetDeviceAccountIdByUID(int32_t uid) const -{ - int userId = 0; -#ifdef OS_ACCOUNT_PART_IS_ENABLED - auto ret = AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(uid, userId); - if (ret != 0) { - ZLOGE("failed get os account local id from uid, ret:%{public}d", ret); - return {}; - } -#endif // OS_ACCOUNT_PART_IS_ENABLED - return std::to_string(userId); -} - void AccountDelegateImpl::NotifyAccountChanged(const AccountEventInfo &accountEventInfo) { observerMap_.ForEach([&accountEventInfo] (const auto& key, const auto& val) { @@ -212,37 +104,5 @@ Status AccountDelegateImpl::Unsubscribe(std::shared_ptr observer) ZLOGD("fail"); return Status::ERROR; } - -std::string AccountDelegateImpl::Sha256UserId(const std::string &plainText) const -{ - std::regex pattern("^[0-9]+$"); - if (!std::regex_match(plainText, pattern)) { - return plainText; - } - - std::string::size_type sizeType; - int64_t plainVal; - std::string::size_type int64MaxLen(std::to_string(INT64_MAX).size()); - // plain text length must be less than INT64_MAX string. - try { - plainVal = static_cast(std::stoll(plainText, &sizeType)); - } catch (const std::out_of_range &) { - plainVal = static_cast(std::stoll( - plainText.substr(plainText.size() - int64MaxLen + 1, int64MaxLen - 1), &sizeType)); - } catch (const std::exception &) { - return plainText; - } - - union UnionLong { - int64_t val; - unsigned char byteLen[sizeof(int64_t)]; - }; - UnionLong unionLong {}; - unionLong.val = plainVal; - std::list unionList(std::begin(unionLong.byteLen), std::end(unionLong.byteLen)); - unionList.reverse(); - std::vector unionVec(unionList.begin(), unionList.end()); - return Crypto::Sha256(unionVec.data(), unionVec.size(), true); -} } // namespace DistributedKv } // namespace OHOS diff --git a/services/distributeddataservice/adapter/account/src/account_delegate_impl.h b/services/distributeddataservice/adapter/account/src/account_delegate_impl.h index fc0748b9c4585e145d986fc65e8a661cb87811c7..cb67143d8c7436c72b774da884c053bbf7a65e8a 100644 --- a/services/distributeddataservice/adapter/account/src/account_delegate_impl.h +++ b/services/distributeddataservice/adapter/account/src/account_delegate_impl.h @@ -40,22 +40,13 @@ private: EventCallback eventCallback_ {}; }; -class AccountDelegateImpl final : public AccountDelegate { +class AccountDelegateImpl : public AccountDelegate { public: - static AccountDelegateImpl *GetInstance(); - static AccountDelegate *GetBaseInstance(); Status Subscribe(std::shared_ptr observer) override; Status Unsubscribe(std::shared_ptr observer) override; - std::string GetCurrentAccountId(const std::string &bundleName = "") const override; - std::string GetDeviceAccountIdByUID(int32_t uid) const override; - void SubscribeAccountEvent() override; -private: - ~AccountDelegateImpl(); - std::string Sha256UserId(const std::string &plainText) const; void NotifyAccountChanged(const AccountEventInfo &accountEventInfo); ConcurrentMap> observerMap_ {}; - std::shared_ptr eventSubscriber_ {}; }; } // namespace DistributedKv } // namespace OHOS diff --git a/services/distributeddataservice/adapter/account/src/account_delegate_normal_impl.cpp b/services/distributeddataservice/adapter/account/src/account_delegate_normal_impl.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e374f63a2c98d24b54a6c43782a2d28f3b7b934f --- /dev/null +++ b/services/distributeddataservice/adapter/account/src/account_delegate_normal_impl.cpp @@ -0,0 +1,157 @@ +/* + * Copyright (c) 2022 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. + */ +#define LOG_TAG "AccountDelegateNormalImpl" + +#include "account_delegate_normal_impl.h" +#include +#include +#include +#include +#include +#include "log_print.h" +#include "ohos_account_kits.h" +#include "os_account_manager.h" +#include "utils/crypto.h" + +namespace OHOS { +namespace DistributedKv { +using namespace OHOS::EventFwk; +using namespace OHOS::AAFwk; +using namespace OHOS::DistributedData; +AccountDelegate::BaseInstance AccountDelegate::getInstance_ = AccountDelegateNormalImpl::GetBaseInstance; + +AccountDelegateNormalImpl *AccountDelegateNormalImpl::GetInstance() +{ + static AccountDelegateNormalImpl accountDelegate; + return &accountDelegate; +} + +AccountDelegate *AccountDelegateNormalImpl::GetBaseInstance() +{ + return AccountDelegateNormalImpl::GetInstance(); +} + +std::string AccountDelegateNormalImpl::GetCurrentAccountId(const std::string &bundleName) const +{ + ZLOGD("start"); + auto ohosAccountInfo = AccountSA::OhosAccountKits::GetInstance().QueryOhosAccountInfo(); + if (!ohosAccountInfo.first) { + ZLOGE("get ohosAccountInfo from OhosAccountKits is null, return default"); + return AccountSA::DEFAULT_OHOS_ACCOUNT_UID; + } + if (ohosAccountInfo.second.uid_.empty()) { + ZLOGE("get ohosAccountInfo from OhosAccountKits is null, return default"); + return AccountSA::DEFAULT_OHOS_ACCOUNT_UID; + } + + return Sha256UserId(ohosAccountInfo.second.uid_); +} + +std::string AccountDelegateNormalImpl::GetDeviceAccountIdByUID(int32_t uid) const +{ + int userId = 0; + auto ret = AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(uid, userId); + if (ret != 0) { + ZLOGE("failed get os account local id from uid, ret:%{public}d", ret); + return {}; + } + return std::to_string(userId); +} + +bool AccountDelegateNormalImpl::QueryUsers(std::vector &users) +{ + users.emplace_back(0); // default user + return AccountSA::OsAccountManager::QueryActiveOsAccountIds(users) == 0; +} + +void AccountDelegateNormalImpl::SubscribeAccountEvent() +{ + ZLOGI("Subscribe account event listener start."); + MatchingSkills matchingSkills; + matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_USER_REMOVED); + matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_USER_SWITCHED); + CommonEventSubscribeInfo info(matchingSkills); + eventSubscriber_ = std::make_shared(info); + eventSubscriber_->SetEventCallback([&](AccountEventInfo &account) { + account.harmonyAccountId = GetCurrentAccountId(); + NotifyAccountChanged(account); + }); + + std::thread th = std::thread([eventSubscriber = eventSubscriber_]() { + int tryTimes = 0; + constexpr int MAX_RETRY_TIME = 300; + constexpr int RETRY_WAIT_TIME_S = 1; + + // we use this method to make sure register success + while (tryTimes < MAX_RETRY_TIME) { + auto result = CommonEventManager::SubscribeCommonEvent(eventSubscriber); + if (result) { + break; + } + + ZLOGE("EventManager: Fail to register subscriber, error:%d", result); + sleep(RETRY_WAIT_TIME_S); + tryTimes++; + } + if (tryTimes == MAX_RETRY_TIME) { + ZLOGE("EventManager: Fail to register subscriber!"); + } + ZLOGI("EventManager: Success to register subscriber."); + }); + th.detach(); +} + +AccountDelegateNormalImpl::~AccountDelegateNormalImpl() +{ + ZLOGD("destruct"); + const auto result = CommonEventManager::UnSubscribeCommonEvent(eventSubscriber_); + if (!result) { + ZLOGE("Fail to unregister account event listener!"); + } + observerMap_.Clear(); +} + +std::string AccountDelegateNormalImpl::Sha256UserId(const std::string &plainText) const +{ + std::regex pattern("^[0-9]+$"); + if (!std::regex_match(plainText, pattern)) { + return plainText; + } + + std::string::size_type sizeType; + int64_t plainVal; + std::string::size_type int64MaxLen(std::to_string(INT64_MAX).size()); + // plain text length must be less than INT64_MAX string. + plainVal = atoll(plainText.c_str()); + if (plainVal == 0) { + return plainText; + } + if (plainVal == INT64_MAX) { + plainVal = atoll(plainText.substr(plainText.size() - int64MaxLen + 1, int64MaxLen - 1).c_str()); + } + + union UnionLong { + int64_t val; + unsigned char byteLen[sizeof(int64_t)]; + }; + UnionLong unionLong {}; + unionLong.val = plainVal; + std::list unionList(std::begin(unionLong.byteLen), std::end(unionLong.byteLen)); + unionList.reverse(); + std::vector unionVec(unionList.begin(), unionList.end()); + return Crypto::Sha256(unionVec.data(), unionVec.size(), true); +} +} // namespace DistributedKv +} // namespace OHOS \ No newline at end of file diff --git a/services/distributeddataservice/adapter/account/src/account_delegate_normal_impl.h b/services/distributeddataservice/adapter/account/src/account_delegate_normal_impl.h new file mode 100644 index 0000000000000000000000000000000000000000..f73966564d20eaccff0177cc716be94dcdb72695 --- /dev/null +++ b/services/distributeddataservice/adapter/account/src/account_delegate_normal_impl.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2022 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 DISTRIBUTEDDATAMGR_ACCOUNT_DELEGATE_NORMAL_IMPL_H +#define DISTRIBUTEDDATAMGR_ACCOUNT_DELEGATE_NORMAL_IMPL_H + +#include "account_delegate_impl.h" +#include "common_event_manager.h" +#include "common_event_subscriber.h" +#include "common_event_support.h" +#include "log_print.h" + +namespace OHOS { +namespace DistributedKv { +class AccountDelegateNormalImpl final : public AccountDelegateImpl { +public: + static AccountDelegateNormalImpl *GetInstance(); + static AccountDelegate *GetBaseInstance(); + std::string GetCurrentAccountId(const std::string &bundleName = "") const override; + std::string GetDeviceAccountIdByUID(int32_t uid) const override; + bool QueryUsers(std::vector &users) override; + void SubscribeAccountEvent() override; + +private: + ~AccountDelegateNormalImpl(); + std::string Sha256UserId(const std::string &plainText) const; + std::shared_ptr eventSubscriber_ {}; +}; +} // namespace DistributedKv +} // namespace OHOS +#endif // DISTRIBUTEDDATAMGR_ACCOUNT_DELEGATE_NORMAL_IMPL_H \ No newline at end of file diff --git a/services/distributeddataservice/adapter/include/account/account_delegate.h b/services/distributeddataservice/adapter/include/account/account_delegate.h index e3e17b339f965bd637304e22b502856674bf4d10..e917a15aed005d42e8849250db21d773e0de1544 100644 --- a/services/distributeddataservice/adapter/include/account/account_delegate.h +++ b/services/distributeddataservice/adapter/include/account/account_delegate.h @@ -41,19 +41,20 @@ class AccountDelegate { public: class Observer { public: - KVSTORE_API virtual ~Observer() = default; - KVSTORE_API virtual void OnAccountChanged(const AccountEventInfo &eventInfo) = 0; + API_EXPORT virtual ~Observer() = default; + API_EXPORT virtual void OnAccountChanged(const AccountEventInfo &eventInfo) = 0; // must specify unique name for observer - KVSTORE_API virtual std::string Name() = 0; + API_EXPORT virtual std::string Name() = 0; }; - KVSTORE_API virtual ~AccountDelegate() = default; - KVSTORE_API virtual Status Subscribe(std::shared_ptr observer) = 0; - KVSTORE_API virtual Status Unsubscribe(std::shared_ptr observer) = 0; - KVSTORE_API virtual std::string GetCurrentAccountId(const std::string &bundleName = "") const = 0; - KVSTORE_API virtual std::string GetDeviceAccountIdByUID(int32_t uid) const = 0; - KVSTORE_API virtual void SubscribeAccountEvent() = 0; - KVSTORE_API static AccountDelegate *GetInstance(); + API_EXPORT virtual ~AccountDelegate() = default; + API_EXPORT virtual Status Subscribe(std::shared_ptr observer) = 0; + API_EXPORT virtual Status Unsubscribe(std::shared_ptr observer) = 0; + API_EXPORT virtual std::string GetCurrentAccountId(const std::string &bundleName = "") const = 0; + API_EXPORT virtual std::string GetDeviceAccountIdByUID(int32_t uid) const = 0; + API_EXPORT virtual void SubscribeAccountEvent() = 0; + API_EXPORT virtual bool QueryUsers(std::vector &users) = 0; + API_EXPORT static AccountDelegate *GetInstance(); private: using BaseInstance = AccountDelegate *(*)(); diff --git a/services/distributeddataservice/app/BUILD.gn b/services/distributeddataservice/app/BUILD.gn index cffa8a91d3c2e727b76065505a6567c7c2c148a8..155e27ba0906993cfc39d22237757d7584fddf37 100644 --- a/services/distributeddataservice/app/BUILD.gn +++ b/services/distributeddataservice/app/BUILD.gn @@ -74,7 +74,6 @@ config("module_private_config") { } ohos_shared_library("distributeddataservice") { - cflags_cc = [] sources = [ "src/backup_handler.cpp", "src/device_change_listener_impl.cpp", @@ -148,11 +147,6 @@ ohos_shared_library("distributeddataservice") { "startup_l2:syspara", ] - if (os_account_part_is_enabled) { - cflags_cc += [ "-DOS_ACCOUNT_PART_IS_ENABLED" ] - external_deps += [ "os_account_standard:os_account_innerkits" ] - } - if (distributeddatamgr_power) { external_deps += [ "battery_manager_native:batterysrv_client", diff --git a/services/distributeddataservice/app/test/BUILD.gn b/services/distributeddataservice/app/test/BUILD.gn index 4a62a9f769dc9b9fc1296a1787c62332541e39cf..373e35701e2cbf980e282b0b681e4a1aff8fefac 100644 --- a/services/distributeddataservice/app/test/BUILD.gn +++ b/services/distributeddataservice/app/test/BUILD.gn @@ -55,7 +55,6 @@ config("module_private_config") { } ohos_unittest("KvStoreImplLogicalIsolationTest") { - cflags_cc = [] module_out_path = module_output_path sources = [ "../src/backup_handler.cpp", @@ -96,11 +95,6 @@ ohos_unittest("KvStoreImplLogicalIsolationTest") { "samgr_standard:samgr_proxy", ] - if (os_account_part_is_enabled) { - cflags_cc += [ "-DOS_ACCOUNT_PART_IS_ENABLED" ] - external_deps += [ "os_account_standard:os_account_innerkits" ] - } - if (distributeddatamgr_power) { external_deps += [ "battery_manager_native:batterysrv_client", @@ -135,7 +129,6 @@ ohos_unittest("KvStoreImplLogicalIsolationTest") { ohos_unittest("KvStoreImplPhysicalIsolationTest") { module_out_path = module_output_path - cflags_cc = [] sources = [ "../src/backup_handler.cpp", "../src/device_change_listener_impl.cpp", @@ -181,11 +174,6 @@ ohos_unittest("KvStoreImplPhysicalIsolationTest") { "samgr_standard:samgr_proxy", ] - if (os_account_part_is_enabled) { - cflags_cc += [ "-DOS_ACCOUNT_PART_IS_ENABLED" ] - external_deps += [ "os_account_standard:os_account_innerkits" ] - } - if (distributeddatamgr_power) { external_deps += [ "battery_manager_native:batterysrv_client", @@ -214,7 +202,6 @@ ohos_unittest("KvStoreImplPhysicalIsolationTest") { ohos_unittest("KvStoreDataServiceTest") { module_out_path = module_output_path - cflags_cc = [] sources = [ "../src/backup_handler.cpp", "../src/device_change_listener_impl.cpp", @@ -259,11 +246,6 @@ ohos_unittest("KvStoreDataServiceTest") { "samgr_standard:samgr_proxy", ] - if (os_account_part_is_enabled) { - cflags_cc += [ "-DOS_ACCOUNT_PART_IS_ENABLED" ] - external_deps += [ "os_account_standard:os_account_innerkits" ] - } - if (distributeddatamgr_power) { external_deps += [ "battery_manager_native:batterysrv_client", @@ -338,11 +320,6 @@ ohos_unittest("KvStoreBackupTest") { "samgr_standard:samgr_proxy", ] - if (os_account_part_is_enabled) { - cflags_cc += [ "-DOS_ACCOUNT_PART_IS_ENABLED" ] - external_deps += [ "os_account_standard:os_account_innerkits" ] - } - if (distributeddatamgr_power) { external_deps += [ "battery_manager_native:batterysrv_client", @@ -373,7 +350,6 @@ ohos_unittest("KvStoreBackupTest") { ohos_unittest("KvStoreFlowCtrlManagerTest") { module_out_path = module_output_path - cflags_cc = [] sources = [ "unittest/kvstore_flowctrl_manager_test.cpp" ] configs = [ ":module_private_config" ] @@ -387,11 +363,6 @@ ohos_unittest("KvStoreFlowCtrlManagerTest") { "samgr_standard:samgr_proxy", ] - if (os_account_part_is_enabled) { - cflags_cc += [ "-DOS_ACCOUNT_PART_IS_ENABLED" ] - external_deps += [ "os_account_standard:os_account_innerkits" ] - } - if (distributeddatamgr_power) { external_deps += [ "battery_manager_native:batterysrv_client", @@ -413,7 +384,6 @@ ohos_unittest("KvStoreFlowCtrlManagerTest") { ohos_unittest("KvStoreSyncManagerTest") { module_out_path = module_output_path - cflags_cc = [] sources = [ "../src/backup_handler.cpp", "../src/device_change_listener_impl.cpp", @@ -457,11 +427,6 @@ ohos_unittest("KvStoreSyncManagerTest") { "samgr_standard:samgr_proxy", ] - if (os_account_part_is_enabled) { - cflags_cc += [ "-DOS_ACCOUNT_PART_IS_ENABLED" ] - external_deps += [ "os_account_standard:os_account_innerkits" ] - } - if (distributeddatamgr_power) { external_deps += [ "battery_manager_native:batterysrv_client", @@ -490,7 +455,6 @@ ohos_unittest("KvStoreSyncManagerTest") { ohos_unittest("KvStoreUninstallerTest") { module_out_path = module_output_path - cflags_cc = [] sources = [ "../src/backup_handler.cpp", "../src/device_change_listener_impl.cpp", @@ -554,11 +518,6 @@ ohos_unittest("KvStoreUninstallerTest") { "samgr_standard:samgr_proxy", ] - if (os_account_part_is_enabled) { - cflags_cc += [ "-DOS_ACCOUNT_PART_IS_ENABLED" ] - external_deps += [ "os_account_standard:os_account_innerkits" ] - } - if (distributeddatamgr_power) { external_deps += [ "battery_manager_native:batterysrv_client", diff --git a/services/distributeddataservice/service/kvdb/user_delegate.cpp b/services/distributeddataservice/service/kvdb/user_delegate.cpp index e88219e03887ae9ff62090d909ee48ed42c5c254..f0cdb6e86ff71ad611d041f0ed68de3b50e36bef 100644 --- a/services/distributeddataservice/service/kvdb/user_delegate.cpp +++ b/services/distributeddataservice/service/kvdb/user_delegate.cpp @@ -23,24 +23,15 @@ #include "executor_factory.h" #include "log_print.h" #include "metadata/meta_data_manager.h" -#ifdef OS_ACCOUNT_PART_IS_ENABLED -#include "os_account_manager.h" -#endif // OS_ACCOUNT_PART_IS_ENABLED #include "utils/anonymous.h" namespace OHOS::DistributedData { using OHOS::AppDistributedKv::CommunicationProvider; using namespace OHOS::DistributedKv; -#ifdef OS_ACCOUNT_PART_IS_ENABLED -using namespace OHOS::AccountSA; -#else // OS_ACCOUNT_PART_IS_ENABLED -namespace { -const int32_t DEFAULT_OS_ACCOUNT_ID = 0; // 0 is the default id when there is no os_account part -} -#endif // OS_ACCOUNT_PART_IS_ENABLED std::string GetLocalDeviceId() { return DeviceKvStoreImpl::GetLocalDeviceId(); } + std::vector UserDelegate::GetLocalUserStatus() { ZLOGI("begin"); @@ -98,20 +89,14 @@ void UserDelegate::UpdateUsers(const std::string &deviceId, const std::vector osAccountIds = { { 0, true } }; // system user default -#ifdef OS_ACCOUNT_PART_IS_ENABLED - auto ret = OsAccountManager::QueryActiveOsAccountIds(osAccountIds); - if (ret != 0 || osAccountIds.empty()) { + std::vector users; + auto ret = AccountDelegate::GetInstance()->QueryUser(users); + if (!ret || osAccountIds.empty()) { ZLOGE("failed to query os accounts, ret:%{public}d", ret); return false; } -#else // OS_ACCOUNT_PART_IS_ENABLED - osAccountIds.clear(); - osAccountIds.push_back(DEFAULT_OS_ACCOUNT_ID); - ZLOGI("there has no os account part, use default id!"); -#endif // OS_ACCOUNT_PART_IS_ENABLED std::vector userStatus = { { 0, true } }; - for (const auto &user : osAccountIds) { + for (const auto &user : users) { userStatus.emplace_back(user, true); } UserMetaData userMetaData;