From 576c5b20086fa53d701d07cec82ea2a7e3aafe59 Mon Sep 17 00:00:00 2001 From: wendel Date: Sat, 13 Sep 2025 19:26:25 +0800 Subject: [PATCH] modify user Signed-off-by: wendel Change-Id: I3a25b10489202f814a7e007431e8175493596a68 --- .../include/os_account_manager_wrapper.h | 14 ++++++ .../src/os_account_manager_wrapper.cpp | 38 ++++++++++++++ .../src/ability_auto_startup_service.cpp | 7 ++- .../src/ability_manager_service.cpp | 6 +-- services/appmgr/BUILD.gn | 1 - .../appmgr/include/app_mgr_service_inner.h | 1 + services/appmgr/src/app_mgr_service_inner.cpp | 50 +++++++++---------- .../src/user_controller/user_controller.cpp | 3 +- .../BUILD.gn | 1 - .../BUILD.gn | 1 - .../BUILD.gn | 1 - .../BUILD.gn | 1 - .../ams/ability_running_record_test/BUILD.gn | 1 - .../common/ams/app_mgr_service_test/BUILD.gn | 1 - .../common/ams/app_recent_list_test/BUILD.gn | 1 - .../common/ams/app_service_flow_test/BUILD.gn | 1 - .../common/ams/ipc_ams_mgr_test/BUILD.gn | 1 - .../common/ams/ipc_app_mgr_test/BUILD.gn | 1 - .../ams/ipc_app_scheduler_test/BUILD.gn | 1 - .../ams/service_start_process_test/BUILD.gn | 1 - .../os_account_manager_wrapper.h | 5 ++ .../BUILD.gn | 1 + .../ams_ability_running_record_test/BUILD.gn | 1 - .../BUILD.gn | 1 - .../ams_service_startup_test/BUILD.gn | 1 - .../BUILD.gn | 1 - .../app_mgr_service_fourth_test/BUILD.gn | 1 - .../BUILD.gn | 1 - .../app_mgr_service_inner_ninth_test/BUILD.gn | 1 - .../BUILD.gn | 1 - .../app_mgr_service_inner_tenth_test/BUILD.gn | 1 - .../app_mgr_service_inner_tenth_test.cpp | 21 ++++++++ .../BUILD.gn | 1 - .../os_account_manager_wrapper_test.cpp | 27 ++++++++++ utils/server/constant/server_constant.h | 1 - 35 files changed, 138 insertions(+), 59 deletions(-) diff --git a/interfaces/inner_api/deps_wrapper/include/os_account_manager_wrapper.h b/interfaces/inner_api/deps_wrapper/include/os_account_manager_wrapper.h index 826ca5b843a..9045547797e 100644 --- a/interfaces/inner_api/deps_wrapper/include/os_account_manager_wrapper.h +++ b/interfaces/inner_api/deps_wrapper/include/os_account_manager_wrapper.h @@ -85,6 +85,20 @@ public: * @return int32_t user ID */ static int32_t GetCurrentActiveAccountId(); + + /** + * @brief Get the userId of logical main screen. + * + * @return int32_t user ID + */ + static int32_t GetDefaultForegroundUserId(); + + /** + * @brief Determine if the userID is a foreground user. + * + * @return bool + */ + static bool IsForegroundUser(int32_t userId); }; } // namespace AppExecFwk } // namespace OHOS diff --git a/interfaces/inner_api/deps_wrapper/src/os_account_manager_wrapper.cpp b/interfaces/inner_api/deps_wrapper/src/os_account_manager_wrapper.cpp index 388620c0931..3330f91133e 100644 --- a/interfaces/inner_api/deps_wrapper/src/os_account_manager_wrapper.cpp +++ b/interfaces/inner_api/deps_wrapper/src/os_account_manager_wrapper.cpp @@ -127,5 +127,43 @@ int32_t OsAccountManagerWrapper::GetCurrentActiveAccountId() TAG_LOGD(AAFwkTag::DEFAULT, "accountId: %{public}d", accountIds[0]); return accountIds[0]; } + +int32_t OsAccountManagerWrapper::GetDefaultForegroundUserId() +{ +#ifndef OS_ACCOUNT_PART_ENABLED + TAG_LOGD(AAFwkTag::DEFAULT, "Without os account subsystem"); + return 0; +#else // OS_ACCOUNT_PART_ENABLED + int32_t localId = 0; + auto errCode = AccountSA::OsAccountManager::GetForegroundOsAccountLocalId(localId); + if (errCode != ERR_OK) { + TAG_LOGE(AAFwkTag::DEFAULT, "Fail to get os account, errCode:%{public}d", errCode); + localId = -1; + } + TAG_LOGD(AAFwkTag::DEFAULT, "local userId:%{public}d", localId); + return localId; +#endif // OS_ACCOUNT_PART_ENABLED +} + +bool OsAccountManagerWrapper::IsForegroundUser(int32_t userId) +{ +#ifndef OS_ACCOUNT_PART_ENABLED + TAG_LOGD(AAFwkTag::DEFAULT, "Without os account subsystem"); + return false; +#else // OS_ACCOUNT_PART_ENABLED + std::vector accounts; + auto errCode = AccountSA::OsAccountManager::GetForegroundOsAccounts(accounts); + if (errCode != ERR_OK) { + TAG_LOGE(AAFwkTag::DEFAULT, "Fail to get os accounts, errCode:%{public}d", errCode); + return false; + } + for (auto &account : accounts) { + if (account.localId == userId) { + return true; + } + } + return false; +#endif // OS_ACCOUNT_PART_ENABLED +} } // namespace AppExecFwk } // namespace OHOS \ No newline at end of file diff --git a/services/abilitymgr/src/ability_auto_startup_service.cpp b/services/abilitymgr/src/ability_auto_startup_service.cpp index 621058ce7fe..0fd90509437 100644 --- a/services/abilitymgr/src/ability_auto_startup_service.cpp +++ b/services/abilitymgr/src/ability_auto_startup_service.cpp @@ -23,9 +23,8 @@ #include "global_constant.h" #include "hilog_tag_wrapper.h" #include "in_process_call_wrapper.h" +#include "os_account_manager_wrapper.h" #include "permission_constants.h" -#include "server_constant.h" -#include "user_controller/user_controller.h" namespace OHOS { namespace AbilityRuntime { @@ -314,7 +313,7 @@ void AbilityAutoStartupService::ExecuteCallbacks(bool isCallOn, const AutoStartu " accessTokenId: %{public}s, setterUserId: %{public}d, userId: %{public}d", info.bundleName.c_str(), info.moduleName.c_str(), info.abilityName.c_str(), info.accessTokenId.c_str(), info.setterUserId, info.userId); - bool isUserIdMatch = UserController::GetInstance().IsForegroundUser(info.userId); + bool isUserIdMatch = AppExecFwk::OsAccountManagerWrapper::IsForegroundUser(info.userId); bool isUserIdU0OrU1 = (U0_USER_ID == info.userId) || (U1_USER_ID == info.userId); if (!isUserIdMatch && !isUserIdU0OrU1) { TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Condition not satisfied"); @@ -430,7 +429,7 @@ int32_t AbilityAutoStartupService::GetValidUserId(int32_t userId) validUserId = IPCSkeleton::GetCallingUid() / AppExecFwk::Constants::BASE_USER_RANGE; } if (validUserId == U0_USER_ID || validUserId == U1_USER_ID) { - validUserId = UserController::GetInstance().GetForegroundUserId(ServerConstant::DEFAULT_DISPLAY_ID); + validUserId = AppExecFwk::OsAccountManagerWrapper::GetDefaultForegroundUserId(); } return validUserId; } diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index 97aa2fbc7cc..d799372d6ca 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -12761,8 +12761,7 @@ void AbilityManagerService::NotifyConfigurationChange(const AppExecFwk::Configur void AbilityManagerService::NotifyStartResidentProcess(std::vector &bundleInfos) { - int32_t callerUser = - AbilityRuntime::UserController::GetInstance().GetForegroundUserId(ServerConstant::DEFAULT_DISPLAY_ID); + int32_t callerUser = AppExecFwk::OsAccountManagerWrapper::GetDefaultForegroundUserId(); std::vector bundleInfosForU0; std::map> bundleInfosMap; for (const auto &item: bundleInfos) { @@ -12804,8 +12803,7 @@ void AbilityManagerService::NotifyStartKeepAliveProcess(std::vector> bundleInfosMap; std::vector bundleInfosForU1; for (const auto &item: bundleInfos) { diff --git a/services/appmgr/BUILD.gn b/services/appmgr/BUILD.gn index 87a2710157b..6c6e4d98978 100644 --- a/services/appmgr/BUILD.gn +++ b/services/appmgr/BUILD.gn @@ -117,7 +117,6 @@ ohos_shared_library("libappms") { "${ability_runtime_services_path}/common:record_cost_time_util", "${ability_runtime_services_path}/common:res_sched_util", "${ability_runtime_services_path}/common:task_handler_wrap", - "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ diff --git a/services/appmgr/include/app_mgr_service_inner.h b/services/appmgr/include/app_mgr_service_inner.h index 10e04fa4872..bcc11939c38 100644 --- a/services/appmgr/include/app_mgr_service_inner.h +++ b/services/appmgr/include/app_mgr_service_inner.h @@ -2141,6 +2141,7 @@ private: void InsertUninstallOrUpgradeUidSet(int32_t uid); void RemoveUninstallOrUpgradeUidSet(int32_t uid); bool IsUninstallingOrUpgrading(int32_t uid); + int32_t GetCallerUserId(int32_t uid); bool isInitAppWaitingDebugListExecuted_ = false; std::atomic sceneBoardAttachFlag_ = true; std::atomic willKillPidsNum_ = 0; diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index 9e3d34208fe..748a61c243c 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -108,7 +108,6 @@ #include "cache_process_manager.h" #include "res_sched_util.h" #include "session_manager_lite.h" -#include "user_controller/user_controller.h" #ifdef APP_NO_RESPONSE_DIALOG #include "fault_data.h" #include "modal_system_app_freeze_uiextension.h" @@ -303,7 +302,6 @@ constexpr int32_t PROCESS_START_FAILED_SUB_REASON_UNKNOWN = 0; constexpr int32_t MAX_SPECIFIED_PROCESS_NAME_LENGTH = 255; constexpr int32_t NWEB_PRELOAD_DELAY = 3000000; -constexpr uint64_t DEFAULT_DISPLAY_ID = 0; constexpr const char* APP_INSTANCE_KEY_0 = "app_instance_0"; @@ -581,10 +579,7 @@ int32_t AppMgrServiceInner::PreloadApplication(const std::string &bundleName, in return ERR_INVALID_VALUE; } if (userId == DEFAULT_INVAL_VALUE) { - userId = GetUserIdByUid(IPCSkeleton::GetCallingUid()); - if (userId == U0_USER_ID || userId == U1_USER_ID) { - userId = UserController::GetInstance().GetForegroundUserId(DEFAULT_DISPLAY_ID); - } + userId = GetCallerUserId(IPCSkeleton::GetCallingUid()); } if (UserRecordManager::GetInstance().IsLogoutUser(userId)) { TAG_LOGE(AAFwkTag::APPMGR, "disable start process in logout user"); @@ -2344,10 +2339,7 @@ int32_t AppMgrServiceInner::ClearUpApplicationData(const std::string &bundleName HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__); int32_t newUserId = userId; if (userId == DEFAULT_INVAL_VALUE) { - newUserId = GetUserIdByUid(callerUid); - if (newUserId == U0_USER_ID || newUserId == U1_USER_ID) { - newUserId = UserController::GetInstance().GetForegroundUserId(DEFAULT_DISPLAY_ID); - } + newUserId = GetCallerUserId(callerUid); } TAG_LOGI(AAFwkTag::APPMGR, "bundleName: %{public}s, uId: %{public}d, appIndex: %{public}d", bundleName.c_str(), newUserId, appCloneIndex); @@ -2368,7 +2360,7 @@ int32_t AppMgrServiceInner::ClearUpApplicationDataBySelf(int32_t callerUid, pid_ if (userId == DEFAULT_INVAL_VALUE) { newUserId = GetUserIdByUid(callerUid); if (newUserId == U0_USER_ID) { - newUserId = UserController::GetInstance().GetForegroundUserId(DEFAULT_DISPLAY_ID); + newUserId = OsAccountManagerWrapper::GetDefaultForegroundUserId(); } } auto appCloneIndex = appRecord->GetAppIndex(); @@ -2472,7 +2464,7 @@ int32_t AppMgrServiceInner::GetRunningProcessesByBundleType(BundleType bundleTyp TAG_LOGE(AAFwkTag::APPMGR, "permission deny"); return ERR_PERMISSION_DENIED; } - int32_t userId = UserController::GetInstance().GetCallerUserId(); + int32_t userId = GetCallerUserId(IPCSkeleton::GetCallingUid()); for (const auto &item : appRunningManager_->GetAppRunningRecordMap()) { const auto &appRecord = item.second; if (!appRecord || !appRecord->GetSpawned()) { @@ -2506,7 +2498,7 @@ int32_t AppMgrServiceInner::GetRunningMultiAppInfoByBundleName(const std::string return ERR_INVALID_VALUE; } ApplicationInfo appInfo; - int32_t userId = UserController::GetInstance().GetCallerUserId(); + int32_t userId = GetCallerUserId(IPCSkeleton::GetCallingUid()); TAG_LOGD(AAFwkTag::APPMGR, "userId: %{public}d, bundleName: %{public}s", userId, bundleName.c_str()); auto queryRet = IN_PROCESS_CALL(bundleMgrHelper->GetApplicationInfo(bundleName, ApplicationFlag::GET_BASIC_APPLICATION_INFO, userId, appInfo)); @@ -2566,7 +2558,7 @@ int32_t AppMgrServiceInner::GetAllRunningInstanceKeysByBundleName(const std::str std::vector &instanceKeys, int32_t userId) { if (userId == -1) { - userId = AbilityRuntime::UserController::GetInstance().GetCallerUserId(); + userId = GetCallerUserId(IPCSkeleton::GetCallingUid()); } if (VerifyAccountPermission(AAFwk::PermissionConstants::PERMISSION_GET_RUNNING_INFO, userId) == ERR_PERMISSION_DENIED) { @@ -6051,8 +6043,7 @@ void AppMgrServiceInner::HandleConfigurationChange(const Configuration& config, for (const auto &item : appStateCallbacks_) { if (item.callback != nullptr && (userId == -1 || item.userId == 0 || item.userId == userId)) { - item.callback->NotifyConfigurationChange(config, - UserController::GetInstance().GetForegroundUserId(DEFAULT_DISPLAY_ID)); + item.callback->NotifyConfigurationChange(config, OsAccountManagerWrapper::GetDefaultForegroundUserId()); } } } @@ -6417,7 +6408,7 @@ int AppMgrServiceInner::VerifyAccountPermission(const std::string &permissionNam { int32_t callerUser = IPCSkeleton::GetCallingUid() / BASE_USER_RANGE; if (((callerUser != U0_USER_ID && callerUser != U1_USER_ID) || - !UserController::GetInstance().IsForegroundUser(userId)) && + !OsAccountManagerWrapper::IsForegroundUser(userId)) && callerUser != userId) { auto isCallingPermAccount = AAFwk::PermissionVerification::GetInstance()->VerifyCallingPermission( AAFwk::PermissionConstants::PERMISSION_INTERACT_ACROSS_LOCAL_ACCOUNTS); @@ -7665,7 +7656,7 @@ int32_t AppMgrServiceInner::IsAppRunning(const std::string &bundleName, int32_t TAG_LOGE(AAFwkTag::APPMGR, "bundleMgrHelper null"); return ERR_INVALID_OPERATION; } - int32_t userId = UserController::GetInstance().GetCallerUserId(); + int32_t userId = GetCallerUserId(IPCSkeleton::GetCallingUid()); BundleInfo bundleInfo; int32_t bundleMgrResult; if (appCloneIndex == 0) { @@ -7703,7 +7694,7 @@ int32_t AppMgrServiceInner::IsAppRunningByBundleNameAndUserId(const std::string } if (userId < 0) { - userId = UserController::GetInstance().GetCallerUserId(); + userId = GetCallerUserId(IPCSkeleton::GetCallingUid()); } return appRunningManager_->IsAppRunningByBundleNameAndUserId(bundleName, userId, isRunning); @@ -7716,7 +7707,7 @@ bool AppMgrServiceInner::CreateAbilityInfo(const AAFwk::Want &want, AbilityInfo TAG_LOGE(AAFwkTag::APPMGR, "get bundle manager helper error"); return false; } - auto userId = UserController::GetInstance().GetCallerUserId(); + auto userId = GetCallerUserId(IPCSkeleton::GetCallingUid()); auto abilityInfoFlag = AbilityRuntime::StartupUtil::BuildAbilityInfoFlag(); if (IN_PROCESS_CALL(bundleMgrHelper->QueryAbilityInfo(want, abilityInfoFlag, userId, abilityInfo))) { TAG_LOGI(AAFwkTag::APPMGR, "queryAbilityInfo ok"); @@ -8152,7 +8143,7 @@ bool AppMgrServiceInner::CheckIsDebugApp(const std::string &bundleName) CHECK_POINTER_AND_RETURN_VALUE(bundleMgrHelper, false); BundleInfo bundleInfo; - auto userId = UserController::GetInstance().GetCallerUserId(); + auto userId = GetCallerUserId(IPCSkeleton::GetCallingUid()); auto ret = IN_PROCESS_CALL(bundleMgrHelper->GetBundleInfoV9(bundleName, static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_APPLICATION), bundleInfo, userId)); if (ret != ERR_OK) { @@ -8404,8 +8395,8 @@ void AppMgrServiceInner::ClearResidentProcessAppRunningData(const std::shared_pt return; } auto userId = GetUserIdByUid(appRecord->GetUid()); - bool isCurentUserId = UserController::GetInstance().IsForegroundUser(userId); - if (appRecord->IsKeepAliveApp() && (userId == 0 || isCurentUserId) && + bool isForegroundtUserId = OsAccountManagerWrapper::IsForegroundUser(userId); + if (appRecord->IsKeepAliveApp() && (userId == 0 || isForegroundtUserId) && appRecord->GetBundleName() != SCENE_BOARD_BUNDLE_NAME) { if (!IsNeedRestartKeepAliveProcess(appRecord->GetBundleName(), appRecord->GetUid())) { return; @@ -8450,10 +8441,10 @@ void AppMgrServiceInner::ClearNonResidentKeepAliveAppRunningData(const std::shar } auto userId = GetUserIdByUid(appRecord->GetUid()); - bool isCurentUserId = UserController::GetInstance().IsForegroundUser(userId); + bool isForegroundtUserId = OsAccountManagerWrapper::IsForegroundUser(userId); bool isDefaultInstance = appRecord->GetInstanceKey().empty() || appRecord->GetInstanceKey() == APP_INSTANCE_KEY_0; if (!appRecord->GetRestartAppFlag() && (appRecord->IsKeepAliveDkv() || appRecord->IsKeepAliveAppService()) && - isDefaultInstance && (userId == 0 || userId == 1 || isCurentUserId) && + isDefaultInstance && (userId == 0 || userId == 1 || isForegroundtUserId) && appRecord->GetBundleName() != SCENE_BOARD_BUNDLE_NAME) { if (ExitResidentProcessManager::GetInstance().IsKilledForUpgradeWeb(appRecord->GetBundleName())) { TAG_LOGI(AAFwkTag::APPMGR, "is killed for upgrade web"); @@ -10705,5 +10696,14 @@ void AppMgrServiceInner::SetSpecifiedProcessRequestId(int32_t recordId, int32_t appRecord->SetSpecifiedProcessRequestId(requestId); return; } + +int32_t AppMgrServiceInner::GetCallerUserId(int32_t uid) +{ + auto userId = GetUserIdByUid(uid); + if (userId == U0_USER_ID || userId == U1_USER_ID) { + userId = OsAccountManagerWrapper::GetDefaultForegroundUserId(); + } + return userId; +} } // namespace AppExecFwk } // namespace OHOS diff --git a/services/common/src/user_controller/user_controller.cpp b/services/common/src/user_controller/user_controller.cpp index acd734740bc..d593064b6df 100644 --- a/services/common/src/user_controller/user_controller.cpp +++ b/services/common/src/user_controller/user_controller.cpp @@ -31,7 +31,6 @@ constexpr int32_t U0_USER_ID = 0; constexpr int32_t U1_USER_ID = 1; constexpr int32_t USER_ID_DEFAULT = 100; constexpr int32_t ACCOUNT_MGR_SERVICE_UID = 3058; -constexpr uint64_t DEFAULT_DISPLAY_ID = 0; } UserController& UserController::GetInstance() { @@ -113,7 +112,7 @@ int32_t UserController::GetCallerUserId() int32_t callerUser = callerUid / BASE_USER_RANGE; TAG_LOGD(AAFwkTag::USER_CONTROLLER, "callerUser = %{public}d, CallingUid = %{public}d.", callerUser, callerUid); if (callerUser == U0_USER_ID || callerUser == U1_USER_ID) { - callerUser = GetForegroundUserId(DEFAULT_DISPLAY_ID); + callerUser = AppExecFwk::OsAccountManagerWrapper::GetDefaultForegroundUserId(); } return callerUser; } diff --git a/test/fuzztest/abilityautostartupdatamanager_fuzzer/BUILD.gn b/test/fuzztest/abilityautostartupdatamanager_fuzzer/BUILD.gn index 303aab7ddfe..0061f2617f2 100644 --- a/test/fuzztest/abilityautostartupdatamanager_fuzzer/BUILD.gn +++ b/test/fuzztest/abilityautostartupdatamanager_fuzzer/BUILD.gn @@ -35,7 +35,6 @@ ohos_fuzztest("AbilityAutoStartupDataManagerFuzzTest") { "-fno-omit-frame-pointer", ] sources = [ - "${ability_runtime_innerkits_path}/deps_wrapper/src/os_account_manager_wrapper.cpp", "${ability_runtime_services_path}/abilitymgr/src/ability_auto_startup_data_manager.cpp", "${ability_runtime_services_path}/common/src/app_utils.cpp", "${ability_runtime_services_path}/common/src/json_utils.cpp", diff --git a/test/fuzztest/abilityautostartupdatamanagerfifth_fuzzer/BUILD.gn b/test/fuzztest/abilityautostartupdatamanagerfifth_fuzzer/BUILD.gn index dbb78f0b91b..369758e6545 100644 --- a/test/fuzztest/abilityautostartupdatamanagerfifth_fuzzer/BUILD.gn +++ b/test/fuzztest/abilityautostartupdatamanagerfifth_fuzzer/BUILD.gn @@ -35,7 +35,6 @@ ohos_fuzztest("AbilityAutoStartupDataManagerFifthFuzzTest") { "-fno-omit-frame-pointer", ] sources = [ - "${ability_runtime_innerkits_path}/deps_wrapper/src/os_account_manager_wrapper.cpp", "${ability_runtime_services_path}/abilitymgr/src/ability_auto_startup_data_manager.cpp", "${ability_runtime_services_path}/common/src/app_utils.cpp", "${ability_runtime_services_path}/common/src/json_utils.cpp", diff --git a/test/fuzztest/abilityautostartupdatamanagerfourth_fuzzer/BUILD.gn b/test/fuzztest/abilityautostartupdatamanagerfourth_fuzzer/BUILD.gn index ee4aeae1213..8bdfad77a39 100644 --- a/test/fuzztest/abilityautostartupdatamanagerfourth_fuzzer/BUILD.gn +++ b/test/fuzztest/abilityautostartupdatamanagerfourth_fuzzer/BUILD.gn @@ -35,7 +35,6 @@ ohos_fuzztest("AbilityAutoStartupDataManagerFourthFuzzTest") { "-fno-omit-frame-pointer", ] sources = [ - "${ability_runtime_innerkits_path}/deps_wrapper/src/os_account_manager_wrapper.cpp", "${ability_runtime_services_path}/abilitymgr/src/ability_auto_startup_data_manager.cpp", "${ability_runtime_services_path}/common/src/app_utils.cpp", "${ability_runtime_services_path}/common/src/json_utils.cpp", diff --git a/test/fuzztest/abilityautostartupdatamanagerthird_fuzzer/BUILD.gn b/test/fuzztest/abilityautostartupdatamanagerthird_fuzzer/BUILD.gn index 1c8e7396bf6..8d9fdbed707 100644 --- a/test/fuzztest/abilityautostartupdatamanagerthird_fuzzer/BUILD.gn +++ b/test/fuzztest/abilityautostartupdatamanagerthird_fuzzer/BUILD.gn @@ -35,7 +35,6 @@ ohos_fuzztest("AbilityAutoStartupDataManagerThirdFuzzTest") { "-fno-omit-frame-pointer", ] sources = [ - "${ability_runtime_innerkits_path}/deps_wrapper/src/os_account_manager_wrapper.cpp", "${ability_runtime_services_path}/abilitymgr/src/ability_auto_startup_data_manager.cpp", "${ability_runtime_services_path}/common/src/app_utils.cpp", "${ability_runtime_services_path}/common/src/json_utils.cpp", diff --git a/test/moduletest/common/ams/ability_running_record_test/BUILD.gn b/test/moduletest/common/ams/ability_running_record_test/BUILD.gn index 41aeac608c4..caa57b284b8 100644 --- a/test/moduletest/common/ams/ability_running_record_test/BUILD.gn +++ b/test/moduletest/common/ams/ability_running_record_test/BUILD.gn @@ -33,7 +33,6 @@ ohos_moduletest("AmsAbilityRunningRecordModuleTest") { "${ability_runtime_services_path}/common:perm_verification", "${ability_runtime_services_path}/common:record_cost_time_util", "${ability_runtime_services_path}/common:res_sched_util", - "${ability_runtime_services_path}/common:user_controller", "${ability_runtime_test_path}/moduletest/common/ams:appmgr_mst_source", ] diff --git a/test/moduletest/common/ams/app_mgr_service_test/BUILD.gn b/test/moduletest/common/ams/app_mgr_service_test/BUILD.gn index 2cf0fe1553f..0f2e6089893 100644 --- a/test/moduletest/common/ams/app_mgr_service_test/BUILD.gn +++ b/test/moduletest/common/ams/app_mgr_service_test/BUILD.gn @@ -43,7 +43,6 @@ ohos_moduletest("AmsAppMgrServiceModuleTest") { "${ability_runtime_services_path}/common:perm_verification", "${ability_runtime_services_path}/common:record_cost_time_util", "${ability_runtime_services_path}/common:res_sched_util", - "${ability_runtime_services_path}/common:user_controller", "${ability_runtime_test_path}/moduletest/common/ams:appmgr_mst_source", ] diff --git a/test/moduletest/common/ams/app_recent_list_test/BUILD.gn b/test/moduletest/common/ams/app_recent_list_test/BUILD.gn index d6b441d8373..d1fbca3d6f0 100644 --- a/test/moduletest/common/ams/app_recent_list_test/BUILD.gn +++ b/test/moduletest/common/ams/app_recent_list_test/BUILD.gn @@ -35,7 +35,6 @@ ohos_moduletest("AmsAppRecentListModuleTest") { "${ability_runtime_services_path}/common:record_cost_time_util", "${ability_runtime_services_path}/common:res_sched_util", "${ability_runtime_services_path}/common:task_handler_wrap", - "${ability_runtime_services_path}/common:user_controller", "${ability_runtime_test_path}/moduletest/common/ams:appmgr_mst_source", ] diff --git a/test/moduletest/common/ams/app_service_flow_test/BUILD.gn b/test/moduletest/common/ams/app_service_flow_test/BUILD.gn index e1e11e547cc..9a41ae9d754 100644 --- a/test/moduletest/common/ams/app_service_flow_test/BUILD.gn +++ b/test/moduletest/common/ams/app_service_flow_test/BUILD.gn @@ -38,7 +38,6 @@ ohos_moduletest("AmsAppServiceFlowModuleTest") { "${ability_runtime_services_path}/common:record_cost_time_util", "${ability_runtime_services_path}/common:res_sched_util", "${ability_runtime_services_path}/common:task_handler_wrap", - "${ability_runtime_services_path}/common:user_controller", "${ability_runtime_test_path}/moduletest/common/ams:appmgr_mst_source", ] diff --git a/test/moduletest/common/ams/ipc_ams_mgr_test/BUILD.gn b/test/moduletest/common/ams/ipc_ams_mgr_test/BUILD.gn index effbcf849d9..b9b5b103f3a 100644 --- a/test/moduletest/common/ams/ipc_ams_mgr_test/BUILD.gn +++ b/test/moduletest/common/ams/ipc_ams_mgr_test/BUILD.gn @@ -44,7 +44,6 @@ ohos_moduletest("AmsIpcAmsmgrModuleTest") { "${ability_runtime_services_path}/common:record_cost_time_util", "${ability_runtime_services_path}/common:res_sched_util", "${ability_runtime_services_path}/common:task_handler_wrap", - "${ability_runtime_services_path}/common:user_controller", "${ability_runtime_test_path}/moduletest/common/ams:appmgr_mst_source", "${ability_runtime_test_path}/unittest:appmgr_test_source", ] diff --git a/test/moduletest/common/ams/ipc_app_mgr_test/BUILD.gn b/test/moduletest/common/ams/ipc_app_mgr_test/BUILD.gn index 3f08a5282f9..e8ec67be57f 100644 --- a/test/moduletest/common/ams/ipc_app_mgr_test/BUILD.gn +++ b/test/moduletest/common/ams/ipc_app_mgr_test/BUILD.gn @@ -35,7 +35,6 @@ ohos_moduletest("AmsIpcAppmgrModuleTest") { "${ability_runtime_services_path}/common:perm_verification", "${ability_runtime_services_path}/common:record_cost_time_util", "${ability_runtime_services_path}/common:res_sched_util", - "${ability_runtime_services_path}/common:user_controller", "${ability_runtime_test_path}/moduletest/common/ams:appmgr_mst_source", ] diff --git a/test/moduletest/common/ams/ipc_app_scheduler_test/BUILD.gn b/test/moduletest/common/ams/ipc_app_scheduler_test/BUILD.gn index 969354cc200..da2aef762d7 100644 --- a/test/moduletest/common/ams/ipc_app_scheduler_test/BUILD.gn +++ b/test/moduletest/common/ams/ipc_app_scheduler_test/BUILD.gn @@ -35,7 +35,6 @@ ohos_moduletest("AmsIpcAppSchedulerModuleTest") { "${ability_runtime_services_path}/common:perm_verification", "${ability_runtime_services_path}/common:record_cost_time_util", "${ability_runtime_services_path}/common:res_sched_util", - "${ability_runtime_services_path}/common:user_controller", "${ability_runtime_test_path}/moduletest/common/ams:appmgr_mst_source", ] diff --git a/test/moduletest/common/ams/service_start_process_test/BUILD.gn b/test/moduletest/common/ams/service_start_process_test/BUILD.gn index 4f4897ba1df..0d31d614156 100644 --- a/test/moduletest/common/ams/service_start_process_test/BUILD.gn +++ b/test/moduletest/common/ams/service_start_process_test/BUILD.gn @@ -35,7 +35,6 @@ ohos_moduletest("AmsServiceStartModuleTest") { "${ability_runtime_services_path}/common:perm_verification", "${ability_runtime_services_path}/common:record_cost_time_util", "${ability_runtime_services_path}/common:res_sched_util", - "${ability_runtime_services_path}/common:user_controller", "${ability_runtime_test_path}/moduletest/common/ams:appmgr_mst_source", ] diff --git a/test/new_test/mock/os_account_manager_wrapper/os_account_manager_wrapper.h b/test/new_test/mock/os_account_manager_wrapper/os_account_manager_wrapper.h index 0831aad853e..6f5e862656f 100644 --- a/test/new_test/mock/os_account_manager_wrapper/os_account_manager_wrapper.h +++ b/test/new_test/mock/os_account_manager_wrapper/os_account_manager_wrapper.h @@ -31,6 +31,11 @@ public: OH_MOCK_METHOD_WITH_OUTPUT_1(ErrCode, isOsAccountExists, OsAccountManagerWrapper, IsOsAccountExists, const int, bool& isOsAccountExists); + + static int32_t GetDefaultForegroundUserId() + { + return 100; + } }; } // namespace AppExecFwk } // namespace OHOS diff --git a/test/unittest/ability_auto_startup_service_third_test/BUILD.gn b/test/unittest/ability_auto_startup_service_third_test/BUILD.gn index 5b328b8a004..b95cb7c1aef 100644 --- a/test/unittest/ability_auto_startup_service_third_test/BUILD.gn +++ b/test/unittest/ability_auto_startup_service_third_test/BUILD.gn @@ -37,6 +37,7 @@ ohos_unittest("ability_auto_startup_service_third_test") { deps = [ "${ability_runtime_innerkits_path}/ability_manager:ability_manager", + "${ability_runtime_innerkits_path}/deps_wrapper:ability_deps_wrapper", "${ability_runtime_native_path}/ability:ability_context_native", "${ability_runtime_native_path}/ability/native:auto_startup_callback", "${ability_runtime_services_path}/common:user_controller", diff --git a/test/unittest/ams_ability_running_record_test/BUILD.gn b/test/unittest/ams_ability_running_record_test/BUILD.gn index 2443ba8cfcd..99a0481c5d5 100644 --- a/test/unittest/ams_ability_running_record_test/BUILD.gn +++ b/test/unittest/ams_ability_running_record_test/BUILD.gn @@ -68,7 +68,6 @@ ohos_unittest("AmsAbilityRunningRecordTest") { "${ability_runtime_services_path}/common:record_cost_time_util", "${ability_runtime_services_path}/common:res_sched_util", "${ability_runtime_services_path}/common:task_handler_wrap", - "${ability_runtime_services_path}/common:user_controller", "${ability_runtime_test_path}/unittest:appmgr_test_source", ] diff --git a/test/unittest/ams_service_load_ability_process_test/BUILD.gn b/test/unittest/ams_service_load_ability_process_test/BUILD.gn index a5e51fd131d..8d6305ea4c3 100644 --- a/test/unittest/ams_service_load_ability_process_test/BUILD.gn +++ b/test/unittest/ams_service_load_ability_process_test/BUILD.gn @@ -77,7 +77,6 @@ ohos_unittest("AmsServiceLoadAbilityProcessTest") { "${ability_runtime_services_path}/common:record_cost_time_util", "${ability_runtime_services_path}/common:res_sched_util", "${ability_runtime_services_path}/common:task_handler_wrap", - "${ability_runtime_services_path}/common:user_controller", "${ability_runtime_test_path}/unittest:appmgr_test_source", ] diff --git a/test/unittest/ams_service_startup_test/BUILD.gn b/test/unittest/ams_service_startup_test/BUILD.gn index 7af0586e5dd..4a9632e6a1a 100644 --- a/test/unittest/ams_service_startup_test/BUILD.gn +++ b/test/unittest/ams_service_startup_test/BUILD.gn @@ -69,7 +69,6 @@ ohos_unittest("AmsServiceStartupTest") { "${ability_runtime_services_path}/common:record_cost_time_util", "${ability_runtime_services_path}/common:res_sched_util", "${ability_runtime_services_path}/common:task_handler_wrap", - "${ability_runtime_services_path}/common:user_controller", "${ability_runtime_test_path}/unittest:appmgr_test_source", ] diff --git a/test/unittest/app_mgr_service_event_handler_test/BUILD.gn b/test/unittest/app_mgr_service_event_handler_test/BUILD.gn index 32bd151db7c..b69100667f2 100644 --- a/test/unittest/app_mgr_service_event_handler_test/BUILD.gn +++ b/test/unittest/app_mgr_service_event_handler_test/BUILD.gn @@ -73,7 +73,6 @@ ohos_unittest("AMSEventHandlerTest") { "${ability_runtime_services_path}/common:record_cost_time_util", "${ability_runtime_services_path}/common:res_sched_util", "${ability_runtime_services_path}/common:task_handler_wrap", - "${ability_runtime_services_path}/common:user_controller", "${ability_runtime_test_path}/unittest:appmgr_test_source", ] diff --git a/test/unittest/app_mgr_service_fourth_test/BUILD.gn b/test/unittest/app_mgr_service_fourth_test/BUILD.gn index 0c4e8e0b2c8..b872283894b 100644 --- a/test/unittest/app_mgr_service_fourth_test/BUILD.gn +++ b/test/unittest/app_mgr_service_fourth_test/BUILD.gn @@ -63,7 +63,6 @@ ohos_unittest("app_mgr_service_fourth_test") { "${ability_runtime_services_path}/common:app_util", "${ability_runtime_services_path}/common:record_cost_time_util", "${ability_runtime_services_path}/common:task_handler_wrap", - "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ diff --git a/test/unittest/app_mgr_service_inner_eighth_test/BUILD.gn b/test/unittest/app_mgr_service_inner_eighth_test/BUILD.gn index c3d4bdc8e4b..4d72806a667 100644 --- a/test/unittest/app_mgr_service_inner_eighth_test/BUILD.gn +++ b/test/unittest/app_mgr_service_inner_eighth_test/BUILD.gn @@ -105,7 +105,6 @@ ohos_unittest("app_mgr_service_inner_eighth_test") { "${ability_runtime_services_path}/common:perm_verification", "${ability_runtime_services_path}/common:res_sched_util", "${ability_runtime_services_path}/common:task_handler_wrap", - "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ diff --git a/test/unittest/app_mgr_service_inner_ninth_test/BUILD.gn b/test/unittest/app_mgr_service_inner_ninth_test/BUILD.gn index 98c1013fa47..f491ef2af5c 100644 --- a/test/unittest/app_mgr_service_inner_ninth_test/BUILD.gn +++ b/test/unittest/app_mgr_service_inner_ninth_test/BUILD.gn @@ -104,7 +104,6 @@ ohos_unittest("app_mgr_service_inner_ninth_test") { "${ability_runtime_services_path}/common:perm_verification", "${ability_runtime_services_path}/common:res_sched_util", "${ability_runtime_services_path}/common:task_handler_wrap", - "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ diff --git a/test/unittest/app_mgr_service_inner_seventh_test/BUILD.gn b/test/unittest/app_mgr_service_inner_seventh_test/BUILD.gn index c81ab32d022..65dc9dee903 100644 --- a/test/unittest/app_mgr_service_inner_seventh_test/BUILD.gn +++ b/test/unittest/app_mgr_service_inner_seventh_test/BUILD.gn @@ -104,7 +104,6 @@ ohos_unittest("app_mgr_service_inner_seventh_test") { "${ability_runtime_services_path}/common:perm_verification", "${ability_runtime_services_path}/common:res_sched_util", "${ability_runtime_services_path}/common:task_handler_wrap", - "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ diff --git a/test/unittest/app_mgr_service_inner_tenth_test/BUILD.gn b/test/unittest/app_mgr_service_inner_tenth_test/BUILD.gn index 73f0921899c..1e1aaa2e5a5 100644 --- a/test/unittest/app_mgr_service_inner_tenth_test/BUILD.gn +++ b/test/unittest/app_mgr_service_inner_tenth_test/BUILD.gn @@ -109,7 +109,6 @@ ohos_unittest("app_mgr_service_inner_tenth_test") { "${ability_runtime_services_path}/common:perm_verification", "${ability_runtime_services_path}/common:res_sched_util", "${ability_runtime_services_path}/common:task_handler_wrap", - "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ diff --git a/test/unittest/app_mgr_service_inner_tenth_test/app_mgr_service_inner_tenth_test.cpp b/test/unittest/app_mgr_service_inner_tenth_test/app_mgr_service_inner_tenth_test.cpp index 6dd89754938..f27ab3931b3 100644 --- a/test/unittest/app_mgr_service_inner_tenth_test/app_mgr_service_inner_tenth_test.cpp +++ b/test/unittest/app_mgr_service_inner_tenth_test/app_mgr_service_inner_tenth_test.cpp @@ -2324,5 +2324,26 @@ HWTEST_F(AppMgrServiceInnerTenthTest, QueryRunningSharedBundles_002, TestSize.Le AAFwk::MyStatus::GetInstance().getAppRunningRecordByPid_ = nullptr; TAG_LOGI(AAFwkTag::TEST, "QueryRunningSharedBundles_002 end"); } + +/** + * @tc.name: GetCallerUserId_001 + * @tc.desc: Test GetCallerUserId + * @tc.type: FUNC + */ +HWTEST_F(AppMgrServiceInnerTenthTest, GetCallerUserId_001, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "GetCallerUserId_001 start"); + auto appMgrServiceInner = std::make_shared(); + int32_t uid = 0; + int32_t userId = appMgrServiceInner->GetCallerUserId(uid); + EXPECT_EQ(userId, 100); + uid = 200000; + userId = appMgrServiceInner->GetCallerUserId(uid); + EXPECT_EQ(userId, 100); + uid = 20000000; + userId = appMgrServiceInner->GetCallerUserId(uid); + EXPECT_EQ(userId, 100); + TAG_LOGI(AAFwkTag::TEST, "GetCallerUserId_001 end"); +} } // namespace AppExecFwk } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/cache_process_manager_second_test/BUILD.gn b/test/unittest/cache_process_manager_second_test/BUILD.gn index 855c317480d..2308e7e7c6e 100644 --- a/test/unittest/cache_process_manager_second_test/BUILD.gn +++ b/test/unittest/cache_process_manager_second_test/BUILD.gn @@ -118,7 +118,6 @@ ohos_unittest("cache_process_manager_second_test") { "${ability_runtime_services_path}/common:perm_verification", "${ability_runtime_services_path}/common:res_sched_util", "${ability_runtime_services_path}/common:task_handler_wrap", - "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ diff --git a/test/unittest/os_account_manager_wrapper_test/os_account_manager_wrapper_test.cpp b/test/unittest/os_account_manager_wrapper_test/os_account_manager_wrapper_test.cpp index 77569fbf529..8567f8aff4f 100644 --- a/test/unittest/os_account_manager_wrapper_test/os_account_manager_wrapper_test.cpp +++ b/test/unittest/os_account_manager_wrapper_test/os_account_manager_wrapper_test.cpp @@ -126,5 +126,32 @@ HWTEST_F(OsAccountManagerWrapperTest, GetCurrentActiveAccountId_0100, TestSize.L int ret = DelayedSingleton::GetInstance()->GetCurrentActiveAccountId(); EXPECT_EQ(ret, 100); } + +/** + * @tc.name: GetDefaultForegroundUserId_0100 + * @tc.desc: Get default accountId. + * @tc.type: FUNC + */ +HWTEST_F(OsAccountManagerWrapperTest, GetDefaultForegroundUserId_0100, TestSize.Level1) +{ + int32_t userId = DelayedSingleton::GetInstance()->GetDefaultForegroundUserId(); + EXPECT_EQ(userId, 100); +} + +/** + * @tc.name: IsForegroundUser_0100 + * @tc.desc: Is foreground user. + * @tc.type: FUNC + */ +HWTEST_F(OsAccountManagerWrapperTest, IsForegroundUser_0100, TestSize.Level1) +{ + int32_t userId = 100; + bool ret = DelayedSingleton::GetInstance()->IsForegroundUser(userId); + EXPECT_TRUE(ret); + + userId = 600; + ret = DelayedSingleton::GetInstance()->IsForegroundUser(userId); + EXPECT_FALSE(ret); +} } // namespace AAFwk } // namespace OHOS diff --git a/utils/server/constant/server_constant.h b/utils/server/constant/server_constant.h index 0eed5a0ba34..d4434e9a7ee 100644 --- a/utils/server/constant/server_constant.h +++ b/utils/server/constant/server_constant.h @@ -23,7 +23,6 @@ constexpr const char* IS_CALL_BY_SCB = "isCallBySCB"; constexpr uint32_t SCENARIO_MOVE_MISSION_TO_FRONT = 0x00000001; constexpr uint32_t SCENARIO_SHOW_ABILITY = 0x00000002; constexpr uint32_t SCENARIO_BACK_TO_CALLER_ABILITY_WITH_RESULT = 0x00000004; -constexpr uint64_t DEFAULT_DISPLAY_ID = 0; } // namespace ServerConstant } // namespace OHOS::AbilityRuntime #endif // OHOS_ABILITY_RUNTIME_SERVER_CONSTANT_H \ No newline at end of file -- Gitee