diff --git a/distributeddatamgr.gni b/distributeddatamgr.gni index 839074222e56c6629960698e2d4725a34482ce20..9e9e0446314a17488d882409d7b85217ad16ca39 100644 --- a/distributeddatamgr.gni +++ b/distributeddatamgr.gni @@ -9,7 +9,7 @@ # 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. +# limitations under the License. declare_args() { distributeddatamgr_power = true @@ -17,4 +17,11 @@ declare_args() { !defined(global_parts_info.battery_manager_native_batterysrv_client)) { distributeddatamgr_power = false } + + if (!defined(global_parts_info) || + defined(global_parts_info.account_os_account_standard)) { + os_account_part_is_enabled = true + } else { + os_account_part_is_enabled = false + } } diff --git a/services/distributeddataservice/adapter/account/BUILD.gn b/services/distributeddataservice/adapter/account/BUILD.gn index a42f278132ab2bcd562958159e0c8331fe9ea002..0d290cb050ebac3c12f820a9213094576ada2b1a 100755 --- a/services/distributeddataservice/adapter/account/BUILD.gn +++ b/services/distributeddataservice/adapter/account/BUILD.gn @@ -11,6 +11,8 @@ # See the License for the specific language governing permissions and # limitations under the License. import("//build/ohos.gni") +import( + "//foundation/distributeddatamgr/distributeddatamgr/distributeddatamgr.gni") ohos_static_library("distributeddata_account_static") { sources = [ @@ -49,9 +51,14 @@ ohos_static_library("distributeddata_account_static") { "ces_standard:cesfwk_innerkits", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", - "os_account_standard:libaccountkits", - "os_account_standard:os_account_innerkits", ] + if (os_account_part_is_enabled) { + cflags_cc += [ "-DOS_ACCOUNT_PART_IS_ENABLED" ] + external_deps += [ + "os_account_standard:libaccountkits", + "os_account_standard:os_account_innerkits", + ] + } subsystem_name = "distributeddatamgr" part_name = "distributeddatamgr" } diff --git a/services/distributeddataservice/adapter/account/src/account_delegate_impl.cpp b/services/distributeddataservice/adapter/account/src/account_delegate_impl.cpp index 60a0c6c11a91688b7eb776be84ffef856182f98b..af7c857500c5bd4d7a92c68c8d2abc4545a95001 100644 --- a/services/distributeddataservice/adapter/account/src/account_delegate_impl.cpp +++ b/services/distributeddataservice/adapter/account/src/account_delegate_impl.cpp @@ -23,8 +23,10 @@ #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" @@ -34,6 +36,12 @@ 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) @@ -128,6 +136,7 @@ void AccountDelegateImpl::SubscribeAccountEvent() 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"); @@ -139,16 +148,22 @@ std::string AccountDelegateImpl::GetCurrentAccountId(const std::string &bundleNa } 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); } diff --git a/services/distributeddataservice/app/BUILD.gn b/services/distributeddataservice/app/BUILD.gn index e7e17bdef4946135dfae087090e238425683551d..cffa8a91d3c2e727b76065505a6567c7c2c148a8 100644 --- a/services/distributeddataservice/app/BUILD.gn +++ b/services/distributeddataservice/app/BUILD.gn @@ -74,6 +74,7 @@ config("module_private_config") { } ohos_shared_library("distributeddataservice") { + cflags_cc = [] sources = [ "src/backup_handler.cpp", "src/device_change_listener_impl.cpp", @@ -142,12 +143,16 @@ ohos_shared_library("distributeddataservice") { "hiviewdfx_hilog_native:libhilog", "huks:libhukssdk", "ipc:ipc_core", - "os_account_standard:os_account_innerkits", "safwk:system_ability_fwk", "samgr_standard:samgr_proxy", "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 f9ace5b335421d79750e10cf5129efc370e63aac..4a62a9f769dc9b9fc1296a1787c62332541e39cf 100644 --- a/services/distributeddataservice/app/test/BUILD.gn +++ b/services/distributeddataservice/app/test/BUILD.gn @@ -55,6 +55,7 @@ config("module_private_config") { } ohos_unittest("KvStoreImplLogicalIsolationTest") { + cflags_cc = [] module_out_path = module_output_path sources = [ "../src/backup_handler.cpp", @@ -91,11 +92,15 @@ ohos_unittest("KvStoreImplLogicalIsolationTest") { "hiviewdfx_hilog_native:libhilog", "huks:libhukssdk", "ipc:ipc_core", - "os_account_standard:os_account_innerkits", "safwk:system_ability_fwk", "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", @@ -130,7 +135,7 @@ 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", @@ -172,11 +177,15 @@ ohos_unittest("KvStoreImplPhysicalIsolationTest") { "hiviewdfx_hilog_native:libhilog", "huks:libhukssdk", "ipc:ipc_core", - "os_account_standard:os_account_innerkits", "safwk:system_ability_fwk", "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", @@ -205,7 +214,7 @@ 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", @@ -246,11 +255,15 @@ ohos_unittest("KvStoreDataServiceTest") { "hiviewdfx_hilog_native:libhilog", "huks:libhukssdk", "ipc:ipc_core", - "os_account_standard:os_account_innerkits", "safwk:system_ability_fwk", "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", @@ -321,11 +334,15 @@ ohos_unittest("KvStoreBackupTest") { "hiviewdfx_hilog_native:libhilog", "huks:libhukssdk", "ipc:ipc_core", - "os_account_standard:os_account_innerkits", "safwk:system_ability_fwk", "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", @@ -356,7 +373,7 @@ 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" ] @@ -366,11 +383,15 @@ ohos_unittest("KvStoreFlowCtrlManagerTest") { "hiviewdfx_hilog_native:libhilog", "huks:libhukssdk", "ipc:ipc_core", - "os_account_standard:os_account_innerkits", "safwk:system_ability_fwk", "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", @@ -392,7 +413,7 @@ 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", @@ -432,11 +453,15 @@ ohos_unittest("KvStoreSyncManagerTest") { "hiviewdfx_hilog_native:libhilog", "huks:libhukssdk", "ipc:ipc_core", - "os_account_standard:os_account_innerkits", "safwk:system_ability_fwk", "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", @@ -465,7 +490,7 @@ 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", @@ -525,11 +550,15 @@ ohos_unittest("KvStoreUninstallerTest") { "hiviewdfx_hilog_native:libhilog", "huks:libhukssdk", "ipc:ipc_core", - "os_account_standard:os_account_innerkits", "safwk:system_ability_fwk", "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 7e473e9176ab38052ea58c27aee779888054da46..e88219e03887ae9ff62090d909ee48ed42c5c254 100644 --- a/services/distributeddataservice/service/kvdb/user_delegate.cpp +++ b/services/distributeddataservice/service/kvdb/user_delegate.cpp @@ -23,12 +23,20 @@ #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(); @@ -91,11 +99,17 @@ 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()) { 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) { userStatus.emplace_back(user, true);