From 14ff71cfac0eaa019051701067b5e09a4a57c4ba Mon Sep 17 00:00:00 2001 From: zhangalong Date: Thu, 7 Apr 2022 16:47:37 +0800 Subject: [PATCH] fix device manager depends on os account Signed-off-by:zhang_along Signed-off-by: zhangalong --- devicemanager.gni | 7 ++++++ services/devicemanagerservice/BUILD.gn | 17 +++++++++++--- .../multipleuser/multiple_user_connector.cpp | 9 ++++++++ test/unittest/BUILD.gn | 23 +++++++++++++++---- 4 files changed, 48 insertions(+), 8 deletions(-) diff --git a/devicemanager.gni b/devicemanager.gni index 517e229e1..f8c80c98e 100644 --- a/devicemanager.gni +++ b/devicemanager.gni @@ -28,4 +28,11 @@ ext_path = "${devicemanager_path}/ext" dm_ldflags = [ "-lpthread" ] declare_args() { device_manager_base_no_interaction_auth = false + + if (!defined(global_parts_info) || + defined(global_parts_info.account_os_account_standard)) { + has_os_account_part = true + } else { + has_os_account_part = false + } } diff --git a/services/devicemanagerservice/BUILD.gn b/services/devicemanagerservice/BUILD.gn index 5580b8ac2..8b5e366fd 100755 --- a/services/devicemanagerservice/BUILD.gn +++ b/services/devicemanagerservice/BUILD.gn @@ -46,7 +46,6 @@ if (defined(ohos_lite)) { "${common_path}/include/ipc/model", "//base/security/deviceauth/interfaces/innerkits", "//third_party/json/include", - "//base/account/os_account/interfaces/innerkits/osaccount/native/include", "${utils_path}/include", "${utils_path}/include/permission/lite", "foundation/multimedia/image_standard/mock/native/include", @@ -107,6 +106,11 @@ if (defined(ohos_lite)) { "LOG_DOMAIN=0xD004100", ] + if (has_os_account_part) { + defines += [ "HAS_OS_ACCOUNT_PART" ] + include_dirs += [ "//base/account/os_account/interfaces/innerkits/osaccount/native/include" ] + } + ldflags = dm_ldflags deps = [ @@ -250,8 +254,11 @@ if (defined(ohos_lite)) { "${utils_path}/include/permission/standard", "//base/security/deviceauth/interfaces/innerkits", "//third_party/json/include", - "//base/account/os_account/interfaces/innerkits/osaccount/native/include", ] + + if (has_os_account_part) { + include_dirs += [ "//base/account/os_account/interfaces/innerkits/osaccount/native/include" ] + } } ohos_shared_library("devicemanagerservice") { @@ -292,13 +299,17 @@ if (defined(ohos_lite)) { deps = [ "${innerkits_path}/native_cpp:devicemanagersdk", "${utils_path}:devicemanagerutils", - "//base/account/os_account/frameworks/osaccount/native:os_account_innerkits", "//base/security/deviceauth/services:deviceauth_sdk", "//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager", "//foundation/aafwk/standard/interfaces/innerkits/want:want", "//foundation/aafwk/standard/services/abilitymgr:abilityms", ] + if (has_os_account_part) { + defines += [ "HAS_OS_ACCOUNT_PART" ] + deps += [ "//base/account/os_account/frameworks/osaccount/native:os_account_innerkits" ] + } + if (!device_manager_base_no_interaction_auth) { deps += [ "${common_path}/include/show_confirm_dialog/dialog_ui/js:dialog_js_files_etc", diff --git a/services/devicemanagerservice/src/dependency/multipleuser/multiple_user_connector.cpp b/services/devicemanagerservice/src/dependency/multipleuser/multiple_user_connector.cpp index 2e143ab21..b94a30de5 100644 --- a/services/devicemanagerservice/src/dependency/multipleuser/multiple_user_connector.cpp +++ b/services/devicemanagerservice/src/dependency/multipleuser/multiple_user_connector.cpp @@ -17,25 +17,34 @@ #include "dm_log.h" #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) +#ifdef HAS_OS_ACCOUNT_PART #include "os_account_manager.h" using namespace OHOS::AccountSA; +#endif // HAS_OS_ACCOUNT_PART #endif namespace OHOS { namespace DistributedHardware { int32_t MultipleUserConnector::oldUserId_ = -1; +#ifndef HAS_OS_ACCOUNT_PART +const int32_t DEFAULT_OS_ACCOUNT_ID = 100; // 100 is the default id when there is no os_account part +#endif // HAS_OS_ACCOUNT_PART int32_t MultipleUserConnector::GetCurrentAccountUserID(void) { #if (defined(__LITEOS_M__) || defined(LITE_DEVICE)) return 0; #else +#ifdef HAS_OS_ACCOUNT_PART std::vector ids; ErrCode ret = OsAccountManager::QueryActiveOsAccountIds(ids); if (ret != ERR_OK || ids.empty()) { return -1; } return ids[0]; +#else // HAS_OS_ACCOUNT_PART + return DEFAULT_OS_ACCOUNT_ID; +#endif // HAS_OS_ACCOUNT_PART #endif } diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index be0ea606f..595f80516 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -563,12 +563,17 @@ config("device_manager_test_common_public") { "//foundation/communication/dsoftbus/interfaces/kits/discovery", "//foundation/communication/dsoftbus/interfaces/inner_kits/transport", "//base/security/deviceauth/interfaces/innerkits", - "//base/account/os_account/interfaces/innerkits/osaccount/native/include", - "//base/account/os_account/frameworks/common/database/include", - "//base/account/os_account/frameworks/common/account_error/include", "//foundation/distributedschedule/safwk/services/safwk", ] + if (has_os_account_part) { + include_dirs += [ + "//base/account/os_account/interfaces/innerkits/osaccount/native/include", + "//base/account/os_account/frameworks/common/database/include", + "//base/account/os_account/frameworks/common/account_error/include", + ] + } + cflags = [ "-Wall", "-Werror", @@ -582,11 +587,15 @@ config("device_manager_test_common_public") { "DH_LOG_TAG=\"device_manager_UTtest\"", "LOG_DOMAIN=0xD004190", ] + + if (has_os_account_part) { + defines += [ "HAS_OS_ACCOUNT_PART" ] + } } ohos_static_library("device_manager_test") { testonly = true - + cflags_cc = [] visibility = [ ":*" ] public_configs = [ ":device_manager_test_common_public" ] @@ -605,13 +614,17 @@ ohos_static_library("device_manager_test") { deps = [ "${innerkits_path}/native_cpp:devicemanagersdk", "${utils_path}:devicemanagerutils", - "//base/account/os_account/frameworks/osaccount/native:os_account_innerkits", "//base/security/deviceauth/services:deviceauth_sdk", "//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager", "//foundation/aafwk/standard/interfaces/innerkits/want:want", "//foundation/aafwk/standard/services/abilitymgr:abilityms", ] + if (has_os_account_part) { + cflags_cc += [ "-DHAS_OS_ACCOUNT_PART" ] + deps += [ "//base/account/os_account/frameworks/osaccount/native:os_account_innerkits" ] + } + external_deps = [ "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", -- Gitee