From 5f147ed170084571f73fd7d888c4a5f4d01afc45 Mon Sep 17 00:00:00 2001 From: wendel Date: Tue, 12 Aug 2025 20:29:40 +0800 Subject: [PATCH] multi foreground users Signed-off-by: wendel Change-Id: Ief03dcd3446f3ebbd8dec9204ff1b5e67974c738 --- .../include/ability_manager_client.h | 3 +- .../include/ability_manager_interface.h | 3 +- .../include/appmgr/app_mgr_client.h | 3 +- .../include/appmgr/app_mgr_interface.h | 3 +- .../include/appmgr/app_mgr_proxy.h | 3 +- .../app_manager/src/appmgr/app_mgr_client.cpp | 4 +- .../app_manager/src/appmgr/app_mgr_proxy.cpp | 3 +- .../app_manager/src/appmgr/app_mgr_stub.cpp | 3 +- services/abilitymgr/BUILD.gn | 1 + .../include/ability_auto_startup_service.h | 1 - .../include/ability_manager_proxy.h | 4 +- .../include/ability_manager_service.h | 12 +- services/abilitymgr/include/user_controller.h | 27 +- .../abilitymgr/include/user_event_handler.h | 7 +- services/abilitymgr/libabilityms.map | 1 + .../src/ability_auto_startup_service.cpp | 25 +- .../src/ability_connect_manager.cpp | 11 +- .../abilitymgr/src/ability_manager_client.cpp | 5 +- .../abilitymgr/src/ability_manager_proxy.cpp | 6 +- .../src/ability_manager_service.cpp | 237 ++++++------- .../abilitymgr/src/ability_manager_stub.cpp | 3 +- .../keep_alive/ability_keep_alive_service.cpp | 2 +- .../keep_alive/keep_alive_process_manager.cpp | 2 +- .../resident_process_manager.cpp | 2 +- services/abilitymgr/src/user_controller.cpp | 97 ++--- .../abilitymgr/src/user_event_handler.cpp | 10 +- services/appmgr/BUILD.gn | 2 + services/appmgr/include/app_mgr_service.h | 3 +- .../appmgr/include/app_mgr_service_inner.h | 5 +- services/appmgr/src/app_mgr_service.cpp | 20 +- services/appmgr/src/app_mgr_service_inner.cpp | 103 +++--- services/common/BUILD.gn | 29 ++ services/common/include/display_util.h | 12 + .../include/user_controller/user_manager.h | 49 +++ .../src/user_controller/user_manager.cpp | 78 ++++ .../BUILD.gn | 1 + .../BUILD.gn | 1 + .../abilityautostartupserviceb_fuzzer.cpp | 1 - .../BUILD.gn | 1 + .../abilitymanagerservicefourth_fuzzer.cpp | 2 +- .../abilitymanagerservicesixth_fuzzer.cpp | 1 - .../startuser_fuzzer/startuser_fuzzer.cpp | 2 +- .../AMS/mock_ability_manager_client.cpp | 5 +- .../AMS/mock_serviceability_manager_service.h | 2 +- .../include/mock_ability_manager_service.h | 2 +- .../mock_ability_delegator_stub.cpp | 6 +- .../mock_ability_delegator_stub.h | 4 +- .../include/mock_app_mgr_service.h | 4 +- .../AMS/mock_ability_manager_service.h | 2 +- .../AMS/mock_serviceability_manager_service.h | 2 +- .../include/appmgr/app_mgr_client.h | 3 +- .../include/appmgr/app_mgr_interface.h | 3 +- .../include/mock_app_mgr_service.h | 4 +- .../mock_iabilitymanager.h | 2 +- .../ability_timeout_module_test.cpp | 9 - test/moduletest/common/ams/BUILD.gn | 1 + .../ams/ability_running_record_test/BUILD.gn | 2 + .../common/ams/app_mgr_service_test/BUILD.gn | 2 + .../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 | 6 +- .../common/ams/ipc_app_mgr_test/BUILD.gn | 2 + .../ams/ipc_app_scheduler_test/BUILD.gn | 2 + .../ams/service_start_process_test/BUILD.gn | 2 + .../mock/include/mock_ability_mgr_service.h | 2 +- .../mock/include/mock_app_mgr_client.h | 4 +- .../running_infos_module_test.cpp | 7 - .../start_ability_implicit_module_test.cpp | 7 +- .../ability_manager_service.h | 2 +- .../user_controller/user_manager.cpp | 78 ++++ .../user_controller/user_manager.h | 49 +++ .../user_event_handler/user_event_handler.h | 3 +- .../user_controller_unit_test/BUILD.gn | 2 + .../user_controller_unit_test.cpp | 334 ++++++++---------- test/unittest/BUILD.gn | 1 + .../BUILD.gn | 1 + .../BUILD.gn | 1 + .../ability_auto_startup_service_test.cpp | 65 ---- .../BUILD.gn | 1 + .../ability_manager_stub_mock_second_test.h | 2 +- .../ability_manager_client_branch_test.cpp | 5 +- .../ability_manager_stub_mock_test.h | 2 +- .../include/ability_manager_stub_mock_test.h | 2 +- .../ability_manager_stub_mock.h | 2 +- .../ability_manager_stub_mock.h | 2 +- .../ability_manager_stub_mock.h | 2 +- .../ability_manager_stub_mock.h | 2 +- .../ability_manager_proxy_test.cpp | 5 +- .../ability_manager_stub_mock.h | 2 +- .../ability_manager_proxy_third_test.cpp | 15 +- .../ability_manager_stub_mock.h | 2 +- .../ability_manager_service_account_test.cpp | 48 +-- .../ability_manager_service_eighth_test.cpp | 19 +- .../BUILD.gn | 1 + .../BUILD.gn | 1 + .../ability_manager_service_second_test.cpp | 38 +- .../ability_manager_service_sixth_test.cpp | 1 - .../ability_manager_service_tenth_test.cpp | 2 +- .../BUILD.gn | 1 + .../ability_manager_service_third_test.cpp | 3 - .../BUILD.gn | 1 + .../ability_manager_service_twelfth_test.cpp | 5 +- .../ability_manager_stub_impl_mock.h | 2 +- .../ability_manager_stub_mock.h | 2 +- .../mock/include/mock_app_mgr_service.h | 4 +- .../ams_ability_running_record_test/BUILD.gn | 7 +- .../BUILD.gn | 2 + .../ams_service_startup_test/BUILD.gn | 7 +- .../app_mgr_proxy_test/app_mgr_proxy_test.cpp | 2 +- .../BUILD.gn | 2 + .../app_mgr_service_fourth_test/BUILD.gn | 2 + .../BUILD.gn | 2 + .../app_mgr_service_inner_eighth_test.cpp | 32 -- .../app_mgr_service_inner_ninth_test/BUILD.gn | 2 + .../app_mgr_service_inner_second_test.cpp | 10 +- .../BUILD.gn | 2 + .../app_mgr_service_inner_seventh_test.cpp | 85 ++--- .../app_mgr_service_inner_tenth_test/BUILD.gn | 2 + .../app_mgr_service_inner_test.cpp | 3 +- .../app_mgr_stub_test/app_mgr_stub_test.cpp | 2 +- .../ability_manager_stub_mock.h | 2 +- .../BUILD.gn | 2 + .../mock_ability_manager_client.cpp | 3 +- .../mock/include/ability_manager_service.h | 8 +- .../mock/src/ability_manager_service.cpp | 11 +- .../include/mock_app_mgr_service.h | 4 +- .../ability_manager_stub_mock.h | 2 +- .../mock_ability_manager_service.h | 2 +- .../ui_ability_lifecycle_manager_test.cpp | 2 +- .../mock/include/mock_app_mgr_service.h | 4 +- .../user_controller_test.cpp | 91 +++-- .../user_event_handler_test.cpp | 3 +- test/unittest/user_manager_test/BUILD.gn | 62 ++++ .../user_manager_test/user_manager_test.cpp | 128 +++++++ tools/test/mock/mock_ability_manager_stub.h | 2 +- 135 files changed, 1197 insertions(+), 874 deletions(-) create mode 100644 services/common/include/user_controller/user_manager.h create mode 100644 services/common/src/user_controller/user_manager.cpp create mode 100644 test/new_test/mock/user_controller/user_controller/user_manager.cpp create mode 100644 test/new_test/mock/user_controller/user_controller/user_manager.h create mode 100644 test/unittest/user_manager_test/BUILD.gn create mode 100644 test/unittest/user_manager_test/user_manager_test.cpp diff --git a/interfaces/inner_api/ability_manager/include/ability_manager_client.h b/interfaces/inner_api/ability_manager/include/ability_manager_client.h index 60e6e80a814..6c386d483d3 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_client.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_client.h @@ -1012,11 +1012,12 @@ public: /** * @brief start user. * @param accountId accountId. + * @param displayId logical screen id. * @param accountId is appRecovery or not. * * @return Returns ERR_OK on success, others on failure. */ - ErrCode StartUser(int accountId, sptr callback, bool isAppRecovery = false); + ErrCode StartUser(int accountId, uint64_t displayId, sptr callback, bool isAppRecovery = false); /** * @brief stop user. diff --git a/interfaces/inner_api/ability_manager/include/ability_manager_interface.h b/interfaces/inner_api/ability_manager/include/ability_manager_interface.h index c04c88ea43a..5ca59587059 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_interface.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_interface.h @@ -1095,10 +1095,11 @@ public: /** * @brief start user. * @param accountId accountId. + * @param displayId logical screen id. * @param isAppRecovery is appRecovery or not. * @return Returns ERR_OK on success, others on failure. */ - virtual int StartUser(int userId, sptr callback, bool isAppRecovery = false) = 0; + virtual int StartUser(int userId, uint64_t displayId, sptr callback, bool isAppRecovery = false) = 0; /** * @brief stop user. diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_client.h b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_client.h index 89149bd4b8d..f536dfe4fe6 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_client.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_client.h @@ -284,11 +284,10 @@ public: * * @param bundlename, bundle name in Application record. * @param instanceKeys, output instance keys of the multi-instance app. - * @param userId, user id. * @return ERR_OK ,return back success,others fail. */ virtual AppMgrResultCode GetAllRunningInstanceKeysByBundleName(const std::string &bundleName, - std::vector &instanceKeys, int32_t userId = -1); + std::vector &instanceKeys); /** * GetAllRenderProcesses, call GetAllRenderProcesses() through proxy project. diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h index 89d21a37c36..c0bd1abed1e 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h @@ -189,11 +189,10 @@ public: * * @param bundlename, bundle name in Application record. * @param instanceKeys, output instance keys of the multi-instance app. - * @param userId, user id. * @return ERR_OK ,return back success,others fail. */ virtual int32_t GetAllRunningInstanceKeysByBundleName(const std::string &bundleName, - std::vector &instanceKeys, int32_t userId = -1) = 0; + std::vector &instanceKeys) = 0; /** * GetRunningProcessesByBundleType, call GetRunningProcessesByBundleType() through proxy project. diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_proxy.h b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_proxy.h index ad22fd3f5aa..448ec1c1122 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_proxy.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_proxy.h @@ -157,11 +157,10 @@ public: * * @param bundlename, bundle name in Application record. * @param instanceKeys, output instance keys of the multi-instance app. - * @param userId, user id. * @return ERR_OK ,return back success,others fail. */ virtual int32_t GetAllRunningInstanceKeysByBundleName(const std::string &bundleName, - std::vector &instanceKeys, int32_t userId = -1) override; + std::vector &instanceKeys) override; /** * GetRunningProcessesByBundleType, call GetRunningProcessesByBundleType() through proxy project. diff --git a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_client.cpp b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_client.cpp index e27824f685c..ec6b7ee496f 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_client.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_client.cpp @@ -514,11 +514,11 @@ AppMgrResultCode AppMgrClient::GetAllRunningInstanceKeysBySelf(std::vector &instanceKeys, int32_t userId) + std::vector &instanceKeys) { sptr service = iface_cast(mgrHolder_->GetRemoteObject()); if (service != nullptr) { - int32_t result = service->GetAllRunningInstanceKeysByBundleName(bundleName, instanceKeys, userId); + int32_t result = service->GetAllRunningInstanceKeysByBundleName(bundleName, instanceKeys); if (result == ERR_OK) { return AppMgrResultCode::RESULT_OK; } diff --git a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_proxy.cpp b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_proxy.cpp index 4999e25f1ac..f52ab7861db 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_proxy.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_proxy.cpp @@ -256,7 +256,7 @@ int32_t AppMgrProxy::GetAllRunningInstanceKeysBySelf(std::vector &i } int32_t AppMgrProxy::GetAllRunningInstanceKeysByBundleName(const std::string &bundleName, - std::vector &instanceKeys, int32_t userId) + std::vector &instanceKeys) { MessageParcel data; MessageParcel reply; @@ -265,7 +265,6 @@ int32_t AppMgrProxy::GetAllRunningInstanceKeysByBundleName(const std::string &bu return ERR_FLATTEN_OBJECT; } PARCEL_UTIL_WRITE_RET_INT(data, String, bundleName); - PARCEL_UTIL_WRITE_RET_INT(data, Int32, userId); PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::GET_All_RUNNING_INSTANCE_KEYS_BY_BUNDLENAME, data, reply, option); if (!reply.ReadStringVector(&instanceKeys)) { diff --git a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_stub.cpp b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_stub.cpp index 216814a12a0..18f8b7ee658 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_stub.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_stub.cpp @@ -564,9 +564,8 @@ int32_t AppMgrStub::HandleGetAllRunningInstanceKeysBySelf(MessageParcel &data, M int32_t AppMgrStub::HandleGetAllRunningInstanceKeysByBundleName(MessageParcel &data, MessageParcel &reply) { std::string bundleName = data.ReadString(); - int32_t userId = data.ReadInt32(); std::vector instanceKeys; - int32_t result = GetAllRunningInstanceKeysByBundleName(bundleName, instanceKeys, userId); + int32_t result = GetAllRunningInstanceKeysByBundleName(bundleName, instanceKeys); if (!reply.WriteStringVector(instanceKeys)) { TAG_LOGE(AAFwkTag::APPMGR, "failed to write isntanceKeys"); return ERR_INVALID_VALUE; diff --git a/services/abilitymgr/BUILD.gn b/services/abilitymgr/BUILD.gn index 822dce7b58e..69362ad783b 100644 --- a/services/abilitymgr/BUILD.gn +++ b/services/abilitymgr/BUILD.gn @@ -157,6 +157,7 @@ ohos_shared_library("abilityms") { "${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/abilitymgr/include/ability_auto_startup_service.h b/services/abilitymgr/include/ability_auto_startup_service.h index a9ea45b1101..4c2859afc8d 100644 --- a/services/abilitymgr/include/ability_auto_startup_service.h +++ b/services/abilitymgr/include/ability_auto_startup_service.h @@ -144,7 +144,6 @@ private: void CleanResource(const wptr &remote); std::string GetSelfApplicationBundleName(); bool CheckSelfApplication(const std::string &bundleName); - int32_t GetValidUserId(int32_t userId); bool GetBundleInfo(const std::string &bundleName, int32_t userId, int32_t appIndex, AppExecFwk::BundleInfo &bundleInfo); bool GetAbilityData(const AutoStartupInfo &info, AutoStartupAbilityData &abilityData); diff --git a/services/abilitymgr/include/ability_manager_proxy.h b/services/abilitymgr/include/ability_manager_proxy.h index 90aa5002ea4..3e8e2addde1 100644 --- a/services/abilitymgr/include/ability_manager_proxy.h +++ b/services/abilitymgr/include/ability_manager_proxy.h @@ -855,10 +855,12 @@ public: /** * @brief start user. * @param accountId accountId. + * @param displayId logical screen id. * @param isAppRecovery is appRecovery or not. * @return Returns ERR_OK on success, others on failure. */ - virtual int StartUser(int userId, sptr callback, bool isAppRecovery = false) override; + virtual int StartUser(int userId, uint64_t displayId, sptr callback, + bool isAppRecovery = false) override; /** * @brief stop user. diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h index 01a1152b878..b1b917d2d27 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -1218,7 +1218,8 @@ public: */ sptr GetAbilityTokenByMissionId(int32_t missionId); - virtual int StartUser(int userId, sptr callback, bool isAppRecovery = false) override; + virtual int StartUser(int userId, uint64_t displayId, sptr callback, + bool isAppRecovery = false) override; virtual int StopUser(int userId, const sptr &callback) override; @@ -1591,7 +1592,7 @@ public: * get the user id. * */ - int32_t GetUserId() const; + int32_t GetCallerUserId() const; virtual int32_t RegisterStatusBarDelegate(sptr delegate) override; @@ -2216,7 +2217,7 @@ private: * start highest priority ability. * */ - int StartHighestPriorityAbility(int32_t userId, bool isBoot, bool isAppRecovery = false); + int StartHighestPriorityAbility(int32_t userId, uint64_t displayId, bool isBoot, bool isAppRecovery = false); #endif /** * connect bms. @@ -2288,7 +2289,7 @@ private: void DumpMissionListInner(const std::string &args, std::vector &info); void DumpMissionInfosInner(const std::string &args, std::vector &info); - bool JudgeMultiUserConcurrency(const int32_t userId); + bool JudgeMultiUserConcurrency(int32_t userId); bool CheckCrossUser(const int32_t userId, AppExecFwk::ExtensionAbilityType extensionType); void SendExtensionReport(EventInfo &eventInfo, int32_t errCode, bool isService = false); void SendIntentReport(EventInfo &eventInfo, int32_t errCode, const std::string &intentName); @@ -2325,7 +2326,7 @@ private: void StartFreezingScreen(); void StopFreezingScreen(); void UserStarted(int32_t userId); - int SwitchToUser(int32_t oldUserId, int32_t userId, sptr callback, + int SwitchToUser(int32_t oldUserId, int32_t userId, uint64_t displayId, sptr callback, bool isAppRecovery = false); void SwitchManagers(int32_t userId, bool switchUser = true); void StartUserApps(); @@ -2740,7 +2741,6 @@ private: std::shared_ptr freeInstallManager_; std::shared_ptr subManagersHelper_; - std::shared_ptr userController_; sptr abilityController_ = nullptr; std::multimap timeoutMap_; diff --git a/services/abilitymgr/include/user_controller.h b/services/abilitymgr/include/user_controller.h index c516fb9206a..3082af55b56 100644 --- a/services/abilitymgr/include/user_controller.h +++ b/services/abilitymgr/include/user_controller.h @@ -60,10 +60,12 @@ public: std::shared_ptr userItem; }; -class UserController : public std::enable_shared_from_this { +class UserController { public: - UserController(); - virtual ~UserController(); + UserController& operator=(const UserController&) = delete; + UserController(const UserController&) = delete; + virtual ~UserController() = default; + static UserController& GetInstance(); void Init(); @@ -71,10 +73,11 @@ public: * Start user, if it is not running.. * * @param userId id of started user. + * @param displayId logical screen id. * @param isForeground whether user should brout to foreground. * @return 0 if the user has been successfully started. */ - int StartUser(int32_t userId, sptr callback, bool isAppRecovery = false); + int StartUser(int32_t userId, uint64_t displayId, sptr callback, bool isAppRecovery = false); /** * Stop user, if it is running.. @@ -92,9 +95,9 @@ public: */ int32_t LogoutUser(int32_t userId, sptr callback = nullptr); - int32_t GetCurrentUserId(); + int32_t GetCurrentUserId(uint64_t displayId); - std::shared_ptr GetUserItem(int32_t userId); + bool GetDisplayIdByUserId(int32_t userId, uint64_t &displayId); void ProcessEvent(const EventWrap &event); @@ -104,14 +107,16 @@ public: void ClearAbilityUserItems(int32_t userId); -private: bool IsCurrentUser(int32_t userId); + +private: + UserController() = default; + bool IsCurrentUser(int32_t userId, uint64_t displayId); bool IsExistOsAccount(int32_t userId) const; std::shared_ptr GetOrCreateUserItem(int32_t userId); - void SetCurrentUserId(int32_t userId); - int MoveUserToForeground(int32_t oldUserId, int32_t newUserId, sptr callback, + void SetCurrentUserId(int32_t userId, uint64_t displayId); + int MoveUserToForeground(int32_t oldUserId, int32_t newUserId, uint64_t displayId, sptr callback, bool isAppRecovery = false); - void UserBootDone(std::shared_ptr &item); void BroadcastUserBackground(int32_t userId); void BroadcastUserForeground(int32_t userId); void BroadcastUserStopping(int32_t userId); @@ -138,8 +143,6 @@ private: void HandleUserSwitchDone(int32_t userId); int32_t StartNoHeadUser(int32_t userId, sptr callback) const; -private: - int32_t currentUserId_ = USER_ID_NO_HEAD; int32_t freezingNewUserId_ = -1; std::shared_ptr eventHandler_; std::unordered_map> userItems_; diff --git a/services/abilitymgr/include/user_event_handler.h b/services/abilitymgr/include/user_event_handler.h index 49b53eb9244..75aeab58159 100644 --- a/services/abilitymgr/include/user_event_handler.h +++ b/services/abilitymgr/include/user_event_handler.h @@ -22,11 +22,9 @@ namespace OHOS { namespace AAFwk { -class UserController; class UserEventHandler : public EventHandlerWrap { public: - UserEventHandler( - const std::shared_ptr &taskHandler, const std::weak_ptr &owner); + UserEventHandler(const std::shared_ptr &taskHandler); virtual ~UserEventHandler() = default; static constexpr uint32_t EVENT_SYSTEM_USER_START = 10; @@ -42,9 +40,6 @@ public: * @param event, inner event loop. */ void ProcessEvent(const EventWrap &event) override; - -private: - std::weak_ptr controller_; }; } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/libabilityms.map b/services/abilitymgr/libabilityms.map index 65832ba509c..5eaf3884b63 100644 --- a/services/abilitymgr/libabilityms.map +++ b/services/abilitymgr/libabilityms.map @@ -93,6 +93,7 @@ *UpdateCallerInfoUtil*; *UriUtils*; *UserController*; + *UserEventHandler*; *UnlockScreenManager*; *WantSenderInfo*; *SenderInfo*; diff --git a/services/abilitymgr/src/ability_auto_startup_service.cpp b/services/abilitymgr/src/ability_auto_startup_service.cpp index 6c6d2a2218c..8e847cda0d9 100644 --- a/services/abilitymgr/src/ability_auto_startup_service.cpp +++ b/services/abilitymgr/src/ability_auto_startup_service.cpp @@ -23,6 +23,7 @@ #include "hilog_tag_wrapper.h" #include "in_process_call_wrapper.h" #include "permission_constants.h" +#include "user_controller/user_manager.h" namespace OHOS { namespace AbilityRuntime { @@ -252,8 +253,7 @@ int32_t AbilityAutoStartupService::CheckAutoStartupData(const std::string &bundl int32_t appIndex = 0; AppExecFwk::BundleInfo bundleInfo; int32_t userId = uid / AppExecFwk::Constants::BASE_USER_RANGE; - int32_t validUserId = GetValidUserId(userId); - if (!GetBundleInfo(bundleName, validUserId, appIndex, bundleInfo)) { + if (!GetBundleInfo(bundleName, userId, appIndex, bundleInfo)) { return INNER_ERR; } auto tokenId = bundleInfo.applicationInfo.accessTokenId; @@ -300,8 +300,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); - int32_t currentUserId = DelayedSingleton::GetInstance()->GetUserId(); - bool isUserIdMatch = (info.userId == currentUserId); + bool isUserIdMatch = UserManager::GetInstance().IsCurrentUser(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"); @@ -408,20 +407,6 @@ bool AbilityAutoStartupService::CheckSelfApplication(const std::string &bundleNa return GetSelfApplicationBundleName() == bundleName ? true : false; } -int32_t AbilityAutoStartupService::GetValidUserId(int32_t userId) -{ - TAG_LOGD(AAFwkTag::AUTO_STARTUP, "userId = %{public}d.", userId); - int32_t validUserId = userId; - - if (userId == -1) { - validUserId = IPCSkeleton::GetCallingUid() / AppExecFwk::Constants::BASE_USER_RANGE; - } - if (validUserId == U0_USER_ID || validUserId == U1_USER_ID) { - validUserId = DelayedSingleton::GetInstance()->GetUserId(); - } - return validUserId; -} - bool AbilityAutoStartupService::GetBundleInfo(const std::string &bundleName, int32_t userId, int32_t appIndex, AppExecFwk::BundleInfo &bundleInfo) { @@ -468,8 +453,8 @@ bool AbilityAutoStartupService::GetAbilityData(const AutoStartupInfo &info, Auto info.bundleName.c_str(), info.moduleName.c_str(), info.abilityName.c_str(), info.accessTokenId.c_str(), info.setterUserId); AppExecFwk::BundleInfo bundleInfo; - int32_t validUserId = GetValidUserId(info.userId); - if (!GetBundleInfo(info.bundleName, validUserId, info.appCloneIndex, bundleInfo)) { + int32_t callerUserId = DelayedSingleton::GetInstance()->GetCallerUserId(); + if (!GetBundleInfo(info.bundleName, callerUserId, info.appCloneIndex, bundleInfo)) { TAG_LOGE(AAFwkTag::AUTO_STARTUP, "GetBundleInfo fail"); return false; } diff --git a/services/abilitymgr/src/ability_connect_manager.cpp b/services/abilitymgr/src/ability_connect_manager.cpp index 6085e0b6c20..18d7d36eb5c 100644 --- a/services/abilitymgr/src/ability_connect_manager.cpp +++ b/services/abilitymgr/src/ability_connect_manager.cpp @@ -652,7 +652,7 @@ int AbilityConnectManager::ConnectAbilityLocked(const AbilityRequest &abilityReq #ifdef SUPPORT_UPMS // grant uri to service extension by connect, must call out of serialMutex_ if (userId_ == U0_USER_ID || - userId_ == DelayedSingleton::GetInstance()->GetUserId()) { + userId_ == DelayedSingleton::GetInstance()->GetCallerUserId()) { UriUtils::GetInstance().GrantUriPermissionForServiceExtension(abilityRequest); } else { TAG_LOGD(AAFwkTag::ABILITYMGR, "cross user, without grantUriPermission"); @@ -1895,7 +1895,7 @@ void AbilityConnectManager::HandleStartTimeoutTask(const std::shared_ptr::GetInstance()->AttachTimeOut(abilityRecord->GetToken()); if (abilityRecord->IsSceneBoard()) { - if (DelayedSingleton::GetInstance()->GetUserId() == userId_) { + if (UserController::GetInstance().IsCurrentUser(userId_)) { RestartAbility(abilityRecord, userId_); } return; @@ -2483,8 +2483,7 @@ void AbilityConnectManager::CleanActivatingTimeoutAbility(std::shared_ptrIsSceneBoard() || - DelayedSingleton::GetInstance()->GetUserId() == userId_) { + if (!abilityRecord->IsSceneBoard() || UserController::GetInstance().IsCurrentUser(userId_)) { RestartAbility(abilityRecord, userId_); } } @@ -2802,6 +2801,10 @@ void AbilityConnectManager::RestartAbility(const std::shared_ptr } if (abilityRecord->IsSceneBoard()) { requestInfo.want.SetParam("ohos.app.recovery", true); + uint64_t displayId = 0; + if (UserController::GetInstance().GetDisplayIdByUserId(userId_, displayId)) { + requestInfo.want.SetParam(Want::PARAM_RESV_DISPLAY_ID, static_cast(displayId)); + } DelayedSingleton::GetInstance()->EnableListForSCBRecovery(userId_); } requestInfo.restartCount = abilityRecord->GetRestartCount(); diff --git a/services/abilitymgr/src/ability_manager_client.cpp b/services/abilitymgr/src/ability_manager_client.cpp index e4149b294d1..eb268f79125 100644 --- a/services/abilitymgr/src/ability_manager_client.cpp +++ b/services/abilitymgr/src/ability_manager_client.cpp @@ -1236,13 +1236,14 @@ ErrCode AbilityManagerClient::StopSyncRemoteMissions(const std::string &devId) return abms->StopSyncRemoteMissions(devId); } -ErrCode AbilityManagerClient::StartUser(int accountId, sptr callback, bool isAppRecovery) +ErrCode AbilityManagerClient::StartUser(int accountId, uint64_t displayId, sptr callback, + bool isAppRecovery) { TAG_LOGI(AAFwkTag::ABILITYMGR, "accountId:%{public}d, isAppRecovery:%{public}d", accountId, isAppRecovery); auto abms = GetAbilityManager(); CHECK_POINTER_RETURN_NOT_CONNECTED(abms); - return abms->StartUser(accountId, callback, isAppRecovery); + return abms->StartUser(accountId, displayId, callback, isAppRecovery); } ErrCode AbilityManagerClient::StopUser(int accountId, sptr callback) diff --git a/services/abilitymgr/src/ability_manager_proxy.cpp b/services/abilitymgr/src/ability_manager_proxy.cpp index 8ab7a0ec36f..4494e0daa6f 100644 --- a/services/abilitymgr/src/ability_manager_proxy.cpp +++ b/services/abilitymgr/src/ability_manager_proxy.cpp @@ -3242,7 +3242,7 @@ int AbilityManagerProxy::MoveMissionsToBackground(const std::vector& mi return reply.ReadInt32(); } -int AbilityManagerProxy::StartUser(int userId, sptr callback, bool isAppRecovery) +int AbilityManagerProxy::StartUser(int userId, uint64_t displayId, sptr callback, bool isAppRecovery) { Ability_MANAGER_HITRACE_CHAIN_NAME("StartUser", HITRACE_FLAG_INCLUDE_ASYNC); MessageParcel data; @@ -3253,6 +3253,10 @@ int AbilityManagerProxy::StartUser(int userId, sptr callback, boo TAG_LOGE(AAFwkTag::ABILITYMGR, "fail"); return ERR_INVALID_VALUE; } + if (!data.WriteUint64(displayId)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "write displayId failed"); + return IPC_PROXY_ERR; + } if (!callback) { data.WriteBool(false); } else { diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index b69764e9456..282c788938c 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -408,8 +408,7 @@ bool AbilityManagerService::Init() CHECK_POINTER_RETURN_BOOL(freeInstallManager_); // init user controller. - userController_ = std::make_shared(); - userController_->Init(); + UserController::GetInstance().Init(); AmsConfigurationParameter::GetInstance().Parse(); TAG_LOGI(AAFwkTag::ABILITYMGR, "config parse"); subManagersHelper_ = std::make_shared(taskHandler_, eventHandler_); @@ -933,7 +932,7 @@ int AbilityManagerService::StartAbilityAsCallerDetails(const Want &want, const s TAG_LOGI(AAFwkTag::ABILITYMGR, "call from interceptor dialog, callerPkg:%{public}s, targetPkg:%{public}s", callerPkg.c_str(), targetPkg.c_str()); - AbilityUtil::AddAbilityJumpRuleToBms(callerPkg, targetPkg, GetUserId()); + AbilityUtil::AddAbilityJumpRuleToBms(callerPkg, targetPkg, GetCallerUserId()); } int32_t ret = StartAbilityWrap(newWant, callerToken, requestCode, false, userId, true, 0, false, isImplicit, false); @@ -971,7 +970,7 @@ int AbilityManagerService::StartAbilityPrechainInterceptor(StartAbilityParams &p HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); auto shouldBlockFunc = [aams = shared_from_this()]() { return aams->ShouldBlockAllAppStart(); }; AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(params.want, params.requestCode, - GetUserId(), true, nullptr, shouldBlockFunc); + GetCallerUserId(), true, nullptr, shouldBlockFunc); auto interceptorResult = interceptorExecuter_ == nullptr ? ERR_INVALID_VALUE : interceptorExecuter_->DoProcess(interceptorParam); if (interceptorResult != ERR_OK) { @@ -1250,7 +1249,7 @@ int AbilityManagerService::StartAbilityInner(const Want &want, const sptrShouldBlockAllAppStart(); }; - AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(want, requestCode, GetUserId(), + AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(want, requestCode, GetCallerUserId(), true, nullptr, shouldBlockFunc); result = interceptorExecuter_ == nullptr ? ERR_NULL_INTERCEPTOR_EXECUTER : interceptorExecuter_->DoProcess(interceptorParam); @@ -1423,7 +1422,7 @@ int AbilityManagerService::StartAbilityInner(const Want &want, const sptr(abilityInfo), isStartAsCaller, appIndex); result = afterCheckExecuter_ == nullptr ? ERR_NULL_AFTER_CHECK_EXECUTER : afterCheckExecuter_->DoProcess(afterCheckParam); @@ -1436,14 +1435,14 @@ int AbilityManagerService::StartAbilityInner(const Want &want, const sptrShouldBlockAllAppStart(); }; - AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(want, requestCode, GetUserId(), + AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(want, requestCode, GetCallerUserId(), true, nullptr, shouldBlockFunc); result = interceptorExecuter_ == nullptr ? ERR_NULL_INTERCEPTOR_EXECUTER : interceptorExecuter_->DoProcess(interceptorParam); @@ -1781,7 +1780,7 @@ int AbilityManagerService::StartAbilityDetails(const Want &want, const AbilitySt } AbilityInterceptorParam afterCheckParam = AbilityInterceptorParam(abilityRequest.want, requestCode, - GetUserId(), true, callerToken, std::make_shared(abilityInfo), false, appIndex); + GetCallerUserId(), true, callerToken, std::make_shared(abilityInfo), false, appIndex); result = afterCheckExecuter_ == nullptr ? ERR_NULL_AFTER_CHECK_EXECUTER : afterCheckExecuter_->DoProcess(afterCheckParam); if (result != ERR_OK) { @@ -2036,7 +2035,7 @@ int AbilityManagerService::StartAbilityForOptionInner(const Want &want, const St } StartAbilityInfoWrap threadLocalInfo(want, validUserId, appIndex, callerToken); auto shouldBlockFunc = [aams = shared_from_this()]() { return aams->ShouldBlockAllAppStart(); }; - AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(want, requestCode, GetUserId(), + AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(want, requestCode, GetCallerUserId(), true, nullptr, shouldBlockFunc); auto result = interceptorExecuter_ == nullptr ? ERR_NULL_INTERCEPTOR_EXECUTER : interceptorExecuter_->DoProcess(interceptorParam); @@ -2231,7 +2230,7 @@ int AbilityManagerService::StartAbilityForOptionInner(const Want &want, const St } Want newWant = abilityRequest.want; - AbilityInterceptorParam afterCheckParam = AbilityInterceptorParam(newWant, requestCode, GetUserId(), + AbilityInterceptorParam afterCheckParam = AbilityInterceptorParam(newWant, requestCode, GetCallerUserId(), true, callerToken, std::make_shared(abilityInfo), isStartAsCaller, appIndex); result = afterCheckExecuter_ == nullptr ? ERR_NULL_AFTER_CHECK_EXECUTER : afterCheckExecuter_->DoProcess(afterCheckParam); @@ -2244,14 +2243,14 @@ int AbilityManagerService::StartAbilityForOptionInner(const Want &want, const St } #ifdef SUPPORT_SCREEN if (result != ERR_OK && isReplaceWantExist) { - result = DialogSessionManager::GetInstance().HandleErmsResult(abilityRequest, GetUserId(), newWant); + result = DialogSessionManager::GetInstance().HandleErmsResult(abilityRequest, GetCallerUserId(), newWant); eventHelper_.SendStartAbilityErrorEvent(eventInfo, result, "HandleErmsResult failed"); return result; } if (result == ERR_OK && - DialogSessionManager::GetInstance().IsCreateCloneSelectorDialog(abilityInfo.bundleName, GetUserId())) { + DialogSessionManager::GetInstance().IsCreateCloneSelectorDialog(abilityInfo.bundleName, GetCallerUserId())) { TAG_LOGI(AAFwkTag::ABILITYMGR, "create clone selector dialog"); - result = CreateCloneSelectorDialog(abilityRequest, GetUserId()); + result = CreateCloneSelectorDialog(abilityRequest, GetCallerUserId()); eventHelper_.SendStartAbilityErrorEvent(eventInfo, result, "CreateCloneSelectorDialog failed"); return result; } @@ -2499,7 +2498,7 @@ int32_t AbilityManagerService::StartUIAbilitiesInterceptorCheck(const Want &want Want newWant = abilityRequest.want; auto abilityInfo = abilityRequest.abilityInfo; auto shouldBlockFunc = [aams = shared_from_this()]() { return aams->ShouldBlockAllAppStart(); }; - AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(want, requestCode, GetUserId(), + AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(want, requestCode, GetCallerUserId(), true, nullptr, shouldBlockFunc); int32_t result = interceptorExecuter_ == nullptr ? ERR_NULL_INTERCEPTOR_EXECUTER : interceptorExecuter_->DoProcess(interceptorParam); @@ -2512,7 +2511,7 @@ int32_t AbilityManagerService::StartUIAbilitiesInterceptorCheck(const Want &want return START_UI_ABILITIES_INTERCEPTOR_CHECK_FAILED; } - AbilityInterceptorParam afterCheckParam = AbilityInterceptorParam(newWant, requestCode, GetUserId(), + AbilityInterceptorParam afterCheckParam = AbilityInterceptorParam(newWant, requestCode, GetCallerUserId(), true, callerToken, std::make_shared(abilityInfo), false, appIndex); result = afterCheckExecuter_ == nullptr ? ERR_NULL_AFTER_CHECK_EXECUTER : afterCheckExecuter_->DoProcess(afterCheckParam); @@ -2594,7 +2593,7 @@ int32_t AbilityManagerService::RequestDialogServiceInner(const Want &want, const int32_t validUserId = GetValidUserId(userId); StartAbilityInfoWrap threadLocalInfo; auto shouldBlockFunc = [aams = shared_from_this()]() { return aams->ShouldBlockAllAppStart(); }; - AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(want, requestCode, GetUserId(), + AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(want, requestCode, GetCallerUserId(), true, nullptr, shouldBlockFunc); auto result = interceptorExecuter_ == nullptr ? ERR_INVALID_VALUE : interceptorExecuter_->DoProcess(interceptorParam); @@ -2642,7 +2641,7 @@ int32_t AbilityManagerService::RequestDialogServiceInner(const Want &want, const } AbilityInterceptorParam afterCheckParam = AbilityInterceptorParam(abilityRequest.want, requestCode, - GetUserId(), true, callerToken, std::make_shared(abilityInfo)); + GetCallerUserId(), true, callerToken, std::make_shared(abilityInfo)); result = afterCheckExecuter_ == nullptr ? ERR_INVALID_VALUE : afterCheckExecuter_->DoProcess(afterCheckParam); if (result != ERR_OK) { @@ -2870,7 +2869,7 @@ int AbilityManagerService::StartUIAbilityBySCBDefault(sptr sessionI Want newWant = abilityRequest.want; auto callerTokenId = IPCSkeleton::GetCallingTokenID(); RemoveUnauthorizedLaunchReasonMessage(sessionInfo->want, abilityRequest, callerTokenId); - AbilityInterceptorParam afterCheckParam = AbilityInterceptorParam(newWant, requestCode, GetUserId(), true, + AbilityInterceptorParam afterCheckParam = AbilityInterceptorParam(newWant, requestCode, GetCallerUserId(), true, sessionInfo->callerToken, std::make_shared(abilityInfo), false, appIndex); result = afterCheckExecuter_ == nullptr ? ERR_INVALID_VALUE : afterCheckExecuter_->DoProcess(afterCheckParam); @@ -2974,7 +2973,7 @@ void AbilityManagerService::AppUpgradeCompleted(int32_t uid) auto bms = AbilityUtil::GetBundleManagerHelper(); CHECK_POINTER(bms); auto userId = uid / BASE_USER_RANGE; - if (userId != U0_USER_ID && userId != U1_USER_ID && userId != GetUserId()) { + if (userId != U0_USER_ID && userId != U1_USER_ID && userId != GetCallerUserId()) { TAG_LOGI(AAFwkTag::ABILITYMGR, "not current user"); return; } @@ -3626,7 +3625,7 @@ int32_t AbilityManagerService::StartExtensionAbilityInner(const Want &want, cons } StartAbilityInfoWrap threadLocalInfo(want, validUserId, appIndex, callerToken, true); auto shouldBlockFunc = [aams = shared_from_this()]() { return aams->ShouldBlockAllAppStart(); }; - AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(want, 0, GetUserId(), false, nullptr, + AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(want, 0, GetCallerUserId(), false, nullptr, shouldBlockFunc); result = interceptorExecuter_ == nullptr ? ERR_INVALID_VALUE : interceptorExecuter_->DoProcess(interceptorParam); @@ -3715,7 +3714,7 @@ int32_t AbilityManagerService::StartExtensionAbilityInner(const Want &want, cons return result; } - AbilityInterceptorParam afterCheckParam = AbilityInterceptorParam(abilityRequest.want, 0, GetUserId(), + AbilityInterceptorParam afterCheckParam = AbilityInterceptorParam(abilityRequest.want, 0, GetCallerUserId(), false, callerToken, std::make_shared(abilityInfo), false, appIndex); result = afterCheckExecuter_ == nullptr ? ERR_INVALID_VALUE : afterCheckExecuter_->DoProcess(afterCheckParam); @@ -3980,7 +3979,7 @@ int AbilityManagerService::StartUIExtensionAbility(const sptr &exte StartAbilityInfoWrap threadLocalInfo; auto shouldBlockFunc = [aams = shared_from_this()]() { return aams->ShouldBlockAllAppStart(); }; - AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(extensionSessionInfo->want, 0, GetUserId(), + AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(extensionSessionInfo->want, 0, GetCallerUserId(), true, nullptr, shouldBlockFunc); auto result = interceptorExecuter_ == nullptr ? ERR_INVALID_VALUE : interceptorExecuter_->DoProcess(interceptorParam); @@ -4051,7 +4050,7 @@ int AbilityManagerService::StartUIExtensionAbility(const sptr &exte return result; } - AbilityInterceptorParam afterCheckParam = AbilityInterceptorParam(abilityRequest.want, 0, GetUserId(), + AbilityInterceptorParam afterCheckParam = AbilityInterceptorParam(abilityRequest.want, 0, GetCallerUserId(), true, callerToken, std::make_shared(abilityInfo)); result = afterCheckExecuter_ == nullptr ? ERR_INVALID_VALUE : afterCheckExecuter_->DoProcess(afterCheckParam); @@ -4177,7 +4176,7 @@ void AbilityManagerService::StopSwitchUserDialog() return; } - if (userController_ == nullptr || userController_->GetFreezingNewUserId() == DEFAULT_INVAL_VALUE) { + if (UserController::GetInstance().GetFreezingNewUserId() == DEFAULT_INVAL_VALUE) { TAG_LOGE(AAFwkTag::ABILITYMGR, "get last userId error"); return; } @@ -4188,9 +4187,9 @@ void AbilityManagerService::StopSwitchUserDialog() return; } Want stopWant = sysDialog->GetSwitchUserDialogWant(); - StopSwitchUserDialogInner(stopWant, userController_->GetFreezingNewUserId()); + StopSwitchUserDialogInner(stopWant, UserController::GetInstance().GetFreezingNewUserId()); #endif // SUPPORT_GRAPHICS - userController_->SetFreezingNewUserId(DEFAULT_INVAL_VALUE); + UserController::GetInstance().SetFreezingNewUserId(DEFAULT_INVAL_VALUE); return; } @@ -4903,7 +4902,7 @@ int32_t AbilityManagerService::ConnectAbilityCommon( #endif // WITH_DLP auto shouldBlockFunc = [aams = shared_from_this()]() { return aams->ShouldBlockAllAppStart(); }; - AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(want, 0, GetUserId(), false, nullptr, + AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(want, 0, GetCallerUserId(), false, nullptr, shouldBlockFunc); result = interceptorExecuter_ == nullptr ? ERR_INVALID_VALUE : interceptorExecuter_->DoProcess(interceptorParam); @@ -5058,7 +5057,7 @@ int AbilityManagerService::ConnectUIExtensionAbility(const Want &want, const spt #endif // WITH_DLP auto shouldBlockFunc = [aams = shared_from_this()]() { return aams->ShouldBlockAllAppStart(); }; - AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(want, 0, GetUserId(), false, nullptr, + AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(want, 0, GetCallerUserId(), false, nullptr, shouldBlockFunc); result = interceptorExecuter_ == nullptr ? ERR_INVALID_VALUE : interceptorExecuter_->DoProcess(interceptorParam); @@ -5271,7 +5270,7 @@ int32_t AbilityManagerService::ConnectLocalAbility(const Want &want, const int32 return result; } - AbilityInterceptorParam afterCheckParam = AbilityInterceptorParam(abilityRequest.want, 0, GetUserId(), + AbilityInterceptorParam afterCheckParam = AbilityInterceptorParam(abilityRequest.want, 0, GetCallerUserId(), false, callerToken, std::make_shared(abilityInfo)); result = afterCheckExecuter_ == nullptr ? ERR_INVALID_VALUE : afterCheckExecuter_->DoProcess(afterCheckParam); @@ -6435,7 +6434,7 @@ void AbilityManagerService::DumpSysMissionListInnerBySCB( const std::string &args, std::vector &info, bool isClient, bool isUserID, int userId) { if (!isUserID) { - userId = GetUserId(); + userId = GetCallerUserId(); } std::vector argList; @@ -6500,7 +6499,7 @@ void AbilityManagerService::DumpSysAbilityInnerBySCB( const std::string &args, std::vector &info, bool isClient, bool isUserID, int userId) { if (!isUserID) { - userId = GetUserId(); + userId = GetCallerUserId(); } std::vector argList; @@ -7231,18 +7230,9 @@ std::shared_ptr AbilityManagerService::GetEventHandler() return eventHandler_; } -// multi user scene -int32_t AbilityManagerService::GetUserId() const -{ - if (userController_) { - auto userId = userController_->GetCurrentUserId(); - TAG_LOGD(AAFwkTag::ABILITYMGR, "userId is %{public}d", userId); - return userId; - } - return U0_USER_ID; -} #ifndef DISABLE_LAUNCHER -int AbilityManagerService::StartHighestPriorityAbility(int32_t userId, bool isBoot, bool isAppRecovery) +int AbilityManagerService::StartHighestPriorityAbility(int32_t userId, uint64_t displayId, bool isBoot, + bool isAppRecovery) { TAG_LOGD(AAFwkTag::ABILITYMGR, "%{public}s", __func__); auto bms = AbilityUtil::GetBundleManagerHelper(); @@ -7299,6 +7289,7 @@ int AbilityManagerService::StartHighestPriorityAbility(int32_t userId, bool isBo #ifdef SUPPORT_GRAPHICS abilityWant.SetParam(NEED_STARTINGWINDOW, false); + abilityWant.SetParam(Want::PARAM_RESV_DISPLAY_ID, static_cast(displayId)); // wait BOOT_ANIMATION_STARTED to start LAUNCHER WaitBootAnimationStart(); #endif @@ -7563,14 +7554,14 @@ void AbilityManagerService::OnAbilityDied(std::shared_ptr ability auto manager = GetMissionListManagerByUserId(abilityRecord->GetOwnerMissionUserId()); if (manager && abilityRecord->GetAbilityInfo().type == AbilityType::PAGE) { ReleaseAbilityTokenMap(abilityRecord->GetToken()); - manager->OnAbilityDied(abilityRecord, GetUserId()); + manager->OnAbilityDied(abilityRecord, abilityRecord->GetOwnerMissionUserId()); return; } } auto connectManager = GetConnectManagerByToken(abilityRecord->GetToken()); if (connectManager) { - connectManager->OnAbilityDied(abilityRecord, GetUserId()); + connectManager->OnAbilityDied(abilityRecord, abilityRecord->GetOwnerMissionUserId()); return; } else { TAG_LOGW(AAFwkTag::ABILITYMGR, "connectManager not found"); @@ -7614,7 +7605,7 @@ int AbilityManagerService::KillProcess(const std::string &bundleName, bool clear bundleName.c_str(), clearPageStack); auto bms = AbilityUtil::GetBundleManagerHelper(); CHECK_POINTER_AND_RETURN(bms, KILL_PROCESS_FAILED); - int32_t userId = GetUserId(); + int32_t userId = GetCallerUserId(); AppExecFwk::BundleInfo bundleInfo; if (IN_PROCESS_CALL(bms->GetCloneBundleInfoExt(bundleName, static_cast(AppExecFwk::GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_APPLICATION), @@ -8169,7 +8160,7 @@ void AbilityManagerService::StartAutoStartupApps() } std::vector infoList; int32_t result = abilityAutoStartupService_->QueryAllAutoStartupApplicationsWithoutPermission(infoList, - GetUserId()); + GetCallerUserId()); if (result != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITYMGR, "failed query data"); return; @@ -8555,7 +8546,7 @@ int AbilityManagerService::StartAbilityByCallWithErrMsg(const Want &want, const return ERR_APP_CLONE_INDEX_INVALID; } auto checkRet = AbilityPermissionUtil::GetInstance().CheckMultiInstanceAndAppClone(const_cast(want), - GetUserId(), appIndex, callerToken, false); + GetCallerUserId(), appIndex, callerToken, false); if (checkRet != ERR_OK) { return checkRet; } @@ -8564,10 +8555,10 @@ int AbilityManagerService::StartAbilityByCallWithErrMsg(const Want &want, const DmsUtil::GetInstance().UpdateFlagForCollaboration(want); #endif - StartAbilityInfoWrap threadLocalInfo(want, GetUserId(), appIndex, callerToken); + StartAbilityInfoWrap threadLocalInfo(want, GetCallerUserId(), appIndex, callerToken); auto shouldBlockFunc = [aams = shared_from_this()]() { return aams->ShouldBlockAllAppStart(); }; isSilent = want.GetBoolParam(Want::PARAM_RESV_CALL_TO_FOREGROUND, false) ? true : !isSilent; - AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(want, 0, GetUserId(), isSilent, nullptr, + AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(want, 0, GetCallerUserId(), isSilent, nullptr, shouldBlockFunc); auto result = interceptorExecuter_ == nullptr ? ERR_INVALID_VALUE : interceptorExecuter_->DoProcess(interceptorParam); @@ -8596,7 +8587,7 @@ int AbilityManagerService::StartAbilityByCallWithErrMsg(const Want &want, const abilityRequest.callerToken = callerToken; abilityRequest.want = want; abilityRequest.connect = connect; - result = GenerateAbilityRequest(want, -1, abilityRequest, callerToken, GetUserId()); + result = GenerateAbilityRequest(want, -1, abilityRequest, callerToken, GetCallerUserId()); if (result != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITYMGR, "generate ability request error"); return result; @@ -8620,7 +8611,7 @@ int AbilityManagerService::StartAbilityByCallWithErrMsg(const Want &want, const TAG_LOGD(AAFwkTag::ABILITYMGR, "abilityInfo.applicationInfo.singleton is %{public}s", abilityRequest.abilityInfo.applicationInfo.singleton ? "true" : "false"); UpdateCallerInfoUtil::GetInstance().UpdateCallerInfo(abilityRequest.want, callerToken); - AbilityInterceptorParam afterCheckParam = AbilityInterceptorParam(abilityRequest.want, 0, GetUserId(), + AbilityInterceptorParam afterCheckParam = AbilityInterceptorParam(abilityRequest.want, 0, GetCallerUserId(), false, callerToken, std::make_shared(abilityRequest.abilityInfo), false, appIndex); result = afterCheckExecuter_ == nullptr ? ERR_INVALID_VALUE : afterCheckExecuter_->DoProcess(afterCheckParam); @@ -8721,9 +8712,9 @@ int AbilityManagerService::JudgeAbilityVisibleControl(const AppExecFwk::AbilityI return ABILITY_VISIBLE_FALSE_DENY_REQUEST; } -int AbilityManagerService::StartUser(int userId, sptr callback, bool isAppRecovery) +int AbilityManagerService::StartUser(int userId, uint64_t displayId, sptr callback, bool isAppRecovery) { - TAG_LOGI(AAFwkTag::ABILITYMGR, "startUser in service:%{public}d", userId); + TAG_LOGI(AAFwkTag::ABILITYMGR, "startUser in service:%{public}d, displayId:%{public}" PRIu64"", userId, displayId); if (callback == nullptr) { TAG_LOGE(AAFwkTag::ABILITYMGR, "startUser callback is nullptr"); return INVALID_PARAMETERS_ERR; @@ -8740,10 +8731,7 @@ int AbilityManagerService::StartUser(int userId, sptr callback, b return ERR_ALL_APP_START_BLOCKED; } - if (userController_) { - return userController_->StartUser(userId, callback, isAppRecovery); - } - return 0; + return UserController::GetInstance().StartUser(userId, displayId, callback, isAppRecovery); } int AbilityManagerService::StopUser(int userId, const sptr &callback) @@ -8758,11 +8746,8 @@ int AbilityManagerService::StopUser(int userId, const sptr &callb return CHECK_PERMISSION_FAILED; } - auto ret = -1; - if (userController_) { - ret = userController_->StopUser(userId); - TAG_LOGD(AAFwkTag::ABILITYMGR, "ret = %{public}d", ret); - } + auto ret = UserController::GetInstance().StopUser(userId); + TAG_LOGD(AAFwkTag::ABILITYMGR, "ret = %{public}d", ret); if (callback) { callback->OnStopUserDone(userId, ret); } @@ -8804,12 +8789,9 @@ int AbilityManagerService::LogoutUser(int32_t userId, sptr callba SubscribeScreenUnlockedEvent(); } - if (userController_) { - auto ret = userController_->LogoutUser(userId, callback); - TAG_LOGD(AAFwkTag::ABILITYMGR, "logout user return = %{public}d", ret); - return ret; - } - return ERR_OK; + auto ret = UserController::GetInstance().LogoutUser(userId, callback); + TAG_LOGD(AAFwkTag::ABILITYMGR, "logout user return = %{public}d", ret); + return ret; } void AbilityManagerService::OnAcceptWantResponse( @@ -8952,7 +8934,7 @@ int AbilityManagerService::GetExtensionRunningInfos(int upperLimit, std::vector< auto isPerm = AAFwk::PermissionVerification::GetInstance()->VerifyRunningInfoPerm(); auto connectManager = GetCurrentConnectManager(); CHECK_POINTER_AND_RETURN(connectManager, ERR_INVALID_VALUE); - connectManager->GetExtensionRunningInfos(upperLimit, info, GetUserId(), isPerm); + connectManager->GetExtensionRunningInfos(upperLimit, info, GetCallerUserId(), isPerm); return ERR_OK; } @@ -9270,7 +9252,7 @@ void AbilityManagerService::ScheduleRecoverAbility(const sptr& to CHECK_POINTER_IS_NULLPTR(bms); AppExecFwk::BundleInfo bundleInfo; auto bundleName = want->GetElement().GetBundleName(); - int32_t userId = GetUserId(); + int32_t userId = GetCallerUserId(); bool ret = IN_PROCESS_CALL( bms->GetBundleInfo(bundleName, AppExecFwk::BundleFlag::GET_BUNDLE_WITH_ABILITIES, bundleInfo, userId)); @@ -9328,10 +9310,6 @@ void AbilityManagerService::StartSwitchUserDialog() return; } - if (userController_ == nullptr) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "user Controller instance null"); - return; - } #ifdef SUPPORT_GRAPHICS auto sysDialog = DelayedSingleton::GetInstance(); if (sysDialog == nullptr) { @@ -9340,7 +9318,7 @@ void AbilityManagerService::StartSwitchUserDialog() } Want dialogWant = sysDialog->GetSwitchUserDialogWant(); - StartSwitchUserDialogInner(dialogWant, userController_->GetFreezingNewUserId()); + StartSwitchUserDialogInner(dialogWant, UserController::GetInstance().GetFreezingNewUserId()); #endif // SUPPORT_GRAPHICS } @@ -9416,8 +9394,8 @@ void AbilityManagerService::UserStarted(int32_t userId) subManagersHelper_->InitSubManagers(userId, false); } -int AbilityManagerService::SwitchToUser(int32_t oldUserId, int32_t userId, sptr callback, - bool isAppRecovery) +int AbilityManagerService::SwitchToUser(int32_t oldUserId, int32_t userId, uint64_t displayId, + sptr callback, bool isAppRecovery) { TAG_LOGI(AAFwkTag::ABILITYMGR, "%{public}s, oldUserId:%{public}d, newUserId:%{public}d, isAppRecovery:%{public}d", __func__, @@ -9430,7 +9408,7 @@ int AbilityManagerService::SwitchToUser(int32_t oldUserId, int32_t userId, sptr< } #ifndef DISABLE_LAUNCHER bool isBoot = oldUserId == U0_USER_ID ? true : false; - auto ret = StartHighestPriorityAbility(userId, isBoot, isAppRecovery); + auto ret = StartHighestPriorityAbility(userId, displayId, isBoot, isAppRecovery); if (ret != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITYMGR, "StartHighestPriorityAbility failed: %{public}d", ret); } @@ -9458,9 +9436,6 @@ int AbilityManagerService::SwitchToUser(int32_t oldUserId, int32_t userId, sptr< bool AbilityManagerService::IsSceneBoardReady(int32_t userId) { - if (userId < 0) { - userId = GetUserId(); - } auto connectManager = GetConnectManagerByUserId(userId); if (connectManager == nullptr) { TAG_LOGE(AAFwkTag::ABILITYMGR, "connectManager is nullptr"); @@ -9546,7 +9521,7 @@ int32_t AbilityManagerService::GetValidUserId(const int32_t userId) TAG_LOGD(AAFwkTag::ABILITYMGR, "validUserId = %{public}d, CallingUid = %{public}d.", validUserId, IPCSkeleton::GetCallingUid()); if (validUserId == U0_USER_ID || validUserId == U1_USER_ID) { - validUserId = GetUserId(); + validUserId = GetCallerUserId(); } } return validUserId; @@ -9646,7 +9621,7 @@ int AbilityManagerService::StartUserTest(const Want &want, const sptrGetBundleInfo(bundleName, AppExecFwk::BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo, U0_USER_ID))) { TAG_LOGE(AAFwkTag::ABILITYMGR, "failed get bundleInfo by U0_USER_ID %{public}d", U0_USER_ID); - int32_t userId = GetUserId(); + int32_t userId = GetCallerUserId(); TAG_LOGD(AAFwkTag::ABILITYMGR, "bundleName: %{public}s, userId: %{public}d", bundleName.c_str(), userId); if (!IN_PROCESS_CALL( bms->GetBundleInfo(bundleName, AppExecFwk::BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo, userId))) { @@ -9661,7 +9636,7 @@ int AbilityManagerService::StartUserTest(const Want &want, const sptr::GetInstance()->StartUserTest(want, observer, bundleInfo, GetUserId()); + return DelayedSingleton::GetInstance()->StartUserTest(want, observer, bundleInfo, GetCallerUserId()); } int AbilityManagerService::FinishUserTest( @@ -9819,7 +9794,7 @@ int AbilityManagerService::DelegatorMoveMissionToFront(int32_t missionId) return missionListManager->MoveMissionToFront(missionId); } -bool AbilityManagerService::JudgeMultiUserConcurrency(const int32_t userId) +bool AbilityManagerService::JudgeMultiUserConcurrency(int32_t userId) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); if (userId == U0_USER_ID || userId == U1_USER_ID) { @@ -9827,15 +9802,11 @@ bool AbilityManagerService::JudgeMultiUserConcurrency(const int32_t userId) return true; } - TAG_LOGD(AAFwkTag::ABILITYMGR, "userId : %{public}d, current userId : %{public}d", userId, GetUserId()); - - // Only non-concurrent mode is supported - bool concurrencyMode = CONCURRENCY_MODE_FALSE; - if (!concurrencyMode) { - return (userId == GetUserId()); + TAG_LOGD(AAFwkTag::ABILITYMGR, "userId : %{public}d, current userId : %{public}d", userId, GetCallerUserId()); + if (userId == GetCallerUserId()) { + return true; } - - return true; + return AAFwk::PermissionVerification::GetInstance()->VerifyAccountPermission() == ERR_OK; } void AbilityManagerService::SendExtensionReport(EventInfo &eventInfo, int32_t errCode, bool isService) @@ -10114,7 +10085,7 @@ void AbilityManagerService::GetAbilityRunningInfo(std::vectorGetCurrentUserId() == userId))) { + if (userId < 0 || GetCallerUserId() == userId) { return ERR_OK; } return AAFwk::PermissionVerification::GetInstance()->VerifyAccountPermission(); @@ -11588,7 +11559,7 @@ int AbilityManagerService::VerifyPermission(const std::string &permission, int p return CHECK_PERMISSION_FAILED; } - int32_t userId = GetUserId(); + int32_t userId = GetCallerUserId(); AppExecFwk::BundleInfo bundleInfo; bool queryBundleInfoRet = IN_PROCESS_CALL( bms->GetBundleInfo(callerBundleName, AppExecFwk::BundleFlag::GET_BUNDLE_WITH_ABILITIES, bundleInfo, userId)); @@ -11755,13 +11726,13 @@ int32_t AbilityManagerService::StartSpecifiedAbilityBySCB(const Want &want) return ERR_APP_CLONE_INDEX_INVALID; } auto result = AbilityPermissionUtil::GetInstance().CheckMultiInstanceAndAppClone(const_cast(want), - GetUserId(), appIndex, nullptr, true); + GetCallerUserId(), appIndex, nullptr, true); if (result != ERR_OK) { return result; } AbilityRequest abilityRequest; - result = GenerateAbilityRequest(want, -1, abilityRequest, want.GetRemoteObject(TOKEN_KEY), GetUserId()); + result = GenerateAbilityRequest(want, -1, abilityRequest, want.GetRemoteObject(TOKEN_KEY), GetCallerUserId()); if (result != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITYMGR, "generate ability request error"); return result; @@ -12030,7 +12001,7 @@ int32_t AbilityManagerService::QueryAllAutoStartupApplications(std::vectorQueryAllAutoStartupApplications(infoList, GetUserId()); + return abilityAutoStartupService_->QueryAllAutoStartupApplications(infoList, GetCallerUserId()); } int AbilityManagerService::PrepareTerminateAbilityBySCB(const sptr &sessionInfo, bool &isTerminate) @@ -12285,7 +12256,7 @@ int32_t AbilityManagerService::ExecuteIntent(uint64_t key, const sptr(AppExecFwk::AbilityType::PAGE); abilityData.appCloneIndex = info.appCloneIndex; AppExecFwk::ApplicationInfo appInfo; - if (!StartAbilityUtils::GetApplicationInfo(abilityData.bundleName, GetUserId(), appInfo)) { + if (!StartAbilityUtils::GetApplicationInfo(abilityData.bundleName, GetCallerUserId(), appInfo)) { TAG_LOGE(AAFwkTag::ABILITYMGR, "can't get applicationInfo through bundleName"); } else if (appInfo.bundleType == AppExecFwk::BundleType::ATOMIC_SERVICE) { abilityData.isAtomicService = true; @@ -12557,19 +12528,15 @@ void AbilityManagerService::NotifyConfigurationChange(const AppExecFwk::Configur void AbilityManagerService::NotifyStartResidentProcess(std::vector &bundleInfos) { - if (userController_ == nullptr) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "userController_ null"); - return; - } - auto currentUser = userController_->GetCurrentUserId(); + int32_t callerUser = GetCallerUserId(); std::vector bundleInfosForU0; - std::vector bundleInfosForCurrentUser; + std::vector bundleInfosForcallerUser; for (const auto &item: bundleInfos) { auto user = item.uid / BASE_USER_RANGE; if (user == U0_USER_ID) { bundleInfosForU0.push_back(item); - } else if (user == currentUser) { - bundleInfosForCurrentUser.push_back(item); + } else if (user == callerUser) { + bundleInfosForcallerUser.push_back(item); } } @@ -12583,9 +12550,9 @@ void AbilityManagerService::NotifyStartResidentProcess(std::vectorStartResidentProcessWithMainElement( - bundleInfosForCurrentUser, currentUser); - if (!bundleInfosForCurrentUser.empty()) { - residentProcessMgr->StartResidentProcess(bundleInfosForCurrentUser); + bundleInfosForcallerUser, callerUser); + if (!bundleInfosForcallerUser.empty()) { + residentProcessMgr->StartResidentProcess(bundleInfosForcallerUser); } } @@ -12595,7 +12562,7 @@ void AbilityManagerService::NotifyStartKeepAliveProcess(std::vector bundleInfosForCurrentUser; std::vector bundleInfosForU1; for (const auto &item: bundleInfos) { @@ -12800,7 +12767,7 @@ bool AbilityManagerService::VerifySameAppOrAppIdentifierAllowListPermission(cons auto bms = AbilityUtil::GetBundleManagerHelper(); CHECK_POINTER_AND_RETURN(bms, false); AppExecFwk::BundleInfo targetBundleInfo; - int32_t userId = GetUserId(); + int32_t userId = GetCallerUserId(); std::string callerAppIdentifier = abilityRequest.want.GetStringParam(Want::PARAM_RESV_CALLER_APP_IDENTIFIER); if (callerAppIdentifier.empty()) { AppExecFwk::SignatureInfo signatureInfo; @@ -12838,7 +12805,7 @@ bool AbilityManagerService::VerifySameAppOrAppIdentifierAllowListPermission(cons void AbilityManagerService::CloseAssertDialog(const std::string &assertSessionId) { TAG_LOGD(AAFwkTag::ABILITYMGR, "Close assert fault dialog begin."); - auto validUserId = GetUserId(); + auto validUserId = GetCallerUserId(); auto connectManager = GetConnectManagerByUserId(validUserId); if (connectManager == nullptr) { TAG_LOGE(AAFwkTag::ABILITYMGR, "manager null, userId: %{public}d", validUserId); @@ -13243,14 +13210,14 @@ bool AbilityManagerService::IsEmbeddedOpenAllowed(sptr callerToke want.SetBundle(bundleName); want.SetParam("send_to_erms_embedded", 1); UpdateCallerInfoUtil::GetInstance().UpdateCallerInfo(want, callerToken); - int32_t ret = freeInstallManager_->StartFreeInstall(want, GetUserId(), 0, callerToken); + int32_t ret = freeInstallManager_->StartFreeInstall(want, GetCallerUserId(), 0, callerToken); if (ret != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITYMGR, "target not allowed free install"); return false; } want.SetParam(Want::PARAM_RESV_CALLER_BUNDLE_NAME, callerAbility->GetElementName().GetBundleName()); auto erms = std::make_shared(); - return erms->DoProcess(want, GetUserId()); + return erms->DoProcess(want, GetCallerUserId()); } int32_t AbilityManagerService::AddQueryERMSObserver(sptr callerToken, @@ -13286,7 +13253,7 @@ int32_t AbilityManagerService::QueryAtomicServiceStartupRule(sptr want.SetBundle(ATOMIC_SERVICE_PREFIX + appId); want.SetParam("send_to_erms_embedded", 1); UpdateCallerInfoUtil::GetInstance().UpdateCallerInfo(want, callerToken); - auto userId = GetUserId(); + auto userId = GetCallerUserId(); int32_t ret = freeInstallManager_->StartFreeInstall(want, userId, 0, callerToken); if (ret != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITYMGR, "free install failed:%{public}d", ret); @@ -13298,7 +13265,7 @@ int32_t AbilityManagerService::QueryAtomicServiceStartupRule(sptr want.SetParam(Want::PARAM_RESV_CALLER_BUNDLE_NAME, callerAbility->GetElementName().GetBundleName()); auto erms = std::make_shared(); sptr replaceWant = nullptr; - ret = erms->QueryAtomicServiceStartupRule(want, callerToken, GetUserId(), rule, replaceWant); + ret = erms->QueryAtomicServiceStartupRule(want, callerToken, GetCallerUserId(), rule, replaceWant); if (ret == ERR_OK) { TAG_LOGI(AAFwkTag::ABILITYMGR, "QueryAtomicServiceStartupRule succeeded"); return ERR_OK; @@ -13883,7 +13850,7 @@ int AbilityManagerService::StartUIAbilityByPreInstallInner(sptr ses } StartAbilityInfoWrap threadLocalInfo(want, validUserId, appIndex, callerToken); auto shouldBlockFunc = [aams = shared_from_this()]() { return aams->ShouldBlockAllAppStart(); }; - AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(want, requestCode, GetUserId(), + AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(want, requestCode, GetCallerUserId(), true, nullptr, shouldBlockFunc); auto result = interceptorExecuter_ == nullptr ? ERR_INVALID_VALUE : interceptorExecuter_->DoProcess(interceptorParam); @@ -13939,7 +13906,7 @@ int AbilityManagerService::StartUIAbilityByPreInstallInner(sptr ses } Want newWant = abilityRequest.want; - AbilityInterceptorParam afterCheckParam = AbilityInterceptorParam(newWant, requestCode, GetUserId(), + AbilityInterceptorParam afterCheckParam = AbilityInterceptorParam(newWant, requestCode, GetCallerUserId(), true, callerToken, std::make_shared(abilityInfo), isStartAsCaller, appIndex); result = afterCheckExecuter_ == nullptr ? ERR_INVALID_VALUE : afterCheckExecuter_->DoProcess(afterCheckParam); @@ -13951,12 +13918,12 @@ int AbilityManagerService::StartUIAbilityByPreInstallInner(sptr ses } #ifdef SUPPORT_SCREEN if (result != ERR_OK && isReplaceWantExist && callerBundleName != BUNDLE_NAME_DIALOG) { - return DialogSessionManager::GetInstance().HandleErmsResult(abilityRequest, GetUserId(), newWant); + return DialogSessionManager::GetInstance().HandleErmsResult(abilityRequest, GetCallerUserId(), newWant); } if (result == ERR_OK && - DialogSessionManager::GetInstance().IsCreateCloneSelectorDialog(abilityInfo.bundleName, GetUserId())) { + DialogSessionManager::GetInstance().IsCreateCloneSelectorDialog(abilityInfo.bundleName, GetCallerUserId())) { TAG_LOGI(AAFwkTag::ABILITYMGR, "create clone selector dialog"); - return CreateCloneSelectorDialog(abilityRequest, GetUserId()); + return CreateCloneSelectorDialog(abilityRequest, GetCallerUserId()); } #endif // SUPPORT_SCREEN @@ -14506,7 +14473,7 @@ int AbilityManagerService::StartSelfUIAbilityInner(StartSelfUIAbilityParam param AppExecFwk::AbilityInfo abilityInfo; CHECK_TRUE_RETURN_RET(!IN_PROCESS_CALL(bundleMgrHelper->QueryAbilityInfo(param.want, - AppExecFwk::AbilityInfoFlag::GET_ABILITY_INFO_WITH_APPLICATION, GetUserId(), abilityInfo)), + AppExecFwk::AbilityInfoFlag::GET_ABILITY_INFO_WITH_APPLICATION, GetCallerUserId(), abilityInfo)), ERR_NOT_ALLOW_IMPLICIT_START, "bundle or ability not exist"); CHECK_TRUE_RETURN_RET(abilityInfo.type != AppExecFwk::AbilityType::PAGE, @@ -14901,7 +14868,17 @@ int32_t AbilityManagerService::GetInsightIntentInfoByIntentName( bool AbilityManagerService::IsCrossUserCall(int32_t userId) const { - return userId != INVALID_USER_ID && userId != U0_USER_ID && userId != U1_USER_ID && userId != GetUserId(); + return userId != INVALID_USER_ID && userId != U0_USER_ID && userId != U1_USER_ID && userId != GetCallerUserId(); +} + +int32_t AbilityManagerService::GetCallerUserId() const +{ + int32_t callerUid = IPCSkeleton::GetCallingUid(); + int32_t callerUser = callerUid / BASE_USER_RANGE; + if (callerUser == U0_USER_ID || callerUser == U1_USER_ID) { + callerUser = UserController::GetInstance().GetCurrentUserId(DisplayUtil::ObtainDefaultDisplayId()); + } + return callerUser; } int32_t AbilityManagerService::RestartSelfAtomicService(sptr callerToken) @@ -15030,7 +15007,7 @@ bool AbilityManagerService::HandleExecuteSAInterceptor(const Want &want, sptr callback = nullptr; if (data.ReadBool()) { callback = iface_cast(data.ReadRemoteObject()); @@ -2551,7 +2552,7 @@ int AbilityManagerStub::StartUserInner(MessageParcel &data, MessageParcel &reply return ERR_INVALID_VALUE; } bool isAppRecovery = data.ReadBool(); - int result = StartUser(userId, callback, isAppRecovery); + int result = StartUser(userId, displayId, callback, isAppRecovery); if (!reply.WriteInt32(result)) { TAG_LOGE(AAFwkTag::ABILITYMGR, "startUser fail"); return ERR_INVALID_VALUE; diff --git a/services/abilitymgr/src/keep_alive/ability_keep_alive_service.cpp b/services/abilitymgr/src/keep_alive/ability_keep_alive_service.cpp index 0d7afe01f05..d1a4aef58b4 100644 --- a/services/abilitymgr/src/keep_alive/ability_keep_alive_service.cpp +++ b/services/abilitymgr/src/keep_alive/ability_keep_alive_service.cpp @@ -111,7 +111,7 @@ void AbilityKeepAliveService::GetValidUserId(int32_t &userId) } if (userId < 0) { - userId = abilityMgr->GetUserId(); + userId = abilityMgr->GetCallerUserId(); } } diff --git a/services/abilitymgr/src/keep_alive/keep_alive_process_manager.cpp b/services/abilitymgr/src/keep_alive/keep_alive_process_manager.cpp index f2bdcf33980..3c16d59d743 100644 --- a/services/abilitymgr/src/keep_alive/keep_alive_process_manager.cpp +++ b/services/abilitymgr/src/keep_alive/keep_alive_process_manager.cpp @@ -219,7 +219,7 @@ int32_t KeepAliveProcessManager::SetApplicationKeepAlive(const std::string &bund auto bms = AbilityUtil::GetBundleManagerHelper(); CHECK_POINTER_AND_RETURN(bms, INNER_ERR); - userId = userId < 0 ? DelayedSingleton::GetInstance()->GetUserId() : userId; + userId = userId < 0 ? DelayedSingleton::GetInstance()->GetCallerUserId() : userId; AppExecFwk::BundleInfo bundleInfo; if (!IN_PROCESS_CALL(bms->GetBundleInfo( bundleName, AppExecFwk::BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo, userId))) { diff --git a/services/abilitymgr/src/resident_process/resident_process_manager.cpp b/services/abilitymgr/src/resident_process/resident_process_manager.cpp index a6f77c07a11..f61df71d246 100644 --- a/services/abilitymgr/src/resident_process/resident_process_manager.cpp +++ b/services/abilitymgr/src/resident_process/resident_process_manager.cpp @@ -211,7 +211,7 @@ void ResidentProcessManager::UpdateResidentProcessesStatus( } AppExecFwk::BundleInfo bundleInfo; - auto currentUser = DelayedSingleton::GetInstance()->GetUserId(); + auto currentUser = DelayedSingleton::GetInstance()->GetCallerUserId(); std::set users{0, currentUser}; for (const auto &userId: users) { diff --git a/services/abilitymgr/src/user_controller.cpp b/services/abilitymgr/src/user_controller.cpp index c1b8408e95a..ed34822b560 100644 --- a/services/abilitymgr/src/user_controller.cpp +++ b/services/abilitymgr/src/user_controller.cpp @@ -20,6 +20,7 @@ #include "mock_session_manager_service.h" #include "os_account_manager_wrapper.h" #include "scene_board_judgement.h" +#include "user_controller/user_manager.h" namespace OHOS { namespace AAFwk { @@ -53,12 +54,10 @@ UserState UserItem::GetState() return curState_; } -UserController::UserController() -{ -} - -UserController::~UserController() +UserController& UserController::GetInstance() { + static UserController instance; + return instance; } void UserController::Init() @@ -71,18 +70,19 @@ void UserController::Init() if (eventHandler_) { return; } - eventHandler_ = std::make_shared(handler, shared_from_this()); + eventHandler_ = std::make_shared(handler); } void UserController::ClearAbilityUserItems(int32_t userId) { + AbilityRuntime::UserManager::GetInstance().ClearUserId(userId); std::lock_guard guard(userLock_); if (userItems_.count(userId)) { userItems_.erase(userId); } } -int UserController::StartUser(int32_t userId, sptr callback, bool isAppRecovery) +int UserController::StartUser(int32_t userId, uint64_t displayId, sptr callback, bool isAppRecovery) { if (userId == U1_USER_ID) { return StartNoHeadUser(userId, callback); @@ -96,7 +96,7 @@ int UserController::StartUser(int32_t userId, sptr callback, bool return INVALID_USERID_VALUE; } - if (IsCurrentUser(userId)) { + if (IsCurrentUser(userId, displayId)) { TAG_LOGW(AAFwkTag::ABILITYMGR, "StartUser current:%{public}d", userId); if (callback != nullptr) { callback->OnStartUserDone(userId, ERR_OK); @@ -119,13 +119,13 @@ int UserController::StartUser(int32_t userId, sptr callback, bool return INVALID_USERID_VALUE; } - if (GetCurrentUserId() != USER_ID_NO_HEAD && !Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { + auto oldUserId = GetCurrentUserId(displayId); + if (oldUserId != USER_ID_NO_HEAD && !Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { // start freezing screen SetFreezingNewUserId(userId); DelayedSingleton::GetInstance()->StartFreezingScreen(); } - auto oldUserId = GetCurrentUserId(); auto userItem = GetOrCreateUserItem(userId); auto state = userItem->GetState(); if (state == STATE_STOPPING || state == STATE_SHUTDOWN) { @@ -136,7 +136,7 @@ int UserController::StartUser(int32_t userId, sptr callback, bool return ERR_DEAD_OBJECT; } - SetCurrentUserId(userId); + SetCurrentUserId(userId, displayId); if (state == STATE_BOOTING) { // send user start msg. SendSystemUserStart(userId); @@ -145,7 +145,7 @@ int UserController::StartUser(int32_t userId, sptr callback, bool SendSystemUserCurrent(oldUserId, userId); SendReportUserSwitch(oldUserId, userId, userItem); SendUserSwitchTimeout(oldUserId, userId, userItem); - return MoveUserToForeground(oldUserId, userId, callback, isAppRecovery); + return MoveUserToForeground(oldUserId, userId, displayId, callback, isAppRecovery); } int32_t UserController::StartNoHeadUser(int32_t userId, sptr callback) const @@ -253,44 +253,36 @@ int32_t UserController::LogoutUser(int32_t userId, sptr callback) } abilityManagerService->ClearUserData(userId); appScheduler->SetEnableStartProcessFlagByUserId(userId, false); - if (IsCurrentUser(userId)) { - SetCurrentUserId(0); - } appScheduler->KillProcessesByUserId(userId, system::GetBoolParameter(DEVELOPER_MODE_STATE, false), callback); ClearAbilityUserItems(userId); return 0; } -int32_t UserController::GetCurrentUserId() +int32_t UserController::GetCurrentUserId(uint64_t displayId) { - std::lock_guard guard(userLock_); - return currentUserId_; + return AbilityRuntime::UserManager::GetInstance().GetCurrentUserId(displayId); } -std::shared_ptr UserController::GetUserItem(int32_t userId) +bool UserController::GetDisplayIdByUserId(int32_t userId, uint64_t &displayId) { - std::lock_guard guard(userLock_); - auto it = userItems_.find(userId); - if (it != userItems_.end()) { - return it->second; - } - - return nullptr; + return AbilityRuntime::UserManager::GetInstance().GetDisplayIdByUserId(userId, displayId); } -bool UserController::IsCurrentUser(int32_t userId) +bool UserController::IsCurrentUser(int32_t userId, uint64_t displayId) { - int32_t oldUserId = GetCurrentUserId(); + int32_t oldUserId = GetCurrentUserId(displayId); if (oldUserId == userId) { - auto userItem = GetUserItem(userId); - if (userItem) { - TAG_LOGW(AAFwkTag::ABILITYMGR, "IsCurrentUserId current:%{public}d", userId); - return true; - } + return true; } + TAG_LOGI(AAFwkTag::ABILITYMGR, "current:%{public}d", oldUserId); return false; } +bool UserController::IsCurrentUser(int32_t userId) +{ + return AbilityRuntime::UserManager::GetInstance().IsCurrentUser(userId); +} + bool UserController::IsExistOsAccount(int32_t userId) const { bool isExist = false; @@ -311,22 +303,22 @@ std::shared_ptr UserController::GetOrCreateUserItem(int32_t userId) return userItem; } -void UserController::SetCurrentUserId(int32_t userId) +void UserController::SetCurrentUserId(int32_t userId, uint64_t displayId) { std::lock_guard guard(userLock_); - currentUserId_ = userId; TAG_LOGD(AAFwkTag::ABILITYMGR, "set current userId: %{public}d", userId); - DelayedSingleton::GetInstance()->SetCurrentUserId(userId); + AbilityRuntime::UserManager::GetInstance().SetCurrentUserId(userId, displayId); + DelayedSingleton::GetInstance()->SetCurrentUserId(static_cast(displayId)); } -int UserController::MoveUserToForeground(int32_t oldUserId, int32_t newUserId, sptr callback, - bool isAppRecovery) +int UserController::MoveUserToForeground(int32_t oldUserId, int32_t newUserId, uint64_t displayId, + sptr callback, bool isAppRecovery) { auto manager = DelayedSingleton::GetInstance(); if (!manager) { return ABILITY_SERVICE_NOT_CONNECTED; } - auto ret = manager->SwitchToUser(oldUserId, newUserId, callback, isAppRecovery); + auto ret = manager->SwitchToUser(oldUserId, newUserId, displayId, callback, isAppRecovery); if (ret != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITYMGR, "SwitchToUser failed: %{public}d", ret); } @@ -335,33 +327,6 @@ int UserController::MoveUserToForeground(int32_t oldUserId, int32_t newUserId, s return ret; } -void UserController::UserBootDone(std::shared_ptr &item) -{ - if (!item) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "null item"); - return; - } - int32_t userId = item->GetUserId(); - - std::lock_guard guard(userLock_); - auto it = userItems_.find(userId); - if (it == userItems_.end()) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "invalid userId"); - return; - } - - if (item != it->second) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "invalid item"); - return; - } - item->SetState(UserState::STATE_STARTED); - auto manager = DelayedSingleton::GetInstance(); - if (!manager) { - return; - } - manager->UserStarted(userId); -} - void UserController::BroadcastUserBackground(int32_t userId) { TAG_LOGD(AAFwkTag::ABILITYMGR, "user background"); diff --git a/services/abilitymgr/src/user_event_handler.cpp b/services/abilitymgr/src/user_event_handler.cpp index 416b02f11dd..7ad88450db9 100644 --- a/services/abilitymgr/src/user_event_handler.cpp +++ b/services/abilitymgr/src/user_event_handler.cpp @@ -19,18 +19,14 @@ namespace OHOS { namespace AAFwk { -UserEventHandler::UserEventHandler( - const std::shared_ptr &taskHandler, const std::weak_ptr &owner) - : EventHandlerWrap(taskHandler), controller_(owner) +UserEventHandler::UserEventHandler(const std::shared_ptr &taskHandler) + : EventHandlerWrap(taskHandler) { } void UserEventHandler::ProcessEvent(const EventWrap &event) { - auto owner = controller_.lock(); - if (owner) { - owner->ProcessEvent(event); - } + UserController::GetInstance().ProcessEvent(event); } } // namespace AAFwk } // namespace OHOS diff --git a/services/appmgr/BUILD.gn b/services/appmgr/BUILD.gn index b9d6640df6b..152990173ec 100644 --- a/services/appmgr/BUILD.gn +++ b/services/appmgr/BUILD.gn @@ -117,6 +117,7 @@ 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 = [ @@ -177,6 +178,7 @@ ohos_shared_library("libappms") { deps += [] external_deps += [ "i18n:intl_util", + "window_manager:libdm", "window_manager:libwm", "window_manager:libwsutils", ] diff --git a/services/appmgr/include/app_mgr_service.h b/services/appmgr/include/app_mgr_service.h index 69b3d741fbf..57f9cd50ca4 100644 --- a/services/appmgr/include/app_mgr_service.h +++ b/services/appmgr/include/app_mgr_service.h @@ -174,11 +174,10 @@ public: * * @param bundlename, bundle name in Application record. * @param instanceKeys, output instance keys of the multi-instance app. - * @param userId, user id. * @return ERR_OK ,return back success,others fail. */ virtual int32_t GetAllRunningInstanceKeysByBundleName(const std::string &bundleName, - std::vector &instanceKeys, int32_t userId = -1) override; + std::vector &instanceKeys) override; /** * GetRunningProcessesByBundleType, call GetRunningProcessesByBundleType() through proxy project. diff --git a/services/appmgr/include/app_mgr_service_inner.h b/services/appmgr/include/app_mgr_service_inner.h index 3753aa74533..2eb6b203824 100644 --- a/services/appmgr/include/app_mgr_service_inner.h +++ b/services/appmgr/include/app_mgr_service_inner.h @@ -447,7 +447,7 @@ public: * @return ERR_OK ,return back success,others fail. */ virtual int32_t GetAllRunningInstanceKeysByBundleName(const std::string &bundleName, - std::vector &instanceKeys, int32_t userId = -1); + std::vector &instanceKeys, int32_t userId); /** * GetRunningProcessesByBundleType, Obtains information about application processes by bundle type. @@ -2035,7 +2035,6 @@ private: void SendHiSysEvent(int32_t innerEventId, std::shared_ptr appRecord); int FinishUserTestLocked( const std::string &msg, const int64_t &resultCode, const std::shared_ptr &appRecord); - int32_t GetCurrentAccountId() const; void SendReStartProcessEvent(AAFwk::EventInfo &eventInfo, int32_t appUid); void SendAppLaunchEvent(const std::shared_ptr &appRecord); void InitAppWaitingDebugList(); @@ -2073,8 +2072,6 @@ private: void UnSubscribeScreenOffEvent(); int32_t RestartExitKeepAliveProcess(const std::vector &exitProcessInfos); bool IsNeedRestartKeepAliveProcess(const std::string &bundleName, int32_t uid); - int32_t GetAllRunningInstanceKeysByBundleNameInner(const std::string &bundleName, - std::vector &instanceKeys, int32_t userId); int32_t KillProcessByPidInner(const pid_t pid, const std::string& reason, const std::string& killReason, std::shared_ptr appRecord, bool isKillPrecedeStart); void SetKilledEventInfo(std::shared_ptr appRecord, AAFwk::EventInfo &eventInfo); diff --git a/services/appmgr/src/app_mgr_service.cpp b/services/appmgr/src/app_mgr_service.cpp index 1b907c9f601..e5da0bc34a1 100644 --- a/services/appmgr/src/app_mgr_service.cpp +++ b/services/appmgr/src/app_mgr_service.cpp @@ -26,6 +26,7 @@ #include "app_death_recipient.h" #include "app_mgr_constants.h" #include "datetime_ex.h" +#include "display_util.h" #include "fd_guard.h" #include "freeze_util.h" #include "global_constant.h" @@ -37,6 +38,7 @@ #include "permission_constants.h" #include "permission_verification.h" #include "system_ability_definition.h" +#include "user_controller/user_manager.h" #include "accesstoken_kit.h" #include "app_mgr_service_const.h" #include "app_mgr_service_dump_error_code.h" @@ -414,8 +416,8 @@ int32_t AppMgrService::GetRunningMultiAppInfoByBundleName(const std::string &bun return ERR_INVALID_OPERATION; } - if (!AAFwk::PermissionVerification::GetInstance()->JudgeCallerIsAllowedToUseSystemAPI()) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "caller is not SA"); + if (!AAFwk::PermissionVerification::GetInstance()->IsSystemAppCall()) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "caller is not system app"); return ERR_INVALID_OPERATION; } @@ -436,11 +438,19 @@ int32_t AppMgrService::GetAllRunningInstanceKeysBySelf(std::vector } int32_t AppMgrService::GetAllRunningInstanceKeysByBundleName(const std::string &bundleName, - std::vector &instanceKeys, int32_t userId) + std::vector &instanceKeys) { if (!IsReady()) { return ERR_INVALID_OPERATION; } + bool isCallingPermission = + AAFwk::PermissionVerification::GetInstance()->CheckSpecificSystemAbilityAccessPermission(FOUNDATION_PROCESS); + if (!isCallingPermission) { + TAG_LOGE(AAFwkTag::APPMGR, "verification failed"); + return ERR_PERMISSION_DENIED; + } + int32_t userId = AbilityRuntime::UserManager::GetInstance().GetCurrentUserId( + AAFwk::DisplayUtil::ObtainDefaultDisplayId()); return appMgrServiceInner_->GetAllRunningInstanceKeysByBundleName(bundleName, instanceKeys, userId); } @@ -450,6 +460,10 @@ int32_t AppMgrService::GetRunningProcessesByBundleType(BundleType bundleType, if (!IsReady()) { return ERR_INVALID_OPERATION; } + if (!AAFwk::PermissionVerification::GetInstance()->IsSystemAppCall()) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "caller is not system app"); + return AAFwk::ERR_NOT_SYSTEM_APP; + } return appMgrServiceInner_->GetRunningProcessesByBundleType(bundleType, info); } diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index c5695bf6184..8855d781813 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -46,6 +46,7 @@ #include "common_event_manager.h" #include "common_event_support.h" #include "datetime_ex.h" +#include "display_util.h" #include "distributed_data_mgr.h" #include "extension_ability_info.h" #include "ffrt.h" @@ -106,6 +107,7 @@ #include "cache_process_manager.h" #include "res_sched_util.h" #include "session_manager_lite.h" +#include "user_controller/user_manager.h" #ifdef APP_NO_RESPONSE_DIALOG #include "fault_data.h" #include "modal_system_app_freeze_uiextension.h" @@ -120,6 +122,7 @@ namespace AppExecFwk { #ifdef SUPPORT_SCREEN using namespace OHOS::Rosen; #endif //SUPPORT_SCREEN +using namespace OHOS::AbilityRuntime; using namespace OHOS::Security; using namespace OHOS::Rosen; @@ -284,7 +287,6 @@ constexpr int32_t ROOT_UID = 0; constexpr int32_t FOUNDATION_UID = 5523; constexpr int32_t QUICKFIX_UID = 5524; constexpr int32_t DEFAULT_USER_ID = 0; -constexpr int32_t CURRENT_USER_ID = -1; constexpr int32_t RESOURCE_MANAGER_UID = 1096; constexpr int32_t BLUETOOTH_GROUPID = 1002; @@ -577,8 +579,11 @@ int32_t AppMgrServiceInner::PreloadApplication(const std::string &bundleName, in TAG_LOGE(AAFwkTag::APPMGR, "null appPreloader"); return ERR_INVALID_VALUE; } - if (userId == CURRENT_USER_ID) { - userId = currentUserId_; + if (userId == DEFAULT_INVAL_VALUE) { + userId = GetUserIdByUid(IPCSkeleton::GetCallingUid()); + if (userId == U0_USER_ID || userId == U1_USER_ID) { + userId = UserManager::GetInstance().GetCurrentUserId(AAFwk::DisplayUtil::ObtainDefaultDisplayId()); + } } if (UserRecordManager::GetInstance().IsLogoutUser(userId)) { TAG_LOGE(AAFwkTag::APPMGR, "disable start process in logout user"); @@ -2303,16 +2308,15 @@ int32_t AppMgrServiceInner::ClearUpApplicationData(const std::string &bundleName int32_t callerUid, pid_t callerPid, int32_t appCloneIndex, int32_t userId) { 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 = currentUserId_; + userId = GetUserIdByUid(callerUid); + if (userId == U0_USER_ID || userId == U1_USER_ID) { + userId = UserManager::GetInstance().GetCurrentUserId(AAFwk::DisplayUtil::ObtainDefaultDisplayId()); } } TAG_LOGI(AAFwkTag::APPMGR, "bundleName: %{public}s, uId: %{public}d, appIndex: %{public}d", bundleName.c_str(), - newUserId, appCloneIndex); - return ClearUpApplicationDataByUserId(bundleName, callerUid, callerPid, appCloneIndex, newUserId, + userId, appCloneIndex); + return ClearUpApplicationDataByUserId(bundleName, callerUid, callerPid, appCloneIndex, userId, false, "ClearUpApplicationData"); } @@ -2328,9 +2332,6 @@ int32_t AppMgrServiceInner::ClearUpApplicationDataBySelf(int32_t callerUid, pid_ int32_t newUserId = userId; if (userId == DEFAULT_INVAL_VALUE) { newUserId = GetUserIdByUid(callerUid); - if (newUserId == U0_USER_ID) { - newUserId = currentUserId_; - } } auto appCloneIndex = appRecord->GetAppIndex(); return ClearUpApplicationDataByUserId(callerBundleName, callerUid, callerPid, appCloneIndex, newUserId, true, @@ -2428,17 +2429,17 @@ int32_t AppMgrServiceInner::GetRunningProcessesByBundleType(BundleType bundleTyp std::vector &info) { TAG_LOGD(AAFwkTag::APPMGR, "called"); - CHECK_CALLER_IS_SYSTEM_APP; if (!AAFwk::PermissionVerification::GetInstance()->VerifyRunningInfoPerm()) { TAG_LOGE(AAFwkTag::APPMGR, "permission deny"); return ERR_PERMISSION_DENIED; } + int32_t userId = GetUserIdByUid(IPCSkeleton::GetCallingUid()); for (const auto &item : appRunningManager_->GetAppRunningRecordMap()) { const auto &appRecord = item.second; if (!appRecord || !appRecord->GetSpawned()) { continue; } - if (GetUserIdByUid(appRecord->GetUid()) != currentUserId_) { + if (GetUserIdByUid(appRecord->GetUid()) != userId) { continue; } auto appInfo = appRecord->GetApplicationInfo(); @@ -2466,9 +2467,10 @@ int32_t AppMgrServiceInner::GetRunningMultiAppInfoByBundleName(const std::string return ERR_INVALID_VALUE; } ApplicationInfo appInfo; - TAG_LOGD(AAFwkTag::APPMGR, "userId: %{public}d, bundleName: %{public}s", currentUserId_, bundleName.c_str()); + int32_t userId = GetUserIdByUid(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, currentUserId_, appInfo)); + ApplicationFlag::GET_BASIC_APPLICATION_INFO, userId, appInfo)); if (!queryRet) { TAG_LOGE(AAFwkTag::APPMGR, "bundle unexist"); return AAFwk::ERR_BUNDLE_NOT_EXIST; @@ -2489,7 +2491,7 @@ int32_t AppMgrServiceInner::GetRunningMultiAppInfoByBundleName(const std::string if (appRecord == nullptr || appRecord->GetBundleName() != bundleName) { continue; } - if (GetUserIdByUid(appRecord->GetUid()) != currentUserId_) { + if (GetUserIdByUid(appRecord->GetUid()) != userId) { continue; } #ifdef SUPPORT_CHILD_PROCESS @@ -2517,25 +2519,12 @@ int32_t AppMgrServiceInner::GetAllRunningInstanceKeysBySelf(std::vector &instanceKeys, int32_t userId) -{ - if (userId == -1) { - userId = currentUserId_; - } - if (VerifyAccountPermission(AAFwk::PermissionConstants::PERMISSION_GET_RUNNING_INFO, userId) == - ERR_PERMISSION_DENIED) { - TAG_LOGE(AAFwkTag::APPMGR, "%{public}s: Permission verification fail", __func__); - return ERR_PERMISSION_DENIED; - } - return GetAllRunningInstanceKeysByBundleNameInner(bundleName, instanceKeys, userId); -} - -int32_t AppMgrServiceInner::GetAllRunningInstanceKeysByBundleNameInner(const std::string &bundleName, - std::vector &instanceKeys, int32_t userId) { if (bundleName.empty()) { TAG_LOGE(AAFwkTag::APPMGR, "bundlename null"); @@ -6349,7 +6338,11 @@ bool AppMgrServiceInner::VerifyAPL() const int AppMgrServiceInner::VerifyAccountPermission(const std::string &permissionName, const int userId) const { - if (userId != currentUserId_) { + auto callerUserId = GetUserIdByUid(IPCSkeleton::GetCallingUid()); + if (callerUserId == U0_USER_ID || callerUserId == U1_USER_ID) { + callerUserId = UserManager::GetInstance().GetCurrentUserId(AAFwk::DisplayUtil::ObtainDefaultDisplayId()); + } + if (userId != callerUserId) { auto isCallingPermAccount = AAFwk::PermissionVerification::GetInstance()->VerifyCallingPermission( AAFwk::PermissionConstants::PERMISSION_INTERACT_ACROSS_LOCAL_ACCOUNTS); if (!isCallingPermAccount) { @@ -7577,8 +7570,11 @@ int32_t AppMgrServiceInner::IsAppRunning(const std::string &bundleName, int32_t TAG_LOGE(AAFwkTag::APPMGR, "bundleMgrHelper null"); return ERR_INVALID_OPERATION; } + int32_t userId = GetUserIdByUid(IPCSkeleton::GetCallingUid()); + if (userId == U0_USER_ID || userId == U1_USER_ID) { + userId = UserManager::GetInstance().GetCurrentUserId(AAFwk::DisplayUtil::ObtainDefaultDisplayId()); + } BundleInfo bundleInfo; - auto userId = GetCurrentAccountId(); int32_t bundleMgrResult; if (appCloneIndex == 0) { bundleMgrResult = IN_PROCESS_CALL(bundleMgrHelper->GetBundleInfoV9(bundleName, @@ -7613,11 +7609,6 @@ int32_t AppMgrServiceInner::IsAppRunningByBundleNameAndUserId(const std::string TAG_LOGE(AAFwkTag::APPMGR, "appRunningManager_ null"); return ERR_NO_INIT; } - - if (userId < 0) { - userId = GetCurrentAccountId(); - } - return appRunningManager_->IsAppRunningByBundleNameAndUserId(bundleName, userId, isRunning); } @@ -7628,7 +7619,10 @@ bool AppMgrServiceInner::CreateAbilityInfo(const AAFwk::Want &want, AbilityInfo TAG_LOGE(AAFwkTag::APPMGR, "get bundle manager helper error"); return false; } - auto userId = GetCurrentAccountId(); + auto userId = GetUserIdByUid(IPCSkeleton::GetCallingUid()); + if (userId == U0_USER_ID || userId == U1_USER_ID) { + userId = UserManager::GetInstance().GetCurrentUserId(AAFwk::DisplayUtil::ObtainDefaultDisplayId()); + } auto abilityInfoFlag = AbilityRuntime::StartupUtil::BuildAbilityInfoFlag(); if (IN_PROCESS_CALL(bundleMgrHelper->QueryAbilityInfo(want, abilityInfoFlag, userId, abilityInfo))) { TAG_LOGI(AAFwkTag::APPMGR, "queryAbilityInfo ok"); @@ -7708,23 +7702,6 @@ int32_t AppMgrServiceInner::StartNativeProcessForDebugger(const AAFwk::Want &wan return StartPerfProcessByStartMsg(startMsg, pefCmd, debugCmd, isSandboxApp); } -int32_t AppMgrServiceInner::GetCurrentAccountId() const -{ - std::vector osActiveAccountIds; - ErrCode ret = DelayedSingleton::GetInstance()-> - QueryActiveOsAccountIds(osActiveAccountIds); - if (ret != ERR_OK) { - TAG_LOGE(AAFwkTag::APPMGR, "queryActiveOsAccountIds fail"); - return DEFAULT_USER_ID; - } - if (osActiveAccountIds.empty()) { - TAG_LOGE(AAFwkTag::APPMGR, "queryActiveOsAccountIds empty"); - return DEFAULT_USER_ID; - } - TAG_LOGD(AAFwkTag::APPMGR, "osActiveAccountId: %{public}d", osActiveAccountIds.front()); - return osActiveAccountIds.front(); -} - void AppMgrServiceInner::SetRunningSharedBundleList(const std::string &bundleName, const std::vector baseSharedBundleInfoList) { @@ -8077,8 +8054,9 @@ bool AppMgrServiceInner::CheckIsDebugApp(const std::string &bundleName) CHECK_POINTER_AND_RETURN_VALUE(bundleMgrHelper, false); BundleInfo bundleInfo; + auto userId = UserManager::GetInstance().GetCurrentUserId(AAFwk::DisplayUtil::ObtainDefaultDisplayId()); auto ret = IN_PROCESS_CALL(bundleMgrHelper->GetBundleInfoV9(bundleName, - static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_APPLICATION), bundleInfo, currentUserId_)); + static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_APPLICATION), bundleInfo, userId)); if (ret != ERR_OK) { TAG_LOGE(AAFwkTag::APPMGR, "getBundleInfo fail"); return false; @@ -8328,7 +8306,8 @@ void AppMgrServiceInner::ClearResidentProcessAppRunningData(const std::shared_pt return; } auto userId = GetUserIdByUid(appRecord->GetUid()); - if (appRecord->IsKeepAliveApp() && (userId == 0 || userId == currentUserId_) && + bool isCurentUserId = UserManager::GetInstance().IsCurrentUser(userId); + if (appRecord->IsKeepAliveApp() && (userId == 0 || isCurentUserId) && appRecord->GetBundleName() != SCENE_BOARD_BUNDLE_NAME) { if (!IsNeedRestartKeepAliveProcess(appRecord->GetBundleName(), appRecord->GetUid())) { return; @@ -8373,10 +8352,10 @@ void AppMgrServiceInner::ClearNonResidentKeepAliveAppRunningData(const std::shar } auto userId = GetUserIdByUid(appRecord->GetUid()); + bool isCurentUserId = UserManager::GetInstance().IsCurrentUser(userId); bool isDefaultInstance = appRecord->GetInstanceKey().empty() || appRecord->GetInstanceKey() == APP_INSTANCE_KEY_0; - if (!appRecord->GetRestartAppFlag() && (appRecord->IsKeepAliveDkv() || appRecord->IsKeepAliveAppService()) && - isDefaultInstance && (userId == 0 || userId == 1 ||userId == currentUserId_) && - appRecord->GetBundleName() != SCENE_BOARD_BUNDLE_NAME) { + if (!appRecord->GetRestartAppFlag() && appRecord->IsKeepAliveDkv() && isDefaultInstance && + (userId == 0 || isCurentUserId) && appRecord->GetBundleName() != SCENE_BOARD_BUNDLE_NAME) { if (ExitResidentProcessManager::GetInstance().IsKilledForUpgradeWeb(appRecord->GetBundleName())) { TAG_LOGI(AAFwkTag::APPMGR, "is killed for upgrade web"); return; diff --git a/services/common/BUILD.gn b/services/common/BUILD.gn index 42fc60e8300..d18fdec279c 100644 --- a/services/common/BUILD.gn +++ b/services/common/BUILD.gn @@ -284,6 +284,35 @@ ohos_shared_library("hitrace_chain_util") { "hitrace:libhitracechain", ] + innerapi_tags = [ "platformsdk_indirect" ] + subsystem_name = "ability" + part_name = "ability_runtime" +} + +ohos_shared_library("user_controller") { + sanitize = { + integer_overflow = true + ubsan = true + boundary_sanitize = true + cfi = true + cfi_cross_dso = true + debug = false + } + branch_protector_ret = "pac_ret" + + include_dirs = [ + "include/user_controller", + "${ability_runtime_services_path}/common/include", + ] + + sources = [ "src/user_controller/user_manager.cpp" ] + + external_deps = [ + "c_utils:utils", + "ffrt:libffrt", + "hilog:libhilog", + ] + innerapi_tags = [ "platformsdk_indirect" ] subsystem_name = "ability" part_name = "ability_runtime" diff --git a/services/common/include/display_util.h b/services/common/include/display_util.h index eb22fda5f3d..897a4c6f051 100644 --- a/services/common/include/display_util.h +++ b/services/common/include/display_util.h @@ -37,6 +37,18 @@ static inline int32_t GetDefaultDisplayId() } return static_cast(Rosen::DisplayManager::GetInstance().GetDefaultDisplayId()); } + +static inline uint64_t ObtainDefaultDisplayId() +{ + if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { + sptr display = Rosen::DisplayManager::GetInstance().GetPrimaryDisplaySync(); + if (display != nullptr) { + TAG_LOGD(AAFwkTag::DEFAULT, "displayId: %{public}" PRIu64"", display->GetId()); + return display->GetId(); + } + } + return Rosen::DisplayManager::GetInstance().GetDefaultDisplayId(); +} #endif }; } // namespace AAFwk diff --git a/services/common/include/user_controller/user_manager.h b/services/common/include/user_controller/user_manager.h new file mode 100644 index 00000000000..5b9c7b67c76 --- /dev/null +++ b/services/common/include/user_controller/user_manager.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2025 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 OHOS_ABILITY_RUNTIME_USER_MANAGER_H +#define OHOS_ABILITY_RUNTIME_USER_MANAGER_H + +#include +#include "cpp/mutex.h" + +namespace OHOS { +namespace AbilityRuntime { +class UserManager final { +public: + UserManager& operator=(const UserManager&) = delete; + UserManager(const UserManager&) = delete; + virtual ~UserManager() = default; + static UserManager& GetInstance(); + + int32_t GetCurrentUserId(uint64_t displayId); + + bool GetDisplayIdByUserId(int32_t userId, uint64_t &displayId); + + bool IsCurrentUser(int32_t userId); + + void SetCurrentUserId(int32_t userId, uint64_t displayId); + + void ClearUserId(int32_t userId); + +private: + UserManager() = default; + + ffrt::mutex userLock_; + std::unordered_map displayIdMap_; +}; +} // namespace AbilityRuntime +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_USER_MANAGER_H \ No newline at end of file diff --git a/services/common/src/user_controller/user_manager.cpp b/services/common/src/user_controller/user_manager.cpp new file mode 100644 index 00000000000..b36a8dfad9e --- /dev/null +++ b/services/common/src/user_controller/user_manager.cpp @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2025 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. + */ + +#include "user_manager.h" + +#include + +namespace OHOS { +namespace AbilityRuntime { +UserManager& UserManager::GetInstance() +{ + static UserManager instance; + return instance; +} + +void UserManager::ClearUserId(int32_t userId) +{ + std::lock_guard guard(userLock_); + for (auto iter = displayIdMap_.begin(); iter != displayIdMap_.end();) { + if (iter->second == userId) { + displayIdMap_.erase(iter); + break; + } + } +} + +int32_t UserManager::GetCurrentUserId(uint64_t displayId) +{ + std::lock_guard guard(userLock_); + auto iter = displayIdMap_.find(displayId); + if (iter != displayIdMap_.end()) { + return iter->second; + } + return 0; +} + +bool UserManager::GetDisplayIdByUserId(int32_t userId, uint64_t &displayId) +{ + std::lock_guard guard(userLock_); + for (auto &item : displayIdMap_) { + if (item.second == userId) { + displayId = item.first; + return true; + } + } + return false; +} + +bool UserManager::IsCurrentUser(int32_t userId) +{ + std::lock_guard guard(userLock_); + for (auto &item : displayIdMap_) { + if (item.second == userId) { + return true; + } + } + return false; +} + +void UserManager::SetCurrentUserId(int32_t userId, uint64_t displayId) +{ + std::lock_guard guard(userLock_); + displayIdMap_[displayId] = userId; +} +} +} \ No newline at end of file diff --git a/test/fuzztest/abilityautostartupservicea_fuzzer/BUILD.gn b/test/fuzztest/abilityautostartupservicea_fuzzer/BUILD.gn index 312685efe45..3bb82929a80 100755 --- a/test/fuzztest/abilityautostartupservicea_fuzzer/BUILD.gn +++ b/test/fuzztest/abilityautostartupservicea_fuzzer/BUILD.gn @@ -56,6 +56,7 @@ ohos_fuzztest("AbilityAutoStartupServiceaFuzzTest") { "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:app_util", "${ability_runtime_services_path}/common:perm_verification", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ diff --git a/test/fuzztest/abilityautostartupserviceb_fuzzer/BUILD.gn b/test/fuzztest/abilityautostartupserviceb_fuzzer/BUILD.gn index c1d52c33e18..0d947e370e7 100755 --- a/test/fuzztest/abilityautostartupserviceb_fuzzer/BUILD.gn +++ b/test/fuzztest/abilityautostartupserviceb_fuzzer/BUILD.gn @@ -56,6 +56,7 @@ ohos_fuzztest("AbilityAutoStartupServicebFuzzTest") { "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:app_util", "${ability_runtime_services_path}/common:perm_verification", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ diff --git a/test/fuzztest/abilityautostartupserviceb_fuzzer/abilityautostartupserviceb_fuzzer.cpp b/test/fuzztest/abilityautostartupserviceb_fuzzer/abilityautostartupserviceb_fuzzer.cpp index 820752e27f5..a67243b7339 100755 --- a/test/fuzztest/abilityautostartupserviceb_fuzzer/abilityautostartupserviceb_fuzzer.cpp +++ b/test/fuzztest/abilityautostartupserviceb_fuzzer/abilityautostartupserviceb_fuzzer.cpp @@ -85,7 +85,6 @@ void AbilityStartupServiceFuzztest1(bool boolParam, std::string &stringParam, in service->GetSelfApplicationBundleName(); service->CheckSelfApplication(stringParam); - service->GetValidUserId(int32Param); AppExecFwk::BundleInfo bundleInfo; service->GetBundleInfo(stringParam, int32Param, int32Param, bundleInfo); // branch AutoStartupInfo info; diff --git a/test/fuzztest/abilityautostartupservicefirst_fuzzer/BUILD.gn b/test/fuzztest/abilityautostartupservicefirst_fuzzer/BUILD.gn index ab0d1d7be62..dda7ec7bc4b 100644 --- a/test/fuzztest/abilityautostartupservicefirst_fuzzer/BUILD.gn +++ b/test/fuzztest/abilityautostartupservicefirst_fuzzer/BUILD.gn @@ -57,6 +57,7 @@ ohos_fuzztest("AbilityAutoStartupServiceFirstFuzzTest") { "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:app_util", "${ability_runtime_services_path}/common:perm_verification", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ diff --git a/test/fuzztest/abilitymanagerservicefourth_fuzzer/abilitymanagerservicefourth_fuzzer.cpp b/test/fuzztest/abilitymanagerservicefourth_fuzzer/abilitymanagerservicefourth_fuzzer.cpp index 61dd7800ee8..caeddfac2c4 100755 --- a/test/fuzztest/abilitymanagerservicefourth_fuzzer/abilitymanagerservicefourth_fuzzer.cpp +++ b/test/fuzztest/abilitymanagerservicefourth_fuzzer/abilitymanagerservicefourth_fuzzer.cpp @@ -66,7 +66,7 @@ bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) AppExecFwk::AbilityInfo abilityInfo; abilityms->JudgeAbilityVisibleControl(abilityInfo); sptr callback; - abilityms->StartUser(intParam, callback); + abilityms->StartUser(intParam, 0, callback); abilityms->StopUser(intParam, callback); abilityms->OnAcceptWantResponse(*want, stringParam, 0); abilityms->OnStartSpecifiedAbilityTimeoutResponse(0); diff --git a/test/fuzztest/abilitymanagerservicesixth_fuzzer/abilitymanagerservicesixth_fuzzer.cpp b/test/fuzztest/abilitymanagerservicesixth_fuzzer/abilitymanagerservicesixth_fuzzer.cpp index a47343fac8f..4b1890151df 100755 --- a/test/fuzztest/abilitymanagerservicesixth_fuzzer/abilitymanagerservicesixth_fuzzer.cpp +++ b/test/fuzztest/abilitymanagerservicesixth_fuzzer/abilitymanagerservicesixth_fuzzer.cpp @@ -79,7 +79,6 @@ bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) // fuzz for AbilityManagerService auto abilityms = std::make_shared(); abilityms->GetEventHandler(); - abilityms->GetUserId(); AbilityRequest request; abilityms->GenerateAbilityRequest(*want, intParam, request, token, int32Param); abilityms->GenerateExtensionAbilityRequest(*want, request, token, int32Param); diff --git a/test/fuzztest/startuser_fuzzer/startuser_fuzzer.cpp b/test/fuzztest/startuser_fuzzer/startuser_fuzzer.cpp index 4c9cc15bbb7..a4b308cac0c 100644 --- a/test/fuzztest/startuser_fuzzer/startuser_fuzzer.cpp +++ b/test/fuzztest/startuser_fuzzer/startuser_fuzzer.cpp @@ -42,7 +42,7 @@ bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) int accountId = static_cast(GetU32Data(data)); sptr callback; - abilitymgr->StartUser(accountId, callback); + abilitymgr->StartUser(accountId, 0, callback); return true; } diff --git a/test/mock/frameworks_kits_ability_ability_runtime_test/AMS/mock_ability_manager_client.cpp b/test/mock/frameworks_kits_ability_ability_runtime_test/AMS/mock_ability_manager_client.cpp index 9fddcdfc1cc..8eb2af62769 100644 --- a/test/mock/frameworks_kits_ability_ability_runtime_test/AMS/mock_ability_manager_client.cpp +++ b/test/mock/frameworks_kits_ability_ability_runtime_test/AMS/mock_ability_manager_client.cpp @@ -326,14 +326,15 @@ ErrCode AbilityManagerClient::StopSyncRemoteMissions(const std::string& devId) return abms->StopSyncRemoteMissions(devId); } -ErrCode AbilityManagerClient::StartUser(int accountId, sptr callback, bool isAppRecovery) +ErrCode AbilityManagerClient::StartUser(int accountId, uint64_t displayId, sptr callback, + bool isAppRecovery) { if (g_remoteObject == nullptr) { return ABILITY_SERVICE_NOT_CONNECTED; } sptr abms = iface_cast(g_remoteObject); - return abms->StartUser(accountId, callback); + return abms->StartUser(accountId, displayId, callback); } ErrCode AbilityManagerClient::StopUser(int accountId, sptr callback) diff --git a/test/mock/frameworks_kits_ability_ability_runtime_test/AMS/mock_serviceability_manager_service.h b/test/mock/frameworks_kits_ability_ability_runtime_test/AMS/mock_serviceability_manager_service.h index 89299aada1b..e731850ebaa 100644 --- a/test/mock/frameworks_kits_ability_ability_runtime_test/AMS/mock_serviceability_manager_service.h +++ b/test/mock/frameworks_kits_ability_ability_runtime_test/AMS/mock_serviceability_manager_service.h @@ -208,7 +208,7 @@ public: return 0; } - int StartUser(int accountId, sptr callback, bool isAppRecovery) + int StartUser(int accountId, uint64_t displayId, sptr callback, bool isAppRecovery) { return 0; } diff --git a/test/mock/frameworks_kits_ability_native_test/include/mock_ability_manager_service.h b/test/mock/frameworks_kits_ability_native_test/include/mock_ability_manager_service.h index dd7fe95a149..4137df30ef0 100644 --- a/test/mock/frameworks_kits_ability_native_test/include/mock_ability_manager_service.h +++ b/test/mock/frameworks_kits_ability_native_test/include/mock_ability_manager_service.h @@ -173,7 +173,7 @@ public: int UninstallApp(const std::string& bundleName, int32_t uid) override; - int StartUser(int userId, sptr callback, bool isAppRecovery) override + int StartUser(int userId, uint64_t displayId, sptr callback, bool isAppRecovery) override { return 0; } diff --git a/test/mock/frameworks_kits_appkit_native_test/ability_delegator/mock_ability_delegator_stub.cpp b/test/mock/frameworks_kits_appkit_native_test/ability_delegator/mock_ability_delegator_stub.cpp index 127ea466c0a..b9f0168fda6 100644 --- a/test/mock/frameworks_kits_appkit_native_test/ability_delegator/mock_ability_delegator_stub.cpp +++ b/test/mock/frameworks_kits_appkit_native_test/ability_delegator/mock_ability_delegator_stub.cpp @@ -60,7 +60,8 @@ void MockAbilityDelegatorStub::DumpState(const std::string& args, std::vector callback, bool isAppRecovery) +int MockAbilityDelegatorStub::StartUser(int userId, uint64_t displayId, sptr callback, + bool isAppRecovery) { return 0; } @@ -253,7 +254,8 @@ int MockAbilityDelegatorStub2::StopServiceAbility(const Want& want, int32_t user return 0; } -int MockAbilityDelegatorStub2::StartUser(int userId, sptr callback, bool isAppRecovery) +int MockAbilityDelegatorStub2::StartUser(int userId, uint64_t displayId, sptr callback, + bool isAppRecovery) { return 0; } diff --git a/test/mock/frameworks_kits_appkit_native_test/ability_delegator/mock_ability_delegator_stub.h b/test/mock/frameworks_kits_appkit_native_test/ability_delegator/mock_ability_delegator_stub.h index 7d1d71c4244..3cb74a26925 100644 --- a/test/mock/frameworks_kits_appkit_native_test/ability_delegator/mock_ability_delegator_stub.h +++ b/test/mock/frameworks_kits_appkit_native_test/ability_delegator/mock_ability_delegator_stub.h @@ -125,7 +125,7 @@ public: MOCK_METHOD4(ShareDataDone, int32_t(const sptr &token, const int32_t &resultCode, const int32_t &uniqueId, WantParams &wantParam)); MOCK_METHOD2(SetMissionContinueState, int(const sptr& token, const AAFwk::ContinueState& state)); - int StartUser(int userId, sptr callback, bool isAppRecovery) override; + int StartUser(int userId, uint64_t displayId, sptr callback, bool isAppRecovery) override; int StopUser(int userId, const sptr& callback) override; int LogoutUser(int32_t userId, sptr callback = nullptr) override; int StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag) override; @@ -306,7 +306,7 @@ public: MOCK_METHOD4(ShareDataDone, int32_t(const sptr &token, const int32_t &resultCode, const int32_t &uniqueId, WantParams &wantParam)); MOCK_METHOD2(SetMissionContinueState, int(const sptr& token, const AAFwk::ContinueState& state)); - int StartUser(int userId, sptr callback, bool isAppRecovery) override; + int StartUser(int userId, uint64_t displayId, sptr callback, bool isAppRecovery) override; int StopUser(int userId, const sptr& callback) override; int LogoutUser(int32_t userId, sptr callback = nullptr) override; int StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag) override; diff --git a/test/mock/frameworks_kits_appkit_test/include/mock_app_mgr_service.h b/test/mock/frameworks_kits_appkit_test/include/mock_app_mgr_service.h index e6d5a1fe687..4fcd6b0ee9b 100644 --- a/test/mock/frameworks_kits_appkit_test/include/mock_app_mgr_service.h +++ b/test/mock/frameworks_kits_appkit_test/include/mock_app_mgr_service.h @@ -88,8 +88,8 @@ public: MOCK_METHOD2(GetRunningMultiAppInfoByBundleName, int32_t(const std::string &bundleName, RunningMultiAppInfo &info)); MOCK_METHOD1(GetAllRunningInstanceKeysBySelf, int32_t(std::vector &instanceKeys)); - MOCK_METHOD3(GetAllRunningInstanceKeysByBundleName, int32_t(const std::string &bundleName, - std::vector &instanceKeys, int32_t userId)); + MOCK_METHOD2(GetAllRunningInstanceKeysByBundleName, int32_t(const std::string &bundleName, + std::vector &instanceKeys)); MOCK_METHOD1(SetSupportedProcessCacheSelf, int32_t(bool isSupported)); MOCK_METHOD2(IsProcessCacheSupported, int32_t(int32_t pid, bool &isSupported)); MOCK_METHOD2(SetProcessCacheEnable, int32_t(int32_t pid, bool enable)); diff --git a/test/mock/frameworks_kits_test/AMS/mock_ability_manager_service.h b/test/mock/frameworks_kits_test/AMS/mock_ability_manager_service.h index 3fb4002e104..44f19bf59ac 100644 --- a/test/mock/frameworks_kits_test/AMS/mock_ability_manager_service.h +++ b/test/mock/frameworks_kits_test/AMS/mock_ability_manager_service.h @@ -165,7 +165,7 @@ public: MOCK_METHOD4(ShareDataDone, int32_t(const sptr &token, const int32_t &resultCode, const int32_t &uniqueId, WantParams &wantParam)); - int StartUser(int userId, sptr callback, bool isAppRecovery) override + int StartUser(int userId, uint64_t displayId, sptr callback, bool isAppRecovery) override { return 0; } diff --git a/test/mock/frameworks_kits_test/AMS/mock_serviceability_manager_service.h b/test/mock/frameworks_kits_test/AMS/mock_serviceability_manager_service.h index 2f54869dfb9..0531d96b543 100644 --- a/test/mock/frameworks_kits_test/AMS/mock_serviceability_manager_service.h +++ b/test/mock/frameworks_kits_test/AMS/mock_serviceability_manager_service.h @@ -179,7 +179,7 @@ public: return 0; } - int StartUser(int userId, sptr callback, bool isAppRecovery) override + int StartUser(int userId, uint64_t displayId, sptr callback, bool isAppRecovery) override { return 0; } diff --git a/test/mock/services_abilitymgr_test/libs/appexecfwk_core/include/appmgr/app_mgr_client.h b/test/mock/services_abilitymgr_test/libs/appexecfwk_core/include/appmgr/app_mgr_client.h index 0a473259fc3..b6c2c13ed37 100644 --- a/test/mock/services_abilitymgr_test/libs/appexecfwk_core/include/appmgr/app_mgr_client.h +++ b/test/mock/services_abilitymgr_test/libs/appexecfwk_core/include/appmgr/app_mgr_client.h @@ -149,11 +149,10 @@ public: * * @param bundlename, bundle name in Application record. * @param instanceKeys, output instance keys of the multi-instance app. - * @param userId, user id. * @return ERR_OK ,return back success,others fail. */ virtual AppMgrResultCode GetAllRunningInstanceKeysByBundleName(const std::string &bundleName, - std::vector &instanceKeys, int32_t userId = -1); + std::vector &instanceKeys); /** * GetAllRenderProcesses, call GetAllRenderProcesses() through proxy project. diff --git a/test/mock/services_abilitymgr_test/libs/appexecfwk_core/include/appmgr/app_mgr_interface.h b/test/mock/services_abilitymgr_test/libs/appexecfwk_core/include/appmgr/app_mgr_interface.h index 8578c55375f..4905359a8a2 100644 --- a/test/mock/services_abilitymgr_test/libs/appexecfwk_core/include/appmgr/app_mgr_interface.h +++ b/test/mock/services_abilitymgr_test/libs/appexecfwk_core/include/appmgr/app_mgr_interface.h @@ -126,11 +126,10 @@ public: * * @param bundlename, bundle name in Application record. * @param instanceKeys, output instance keys of the multi-instance app. - * @param userId, user id. * @return ERR_OK ,return back success,others fail. */ virtual int32_t GetAllRunningInstanceKeysByBundleName(const std::string &bundleName, - std::vector &instanceKeys, int32_t userId = -1) = 0; + std::vector &instanceKeys) = 0; /** * GetAllRenderProcesses, call GetAllRenderProcesses() through proxy project. diff --git a/test/mock/services_appmgr_test/include/mock_app_mgr_service.h b/test/mock/services_appmgr_test/include/mock_app_mgr_service.h index 859875dbefa..939aa2e0679 100644 --- a/test/mock/services_appmgr_test/include/mock_app_mgr_service.h +++ b/test/mock/services_appmgr_test/include/mock_app_mgr_service.h @@ -97,8 +97,8 @@ public: MOCK_METHOD2(GetRunningMultiAppInfoByBundleName, int32_t(const std::string &bundleName, RunningMultiAppInfo &info)); MOCK_METHOD1(GetAllRunningInstanceKeysBySelf, int32_t(std::vector &instanceKeys)); - MOCK_METHOD3(GetAllRunningInstanceKeysByBundleName, int32_t(const std::string &bundleName, - std::vector &instanceKeys, int32_t userId)); + MOCK_METHOD2(GetAllRunningInstanceKeysByBundleName, int32_t(const std::string &bundleName, + std::vector &instanceKeys)); MOCK_METHOD2(IsApplicationRunning, int32_t(const std::string &bundleName, bool &isRunning)); MOCK_METHOD3(IsAppRunning, int32_t(const std::string &bundleName, int32_t appCloneIndex, bool &isRunning)); diff --git a/test/moduletest/ability_manager_client_test/mock_iabilitymanager.h b/test/moduletest/ability_manager_client_test/mock_iabilitymanager.h index 4682b9fb078..468a9e3580d 100644 --- a/test/moduletest/ability_manager_client_test/mock_iabilitymanager.h +++ b/test/moduletest/ability_manager_client_test/mock_iabilitymanager.h @@ -289,7 +289,7 @@ public: { return 0; } - int StartUser(int userId, sptr callback, bool isAppRecovery = false) override + int StartUser(int userId, uint64_t displayId, sptr callback, bool isAppRecovery = false) override { return 0; } diff --git a/test/moduletest/ability_timeout_module_test/ability_timeout_module_test.cpp b/test/moduletest/ability_timeout_module_test/ability_timeout_module_test.cpp index 3b1167e5522..fad5325e4ea 100644 --- a/test/moduletest/ability_timeout_module_test/ability_timeout_module_test.cpp +++ b/test/moduletest/ability_timeout_module_test/ability_timeout_module_test.cpp @@ -138,18 +138,11 @@ void AbilityTimeoutModuleTest::MockOnStart() abilityMs_->taskHandler_ = TaskHandlerWrap::CreateQueueHandler(AbilityConfig::NAME_ABILITY_MGR_SERVICE); EXPECT_TRUE(abilityMs_->taskHandler_); - // init user controller. - abilityMs_->userController_ = std::make_shared(); - EXPECT_TRUE(abilityMs_->userController_); - abilityMs_->userController_->Init(); - AmsConfigurationParameter::GetInstance().Parse(); abilityMs_->subManagersHelper_ = std::make_shared(nullptr, nullptr); abilityMs_->subManagersHelper_->InitSubManagers(MOCK_MAIN_USER_ID, true); abilityMs_->SwitchManagers(MOCK_U0_USER_ID, false); - abilityMs_->userController_->SetCurrentUserId(MOCK_MAIN_USER_ID); - abilityMs_->state_ = ServiceRunningState::STATE_RUNNING; abilityMs_->iBundleManager_ = new BundleMgrService(); @@ -174,7 +167,6 @@ void AbilityTimeoutModuleTest::MockOnStop() abilityMs_->subManagersHelper_->currentPendingWantManager_.reset(); abilityMs_->subManagersHelper_->missionListManagers_.clear(); abilityMs_->subManagersHelper_->currentMissionListManager_.reset(); - abilityMs_->userController_.reset(); abilityMs_->abilityController_.clear(); abilityMs_->OnStop(); } @@ -320,7 +312,6 @@ HWTEST_F(AbilityTimeoutModuleTest, OnAbilityDied_001, TestSize.Level1) EXPECT_EQ(rootLauncher, ability); EXPECT_TRUE(rootLauncher->IsLauncherRoot()); - GTEST_LOG_(INFO) << "userId:" << abilityMs_->GetUserId(); GTEST_LOG_(INFO) << "currentmanager userId" << curListManager->userId_; // died rootlauncher ability diff --git a/test/moduletest/common/ams/BUILD.gn b/test/moduletest/common/ams/BUILD.gn index fcff77e2efe..1ca2625d8a2 100644 --- a/test/moduletest/common/ams/BUILD.gn +++ b/test/moduletest/common/ams/BUILD.gn @@ -65,6 +65,7 @@ ohos_source_set("appmgr_mst_source") { "init:libbegetutil", "ipc:ipc_core", "json:nlohmann_json_static", + "window_manager:libwsutils", ] public_external_deps = [ 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 60e8956a967..41aeac608c4 100644 --- a/test/moduletest/common/ams/ability_running_record_test/BUILD.gn +++ b/test/moduletest/common/ams/ability_running_record_test/BUILD.gn @@ -33,6 +33,7 @@ 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", ] @@ -55,6 +56,7 @@ ohos_moduletest("AmsAbilityRunningRecordModuleTest") { if (ability_runtime_graphics) { external_deps += [ + "window_manager:libdm", "window_manager:libwm", "window_manager:libwsutils", ] 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 245d98c4f01..2cf0fe1553f 100644 --- a/test/moduletest/common/ams/app_mgr_service_test/BUILD.gn +++ b/test/moduletest/common/ams/app_mgr_service_test/BUILD.gn @@ -43,6 +43,7 @@ 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", ] @@ -66,6 +67,7 @@ ohos_moduletest("AmsAppMgrServiceModuleTest") { if (ability_runtime_graphics) { external_deps += [ "i18n:intl_util", + "window_manager:libdm", "window_manager:libwm", ] } 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 d1fbca3d6f0..d6b441d8373 100644 --- a/test/moduletest/common/ams/app_recent_list_test/BUILD.gn +++ b/test/moduletest/common/ams/app_recent_list_test/BUILD.gn @@ -35,6 +35,7 @@ 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 9a41ae9d754..e1e11e547cc 100644 --- a/test/moduletest/common/ams/app_service_flow_test/BUILD.gn +++ b/test/moduletest/common/ams/app_service_flow_test/BUILD.gn @@ -38,6 +38,7 @@ 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 effd5e6d6f7..effbcf849d9 100644 --- a/test/moduletest/common/ams/ipc_ams_mgr_test/BUILD.gn +++ b/test/moduletest/common/ams/ipc_ams_mgr_test/BUILD.gn @@ -44,6 +44,7 @@ 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", ] @@ -67,7 +68,10 @@ ohos_moduletest("AmsIpcAmsmgrModuleTest") { ] if (ability_runtime_graphics) { - external_deps += [ "window_manager:libwm" ] + external_deps += [ + "window_manager:libdm", + "window_manager:libwm", + ] } if (background_task_mgr_continuous_task_enable) { 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 9689d74f1b5..3f08a5282f9 100644 --- a/test/moduletest/common/ams/ipc_app_mgr_test/BUILD.gn +++ b/test/moduletest/common/ams/ipc_app_mgr_test/BUILD.gn @@ -35,6 +35,7 @@ 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", ] @@ -60,6 +61,7 @@ ohos_moduletest("AmsIpcAppmgrModuleTest") { "memory_utils:libmeminfo", "safwk:system_ability_fwk", "samgr:samgr_proxy", + "window_manager:libdm", "window_manager:libwm", "window_manager:libwsutils", ] 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 8f3185e86e1..969354cc200 100644 --- a/test/moduletest/common/ams/ipc_app_scheduler_test/BUILD.gn +++ b/test/moduletest/common/ams/ipc_app_scheduler_test/BUILD.gn @@ -35,6 +35,7 @@ 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", ] @@ -60,6 +61,7 @@ ohos_moduletest("AmsIpcAppSchedulerModuleTest") { "memory_utils:libmeminfo", "safwk:system_ability_fwk", "samgr:samgr_proxy", + "window_manager:libdm", "window_manager:libwm", "window_manager:libwsutils", ] 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 92bf5be75cb..4f4897ba1df 100644 --- a/test/moduletest/common/ams/service_start_process_test/BUILD.gn +++ b/test/moduletest/common/ams/service_start_process_test/BUILD.gn @@ -35,6 +35,7 @@ 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", ] @@ -54,6 +55,7 @@ ohos_moduletest("AmsServiceStartModuleTest") { if (ability_runtime_graphics) { external_deps += [ "i18n:intl_util", + "window_manager:libdm", "window_manager:libwm", ] } diff --git a/test/moduletest/mock/include/mock_ability_mgr_service.h b/test/moduletest/mock/include/mock_ability_mgr_service.h index 9f9438d1759..2aa5fe0bae2 100644 --- a/test/moduletest/mock/include/mock_ability_mgr_service.h +++ b/test/moduletest/mock/include/mock_ability_mgr_service.h @@ -130,7 +130,7 @@ public: return 0; } - virtual int StartUser(int userId, sptr callback, bool isAppRecovery) override + virtual int StartUser(int userId, uint64_t displayId, sptr callback, bool isAppRecovery) override { return 0; } diff --git a/test/moduletest/mock/include/mock_app_mgr_client.h b/test/moduletest/mock/include/mock_app_mgr_client.h index 04408b97aa3..8971e095122 100644 --- a/test/moduletest/mock/include/mock_app_mgr_client.h +++ b/test/moduletest/mock/include/mock_app_mgr_client.h @@ -39,8 +39,8 @@ public: AppExecFwk::RunningProcessInfo& info))); MOCK_METHOD1(GetAllRunningProcesses, AppMgrResultCode(std::vector& info)); MOCK_METHOD1(GetAllRunningInstanceKeysBySelf, AppMgrResultCode(std::vector &instanceKeys)); - MOCK_METHOD3(GetAllRunningInstanceKeysByBundleName, AppMgrResultCode(const std::string &bundleName, - std::vector &instanceKeys, int32_t userId)); + MOCK_METHOD2(GetAllRunningInstanceKeysByBundleName, AppMgrResultCode(const std::string &bundleName, + std::vector &instanceKeys)); AppMgrResultCode GetProcessRunningInfosByUserId(std::vector& info, int32_t userId); diff --git a/test/moduletest/running_infos_module_test/running_infos_module_test.cpp b/test/moduletest/running_infos_module_test/running_infos_module_test.cpp index 82cb2a1de86..dbd0f973508 100644 --- a/test/moduletest/running_infos_module_test/running_infos_module_test.cpp +++ b/test/moduletest/running_infos_module_test/running_infos_module_test.cpp @@ -116,13 +116,6 @@ void RunningInfosModuleTest::OnStartAms() abilityMgrServ_->taskHandler_ = TaskHandlerWrap::CreateQueueHandler(AbilityConfig::NAME_ABILITY_MGR_SERVICE); EXPECT_TRUE(abilityMgrServ_->taskHandler_); - // init user controller. - abilityMgrServ_->userController_ = std::make_shared(); - EXPECT_TRUE(abilityMgrServ_->userController_); - abilityMgrServ_->userController_->Init(); - int userId = MOCK_MAIN_USER_ID; - abilityMgrServ_->userController_->SetCurrentUserId(userId); - AmsConfigurationParameter::GetInstance().Parse(); abilityMgrServ_->interceptorExecuter_ = std::make_shared(); diff --git a/test/moduletest/start_ability_implicit_module_test/start_ability_implicit_module_test.cpp b/test/moduletest/start_ability_implicit_module_test/start_ability_implicit_module_test.cpp index 4b554b108b4..d924b4eb818 100644 --- a/test/moduletest/start_ability_implicit_module_test/start_ability_implicit_module_test.cpp +++ b/test/moduletest/start_ability_implicit_module_test/start_ability_implicit_module_test.cpp @@ -28,6 +28,7 @@ #include "mock_bundle_mgr.h" #include "sa_mgr_client.h" #include "system_ability_definition.h" +#include "user_controller.h" #include "ui_service_mgr_client_mock.h" #include "mission_list_manager.h" @@ -87,10 +88,6 @@ void StartAbilityImplicitModuleTest::OnStartAms() const abilityMs_->state_ = ServiceRunningState::STATE_RUNNING; abilityMs_->taskHandler_ = TaskHandlerWrap::CreateQueueHandler("StartAbilityImplicitModuleTest"); - // init user controller. - abilityMs_->userController_ = std::make_shared(); - EXPECT_TRUE(abilityMs_->userController_); - abilityMs_->userController_->Init(); abilityMs_->subManagersHelper_ = std::make_shared(nullptr, nullptr); abilityMs_->subManagersHelper_->InitSubManagers(MOCK_MAIN_USER_ID, true); @@ -105,7 +102,7 @@ void StartAbilityImplicitModuleTest::OnStartAms() const DelayedSingleton::GetInstance()->SetDeviceType("phone"); abilityMs_->SwitchManagers(0, false); - abilityMs_->userController_->SetCurrentUserId(MOCK_MAIN_USER_ID); + UserController::GetInstance().SetCurrentUserId(MOCK_MAIN_USER_ID, 0); return; } diff --git a/test/new_test/mock/ability_manager_service/ability_manager_service.h b/test/new_test/mock/ability_manager_service/ability_manager_service.h index da613207363..a7315a46a1e 100644 --- a/test/new_test/mock/ability_manager_service/ability_manager_service.h +++ b/test/new_test/mock/ability_manager_service/ability_manager_service.h @@ -45,7 +45,7 @@ public: void StopFreezingScreen() {} void UserStarted(int32_t userId) {} - OH_MOCK_METHOD(int, AbilityManagerService, SwitchToUser, int32_t, int32_t, + OH_MOCK_METHOD(int, AbilityManagerService, SwitchToUser, int32_t, int32_t, uint64_t, sptr, bool isAppRecovery = false); void ClearUserData(int32_t userId) {} }; diff --git a/test/new_test/mock/user_controller/user_controller/user_manager.cpp b/test/new_test/mock/user_controller/user_controller/user_manager.cpp new file mode 100644 index 00000000000..b36a8dfad9e --- /dev/null +++ b/test/new_test/mock/user_controller/user_controller/user_manager.cpp @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2025 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. + */ + +#include "user_manager.h" + +#include + +namespace OHOS { +namespace AbilityRuntime { +UserManager& UserManager::GetInstance() +{ + static UserManager instance; + return instance; +} + +void UserManager::ClearUserId(int32_t userId) +{ + std::lock_guard guard(userLock_); + for (auto iter = displayIdMap_.begin(); iter != displayIdMap_.end();) { + if (iter->second == userId) { + displayIdMap_.erase(iter); + break; + } + } +} + +int32_t UserManager::GetCurrentUserId(uint64_t displayId) +{ + std::lock_guard guard(userLock_); + auto iter = displayIdMap_.find(displayId); + if (iter != displayIdMap_.end()) { + return iter->second; + } + return 0; +} + +bool UserManager::GetDisplayIdByUserId(int32_t userId, uint64_t &displayId) +{ + std::lock_guard guard(userLock_); + for (auto &item : displayIdMap_) { + if (item.second == userId) { + displayId = item.first; + return true; + } + } + return false; +} + +bool UserManager::IsCurrentUser(int32_t userId) +{ + std::lock_guard guard(userLock_); + for (auto &item : displayIdMap_) { + if (item.second == userId) { + return true; + } + } + return false; +} + +void UserManager::SetCurrentUserId(int32_t userId, uint64_t displayId) +{ + std::lock_guard guard(userLock_); + displayIdMap_[displayId] = userId; +} +} +} \ No newline at end of file diff --git a/test/new_test/mock/user_controller/user_controller/user_manager.h b/test/new_test/mock/user_controller/user_controller/user_manager.h new file mode 100644 index 00000000000..5b9c7b67c76 --- /dev/null +++ b/test/new_test/mock/user_controller/user_controller/user_manager.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2025 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 OHOS_ABILITY_RUNTIME_USER_MANAGER_H +#define OHOS_ABILITY_RUNTIME_USER_MANAGER_H + +#include +#include "cpp/mutex.h" + +namespace OHOS { +namespace AbilityRuntime { +class UserManager final { +public: + UserManager& operator=(const UserManager&) = delete; + UserManager(const UserManager&) = delete; + virtual ~UserManager() = default; + static UserManager& GetInstance(); + + int32_t GetCurrentUserId(uint64_t displayId); + + bool GetDisplayIdByUserId(int32_t userId, uint64_t &displayId); + + bool IsCurrentUser(int32_t userId); + + void SetCurrentUserId(int32_t userId, uint64_t displayId); + + void ClearUserId(int32_t userId); + +private: + UserManager() = default; + + ffrt::mutex userLock_; + std::unordered_map displayIdMap_; +}; +} // namespace AbilityRuntime +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_USER_MANAGER_H \ No newline at end of file diff --git a/test/new_test/mock/user_event_handler/user_event_handler.h b/test/new_test/mock/user_event_handler/user_event_handler.h index e41e001bb5e..5eebf66667e 100644 --- a/test/new_test/mock/user_event_handler/user_event_handler.h +++ b/test/new_test/mock/user_event_handler/user_event_handler.h @@ -25,8 +25,7 @@ namespace AAFwk { class UserController; class UserEventHandler : public EventHandlerWrap { public: - UserEventHandler( - const std::shared_ptr &taskHandler, const std::weak_ptr &owner) {} + UserEventHandler(const std::shared_ptr &taskHandler) {} virtual ~UserEventHandler() {} diff --git a/test/new_test/unit_test/user_controller_unit_test/BUILD.gn b/test/new_test/unit_test/user_controller_unit_test/BUILD.gn index d7c3f2d7c81..196b62be070 100644 --- a/test/new_test/unit_test/user_controller_unit_test/BUILD.gn +++ b/test/new_test/unit_test/user_controller_unit_test/BUILD.gn @@ -61,6 +61,7 @@ ohos_unittest("user_controller_unit_test") { "../../mock/uri", "../../mock/user_event_handler", "../../mock/user_callback", + "../../mock/user_controller", "../../mock/want", "../../mock/want_params", ] @@ -73,6 +74,7 @@ ohos_unittest("user_controller_unit_test") { "../../mock/ability_manager_service/ability_manager_service.cpp", "../../mock/app_scheduler/app_scheduler.cpp", "../../mock/parameters/parameters.cpp", + "../../mock/user_controller/user_controller/user_manager.cpp", ] deps = [ diff --git a/test/new_test/unit_test/user_controller_unit_test/user_controller_unit_test.cpp b/test/new_test/unit_test/user_controller_unit_test/user_controller_unit_test.cpp index 1ca61ede911..7e73444a74a 100644 --- a/test/new_test/unit_test/user_controller_unit_test/user_controller_unit_test.cpp +++ b/test/new_test/unit_test/user_controller_unit_test/user_controller_unit_test.cpp @@ -146,7 +146,7 @@ HWTEST_F(UserControllerTest, Init_003, TestSize.Level1) std::shared_ptr controller = std::make_shared(); std::shared_ptr handler = std::make_shared(); OH_EXPECT_RET({handler}, AbilityManagerService, GetTaskHandler); - controller->eventHandler_ = std::make_shared(handler, controller); + controller->eventHandler_ = std::make_shared(handler); controller->Init(); EXPECT_NE(controller->eventHandler_, nullptr); } @@ -193,7 +193,8 @@ HWTEST_F(UserControllerTest, StartUser_001, TestSize.Level1) int32_t userId = -1; sptr callback = nullptr; bool isAppRecovery = 0; - EXPECT_EQ(controller->StartUser(userId, callback, isAppRecovery), AAFwk::INVALID_USERID_VALUE); + uint64_t displayId = 0; + EXPECT_EQ(controller->StartUser(userId, displayId, callback, isAppRecovery), AAFwk::INVALID_USERID_VALUE); } /** @@ -208,7 +209,8 @@ HWTEST_F(UserControllerTest, StartUser_002, TestSize.Level1) int32_t userId = -1; sptr callback = sptr::MakeSptr(); bool isAppRecovery = 0; - EXPECT_EQ(controller->StartUser(userId, callback, isAppRecovery), AAFwk::INVALID_USERID_VALUE); + uint64_t displayId = 0; + EXPECT_EQ(controller->StartUser(userId, displayId, callback, isAppRecovery), AAFwk::INVALID_USERID_VALUE); } /** @@ -223,7 +225,8 @@ HWTEST_F(UserControllerTest, StartUser_003, TestSize.Level1) int32_t userId = AAFwk::USER_ID_NO_HEAD; sptr callback = nullptr; bool isAppRecovery = 0; - EXPECT_EQ(controller->StartUser(userId, callback, isAppRecovery), AAFwk::INVALID_USERID_VALUE); + uint64_t displayId = 0; + EXPECT_EQ(controller->StartUser(userId, displayId, callback, isAppRecovery), AAFwk::INVALID_USERID_VALUE); } /** @@ -238,7 +241,8 @@ HWTEST_F(UserControllerTest, StartUser_004, TestSize.Level1) int32_t userId = AAFwk::USER_ID_NO_HEAD; sptr callback = sptr::MakeSptr(); bool isAppRecovery = 0; - EXPECT_EQ(controller->StartUser(userId, callback, isAppRecovery), AAFwk::INVALID_USERID_VALUE); + uint64_t displayId = 0; + EXPECT_EQ(controller->StartUser(userId, displayId, callback, isAppRecovery), AAFwk::INVALID_USERID_VALUE); } /** @@ -250,13 +254,12 @@ HWTEST_F(UserControllerTest, StartUser_004, TestSize.Level1) HWTEST_F(UserControllerTest, StartUser_005, TestSize.Level1) { std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 101; + uint64_t displayId = 0; int32_t userId = 101; - std::shared_ptr userItem = std::make_shared(userId); - controller->userItems_.insert({101, userItem}); + controller->SetCurrentUserId(userId, displayId); sptr callback = nullptr; bool isAppRecovery = 0; - EXPECT_EQ(controller->StartUser(userId, callback, isAppRecovery), ERR_OK); + EXPECT_EQ(controller->StartUser(userId, displayId, callback, isAppRecovery), ERR_OK); } /** @@ -268,13 +271,12 @@ HWTEST_F(UserControllerTest, StartUser_005, TestSize.Level1) HWTEST_F(UserControllerTest, StartUser_006, TestSize.Level1) { std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 101; + uint64_t displayId = 0; int32_t userId = 101; - std::shared_ptr userItem = std::make_shared(userId); - controller->userItems_.insert({101, userItem}); + controller->SetCurrentUserId(userId, displayId); sptr callback = sptr::MakeSptr(); bool isAppRecovery = 0; - EXPECT_EQ(controller->StartUser(userId, callback, isAppRecovery), ERR_OK); + EXPECT_EQ(controller->StartUser(userId, displayId, callback, isAppRecovery), ERR_OK); } /** @@ -286,16 +288,16 @@ HWTEST_F(UserControllerTest, StartUser_006, TestSize.Level1) HWTEST_F(UserControllerTest, StartUser_007, TestSize.Level1) { std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 100; - int32_t userId = 101; - std::shared_ptr userItem = std::make_shared(userId); - controller->userItems_.insert({101, userItem}); + uint64_t displayId = 0; + int32_t userId = 100; + controller->SetCurrentUserId(userId, displayId); + userId = 101; sptr callback = nullptr; bool isAppRecovery = 0; std::vector> expectOuter = {{false}}; OH_EXPECT_RET_AND_OUTPUT({0}, expectOuter, OsAccountManagerWrapper, IsOsAccountExists, const int, bool& isOsAccountExists); - EXPECT_EQ(controller->StartUser(userId, callback, isAppRecovery), AAFwk::INVALID_USERID_VALUE); + EXPECT_EQ(controller->StartUser(userId, displayId, callback, isAppRecovery), AAFwk::INVALID_USERID_VALUE); } /** @@ -307,16 +309,16 @@ HWTEST_F(UserControllerTest, StartUser_007, TestSize.Level1) HWTEST_F(UserControllerTest, StartUser_008, TestSize.Level1) { std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 100; - int32_t userId = 101; - std::shared_ptr userItem = std::make_shared(userId); - controller->userItems_.insert({101, userItem}); + uint64_t displayId = 0; + int32_t userId = 100; + controller->SetCurrentUserId(userId, displayId); + userId = 101; sptr callback = sptr::MakeSptr(); bool isAppRecovery = 0; std::vector> expectOuter = {{false}}; OH_EXPECT_RET_AND_OUTPUT({0}, expectOuter, OsAccountManagerWrapper, IsOsAccountExists, const int, bool& isOsAccountExists); - EXPECT_EQ(controller->StartUser(userId, callback, isAppRecovery), AAFwk::INVALID_USERID_VALUE); + EXPECT_EQ(controller->StartUser(userId, displayId, callback, isAppRecovery), AAFwk::INVALID_USERID_VALUE); } /** @@ -328,9 +330,11 @@ HWTEST_F(UserControllerTest, StartUser_008, TestSize.Level1) HWTEST_F(UserControllerTest, StartUser_009, TestSize.Level1) { std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 100; + uint64_t displayId = 0; + int32_t userId = 100; + controller->SetCurrentUserId(userId, displayId); controller->freezingNewUserId_ = 0; - int32_t userId = 101; + userId = 101; std::shared_ptr userItem = std::make_shared(userId); controller->userItems_.insert({userId, userItem}); sptr callback = sptr::MakeSptr(); @@ -339,7 +343,7 @@ HWTEST_F(UserControllerTest, StartUser_009, TestSize.Level1) OH_EXPECT_RET_AND_OUTPUT({0}, expectOuter, OsAccountManagerWrapper, IsOsAccountExists, const int, bool& isOsAccountExists); OH_EXPECT_RET({false}, SceneBoardJudgement, IsSceneBoardEnabled); - EXPECT_EQ(controller->StartUser(userId, callback, isAppRecovery), ERR_OK); + EXPECT_EQ(controller->StartUser(userId, displayId, callback, isAppRecovery), ERR_OK); EXPECT_EQ(controller->freezingNewUserId_, 101); } @@ -352,9 +356,11 @@ HWTEST_F(UserControllerTest, StartUser_009, TestSize.Level1) HWTEST_F(UserControllerTest, StartUser_010, TestSize.Level1) { std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 0; + uint64_t displayId = 0; + int32_t userId = 0; + controller->SetCurrentUserId(userId, displayId); controller->freezingNewUserId_ = 0; - int32_t userId = 101; + userId = 101; std::shared_ptr userItem = std::make_shared(userId); controller->userItems_.insert({userId, userItem}); sptr callback = sptr::MakeSptr(); @@ -363,7 +369,7 @@ HWTEST_F(UserControllerTest, StartUser_010, TestSize.Level1) OH_EXPECT_RET_AND_OUTPUT({0}, expectOuter, OsAccountManagerWrapper, IsOsAccountExists, const int, bool& isOsAccountExists); OH_EXPECT_RET({false}, SceneBoardJudgement, IsSceneBoardEnabled); - EXPECT_EQ(controller->StartUser(userId, callback, isAppRecovery), ERR_OK); + EXPECT_EQ(controller->StartUser(userId, displayId, callback, isAppRecovery), ERR_OK); EXPECT_EQ(controller->freezingNewUserId_, 0); } @@ -376,9 +382,11 @@ HWTEST_F(UserControllerTest, StartUser_010, TestSize.Level1) HWTEST_F(UserControllerTest, StartUser_011, TestSize.Level1) { std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 100; + uint64_t displayId = 0; + int32_t userId = 100; + controller->SetCurrentUserId(userId, displayId); controller->freezingNewUserId_ = 0; - int32_t userId = 101; + userId = 101; std::shared_ptr userItem = std::make_shared(userId); controller->userItems_.insert({userId, userItem}); sptr callback = sptr::MakeSptr(); @@ -387,7 +395,7 @@ HWTEST_F(UserControllerTest, StartUser_011, TestSize.Level1) OH_EXPECT_RET_AND_OUTPUT({0}, expectOuter, OsAccountManagerWrapper, IsOsAccountExists, const int, bool& isOsAccountExists); OH_EXPECT_RET({true}, SceneBoardJudgement, IsSceneBoardEnabled); - EXPECT_EQ(controller->StartUser(userId, callback, isAppRecovery), ERR_OK); + EXPECT_EQ(controller->StartUser(userId, displayId, callback, isAppRecovery), ERR_OK); EXPECT_EQ(controller->freezingNewUserId_, 0); } @@ -400,9 +408,11 @@ HWTEST_F(UserControllerTest, StartUser_011, TestSize.Level1) HWTEST_F(UserControllerTest, StartUser_012, TestSize.Level1) { std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 0; + uint64_t displayId = 0; + int32_t userId = 0; + controller->SetCurrentUserId(userId, displayId); controller->freezingNewUserId_ = 0; - int32_t userId = 101; + userId = 101; std::shared_ptr userItem = std::make_shared(userId); controller->userItems_.insert({userId, userItem}); sptr callback = sptr::MakeSptr(); @@ -411,7 +421,7 @@ HWTEST_F(UserControllerTest, StartUser_012, TestSize.Level1) OH_EXPECT_RET_AND_OUTPUT({0}, expectOuter, OsAccountManagerWrapper, IsOsAccountExists, const int, bool& isOsAccountExists); OH_EXPECT_RET({true}, SceneBoardJudgement, IsSceneBoardEnabled); - EXPECT_EQ(controller->StartUser(userId, callback, isAppRecovery), ERR_OK); + EXPECT_EQ(controller->StartUser(userId, displayId, callback, isAppRecovery), ERR_OK); EXPECT_EQ(controller->freezingNewUserId_, 0); } @@ -424,8 +434,10 @@ HWTEST_F(UserControllerTest, StartUser_012, TestSize.Level1) HWTEST_F(UserControllerTest, StartUser_013, TestSize.Level1) { std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 100; - int32_t userId = 101; + uint64_t displayId = 0; + int32_t userId = 100; + controller->SetCurrentUserId(userId, displayId); + userId = 101; std::shared_ptr userItem = std::make_shared(userId); userItem->SetState(AAFwk::STATE_STOPPING); controller->userItems_.insert({userId, userItem}); @@ -434,7 +446,7 @@ HWTEST_F(UserControllerTest, StartUser_013, TestSize.Level1) std::vector> expectOuter = {{true}}; OH_EXPECT_RET_AND_OUTPUT({0}, expectOuter, OsAccountManagerWrapper, IsOsAccountExists, const int, bool& isOsAccountExists); - EXPECT_EQ(controller->StartUser(userId, callback, isAppRecovery), ERR_DEAD_OBJECT); + EXPECT_EQ(controller->StartUser(userId, displayId, callback, isAppRecovery), ERR_DEAD_OBJECT); } /** @@ -446,8 +458,10 @@ HWTEST_F(UserControllerTest, StartUser_013, TestSize.Level1) HWTEST_F(UserControllerTest, StartUser_014, TestSize.Level1) { std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 100; - int32_t userId = 101; + uint64_t displayId = 0; + int32_t userId = 100; + controller->SetCurrentUserId(userId, displayId); + userId = 101; std::shared_ptr userItem = std::make_shared(userId); userItem->SetState(AAFwk::STATE_STOPPING); controller->userItems_.insert({userId, userItem}); @@ -456,7 +470,7 @@ HWTEST_F(UserControllerTest, StartUser_014, TestSize.Level1) std::vector> expectOuter = {{true}}; OH_EXPECT_RET_AND_OUTPUT({0}, expectOuter, OsAccountManagerWrapper, IsOsAccountExists, const int, bool& isOsAccountExists); - EXPECT_EQ(controller->StartUser(userId, callback, isAppRecovery), ERR_DEAD_OBJECT); + EXPECT_EQ(controller->StartUser(userId, displayId, callback, isAppRecovery), ERR_DEAD_OBJECT); } /** @@ -468,8 +482,10 @@ HWTEST_F(UserControllerTest, StartUser_014, TestSize.Level1) HWTEST_F(UserControllerTest, StartUser_015, TestSize.Level1) { std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 100; - int32_t userId = 101; + uint64_t displayId = 0; + int32_t userId = 100; + controller->SetCurrentUserId(userId, displayId); + userId = 101; std::shared_ptr userItem = std::make_shared(userId); userItem->SetState(AAFwk::STATE_SHUTDOWN); controller->userItems_.insert({userId, userItem}); @@ -478,7 +494,7 @@ HWTEST_F(UserControllerTest, StartUser_015, TestSize.Level1) std::vector> expectOuter = {{true}}; OH_EXPECT_RET_AND_OUTPUT({0}, expectOuter, OsAccountManagerWrapper, IsOsAccountExists, const int, bool& isOsAccountExists); - EXPECT_EQ(controller->StartUser(userId, callback, isAppRecovery), ERR_DEAD_OBJECT); + EXPECT_EQ(controller->StartUser(userId, displayId, callback, isAppRecovery), ERR_DEAD_OBJECT); } /** @@ -490,8 +506,10 @@ HWTEST_F(UserControllerTest, StartUser_015, TestSize.Level1) HWTEST_F(UserControllerTest, StartUser_016, TestSize.Level1) { std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 100; - int32_t userId = 101; + uint64_t displayId = 0; + int32_t userId = 100; + controller->SetCurrentUserId(userId, displayId); + userId = 101; std::shared_ptr userItem = std::make_shared(userId); userItem->SetState(AAFwk::STATE_SHUTDOWN); controller->userItems_.insert({userId, userItem}); @@ -500,7 +518,7 @@ HWTEST_F(UserControllerTest, StartUser_016, TestSize.Level1) std::vector> expectOuter = {{true}}; OH_EXPECT_RET_AND_OUTPUT({0}, expectOuter, OsAccountManagerWrapper, IsOsAccountExists, const int, bool& isOsAccountExists); - EXPECT_EQ(controller->StartUser(userId, callback, isAppRecovery), ERR_DEAD_OBJECT); + EXPECT_EQ(controller->StartUser(userId, displayId, callback, isAppRecovery), ERR_DEAD_OBJECT); } /** @@ -512,8 +530,10 @@ HWTEST_F(UserControllerTest, StartUser_016, TestSize.Level1) HWTEST_F(UserControllerTest, StartUser_017, TestSize.Level1) { std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 100; - int32_t userId = 101; + uint64_t displayId = 0; + int32_t userId = 100; + controller->SetCurrentUserId(userId, displayId); + userId = 101; std::shared_ptr userItem = std::make_shared(userId); userItem->SetState(AAFwk::STATE_BOOTING); controller->userItems_.insert({userId, userItem}); @@ -522,8 +542,8 @@ HWTEST_F(UserControllerTest, StartUser_017, TestSize.Level1) std::vector> expectOuter = {{true}}; OH_EXPECT_RET_AND_OUTPUT({0}, expectOuter, OsAccountManagerWrapper, IsOsAccountExists, const int, bool& isOsAccountExists); - EXPECT_NE(controller->StartUser(userId, callback, isAppRecovery), ERR_DEAD_OBJECT); - EXPECT_EQ(controller->currentUserId_, 101); + EXPECT_NE(controller->StartUser(userId, displayId, callback, isAppRecovery), ERR_DEAD_OBJECT); + EXPECT_EQ(controller->GetCurrentUserId(displayId), 101); } /** @@ -574,10 +594,9 @@ HWTEST_F(UserControllerTest, StopUser_003, TestSize.Level1) HWTEST_F(UserControllerTest, StopUser_004, TestSize.Level1) { std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 101; + uint64_t displayId = 0; int32_t userId = 101; - std::shared_ptr userItem = std::make_shared(userId); - controller->userItems_.insert({userId, userItem}); + controller->SetCurrentUserId(userId, displayId); EXPECT_EQ(controller->StopUser(userId), 0); } @@ -590,8 +609,10 @@ HWTEST_F(UserControllerTest, StopUser_004, TestSize.Level1) HWTEST_F(UserControllerTest, StopUser_005, TestSize.Level1) { std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 100; - int32_t userId = 101; + uint64_t displayId = 0; + int32_t userId = 100; + controller->SetCurrentUserId(userId, displayId); + userId = 101; std::vector> expectOuter = {{false}}; OH_EXPECT_RET_AND_OUTPUT({0}, expectOuter, OsAccountManagerWrapper, IsOsAccountExists, const int, bool& isOsAccountExists); @@ -607,8 +628,10 @@ HWTEST_F(UserControllerTest, StopUser_005, TestSize.Level1) HWTEST_F(UserControllerTest, StopUser_006, TestSize.Level1) { std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 100; - int32_t userId = 101; + uint64_t displayId = 0; + int32_t userId = 100; + controller->SetCurrentUserId(userId, displayId); + userId = 101; std::vector> expectOuter = {{true}}; OH_EXPECT_RET_AND_OUTPUT({0}, expectOuter, OsAccountManagerWrapper, IsOsAccountExists, const int, bool& isOsAccountExists); @@ -627,8 +650,10 @@ HWTEST_F(UserControllerTest, StopUser_006, TestSize.Level1) HWTEST_F(UserControllerTest, StopUser_007, TestSize.Level1) { std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 100; - int32_t userId = 101; + uint64_t displayId = 0; + int32_t userId = 100; + controller->SetCurrentUserId(userId, displayId); + userId = 101; std::vector> expectOuter = {{true}}; OH_EXPECT_RET_AND_OUTPUT({0}, expectOuter, OsAccountManagerWrapper, IsOsAccountExists, const int, bool& isOsAccountExists); @@ -647,8 +672,10 @@ HWTEST_F(UserControllerTest, StopUser_007, TestSize.Level1) HWTEST_F(UserControllerTest, StopUser_008, TestSize.Level1) { std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 100; - int32_t userId = 101; + uint64_t displayId = 0; + int32_t userId = 100; + controller->SetCurrentUserId(userId, displayId); + userId = 101; std::vector> expectOuter = {{true}}; OH_EXPECT_RET_AND_OUTPUT({0}, expectOuter, OsAccountManagerWrapper, IsOsAccountExists, const int, bool& isOsAccountExists); @@ -667,8 +694,10 @@ HWTEST_F(UserControllerTest, StopUser_008, TestSize.Level1) HWTEST_F(UserControllerTest, StopUser_009, TestSize.Level1) { std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 100; - int32_t userId = 101; + uint64_t displayId = 0; + int32_t userId = 100; + controller->SetCurrentUserId(userId, displayId); + userId = 101; std::vector> expectOuter = {{true}}; OH_EXPECT_RET_AND_OUTPUT({0}, expectOuter, OsAccountManagerWrapper, IsOsAccountExists, const int, bool& isOsAccountExists); @@ -743,8 +772,10 @@ HWTEST_F(UserControllerTest, LogoutUser_004, TestSize.Level1) HWTEST_F(UserControllerTest, LogoutUser_005, TestSize.Level1) { std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 100; - int32_t userId = 101; + uint64_t displayId = 0; + int32_t userId = 100; + controller->SetCurrentUserId(userId, displayId); + userId = 101; sptr callback = nullptr; std::vector> expectOuter = {{false}}; OH_EXPECT_RET_AND_OUTPUT({0}, expectOuter, OsAccountManagerWrapper, @@ -761,8 +792,10 @@ HWTEST_F(UserControllerTest, LogoutUser_005, TestSize.Level1) HWTEST_F(UserControllerTest, LogoutUser_006, TestSize.Level1) { std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 100; - int32_t userId = 101; + uint64_t displayId = 0; + int32_t userId = 100; + controller->SetCurrentUserId(userId, displayId); + userId = 101; sptr callback = sptr::MakeSptr(); std::vector> expectOuter = {{false}}; OH_EXPECT_RET_AND_OUTPUT({0}, expectOuter, OsAccountManagerWrapper, @@ -779,8 +812,10 @@ HWTEST_F(UserControllerTest, LogoutUser_006, TestSize.Level1) HWTEST_F(UserControllerTest, LogoutUser_007, TestSize.Level1) { std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 100; - int32_t userId = 101; + uint64_t displayId = 0; + int32_t userId = 100; + controller->SetCurrentUserId(userId, displayId); + userId = 101; sptr callback = sptr::MakeSptr(); std::vector> expectOuter = {{true}}; OH_EXPECT_RET_AND_OUTPUT({0}, expectOuter, OsAccountManagerWrapper, @@ -799,8 +834,10 @@ HWTEST_F(UserControllerTest, LogoutUser_007, TestSize.Level1) HWTEST_F(UserControllerTest, LogoutUser_008, TestSize.Level1) { std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 100; - int32_t userId = 101; + uint64_t displayId = 0; + int32_t userId = 100; + controller->SetCurrentUserId(userId, displayId); + userId = 101; sptr callback = sptr::MakeSptr(); std::vector> expectOuter = {{true}}; OH_EXPECT_RET_AND_OUTPUT({0}, expectOuter, OsAccountManagerWrapper, @@ -818,8 +855,9 @@ HWTEST_F(UserControllerTest, LogoutUser_008, TestSize.Level1) HWTEST_F(UserControllerTest, LogoutUser_009, TestSize.Level1) { std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 100; + uint64_t displayId = 0; int32_t userId = 100; + controller->SetCurrentUserId(userId, displayId); sptr callback = sptr::MakeSptr(); std::vector> expectOuter = {{true}}; OH_EXPECT_RET_AND_OUTPUT({0}, expectOuter, OsAccountManagerWrapper, @@ -827,7 +865,7 @@ HWTEST_F(UserControllerTest, LogoutUser_009, TestSize.Level1) std::shared_ptr userItem = std::make_shared(userId); controller->userItems_.insert({userId, userItem}); EXPECT_EQ(controller->LogoutUser(userId, callback), 0); - EXPECT_EQ(controller->currentUserId_, 0); + EXPECT_EQ(controller->GetCurrentUserId(displayId), 0); } /** @@ -839,8 +877,10 @@ HWTEST_F(UserControllerTest, LogoutUser_009, TestSize.Level1) HWTEST_F(UserControllerTest, LogoutUser_010, TestSize.Level1) { std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 100; - int32_t userId = 101; + uint64_t displayId = 0; + int32_t userId = 100; + controller->SetCurrentUserId(userId, displayId); + userId = 101; sptr callback = sptr::MakeSptr(); std::vector> expectOuter = {{true}}; OH_EXPECT_RET_AND_OUTPUT({0}, expectOuter, OsAccountManagerWrapper, @@ -848,7 +888,7 @@ HWTEST_F(UserControllerTest, LogoutUser_010, TestSize.Level1) std::shared_ptr userItem = std::make_shared(userId); controller->userItems_.insert({userId, userItem}); EXPECT_EQ(controller->LogoutUser(userId, callback), 0); - EXPECT_EQ(controller->currentUserId_, 100); + EXPECT_EQ(controller->GetCurrentUserId(displayId), 100); } /** @@ -859,34 +899,10 @@ HWTEST_F(UserControllerTest, LogoutUser_010, TestSize.Level1) HWTEST_F(UserControllerTest, GetCurrentUserId_001, TestSize.Level1) { std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 100; - EXPECT_EQ(controller->GetCurrentUserId(), 100); -} - -/** - * @tc.name: GetUserItem_001 - * @tc.desc: Verify GetUserItem call. - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, GetUserItem_001, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - int32_t userId = 100; - std::shared_ptr userItem = std::make_shared(userId); - controller->userItems_.insert({userId, userItem}); - EXPECT_EQ(controller->GetUserItem(userId), userItem); -} - -/** - * @tc.name: GetUserItem_002 - * @tc.desc: Verify GetUserItem call. - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, GetUserItem_002, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); + uint64_t displayId = 0; int32_t userId = 100; - EXPECT_EQ(controller->GetUserItem(userId), nullptr); + controller->SetCurrentUserId(userId, displayId); + EXPECT_EQ(controller->GetCurrentUserId(displayId), 100); } /** @@ -987,10 +1003,12 @@ HWTEST_F(UserControllerTest, GetOrCreateUserItem_002, TestSize.Level1) HWTEST_F(UserControllerTest, SetCurrentUserId_001, TestSize.Level1) { std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 100; - int32_t userId = 101; - controller->SetCurrentUserId(userId); - EXPECT_EQ(controller->currentUserId_, 101); + uint64_t displayId = 0; + int32_t userId = 100; + controller->SetCurrentUserId(userId, displayId); + userId = 101; + controller->SetCurrentUserId(userId, displayId); + EXPECT_EQ(controller->GetCurrentUserId(displayId), 101); } /** @@ -1001,15 +1019,17 @@ HWTEST_F(UserControllerTest, SetCurrentUserId_001, TestSize.Level1) HWTEST_F(UserControllerTest, MoveUserToForeground_001, TestSize.Level1) { std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 100; - int32_t userId = 101; - OH_EXPECT_RET({0}, AbilityManagerService, SwitchToUser, int32_t, int32_t, + uint64_t displayId = 0; + int32_t userId = 100; + controller->SetCurrentUserId(userId, displayId); + userId = 101; + OH_EXPECT_RET({0}, AbilityManagerService, SwitchToUser, int32_t, int32_t, uint64_t, sptr, bool isAppRecovery = false); int32_t oldUserId = 100; int32_t newUserId = 101; sptr callback = nullptr; bool isAppRecovery = false; - EXPECT_EQ(controller->MoveUserToForeground(oldUserId, newUserId, callback, isAppRecovery), ERR_OK); + EXPECT_EQ(controller->MoveUserToForeground(oldUserId, newUserId, displayId, callback, isAppRecovery), ERR_OK); } /** @@ -1020,79 +1040,17 @@ HWTEST_F(UserControllerTest, MoveUserToForeground_001, TestSize.Level1) HWTEST_F(UserControllerTest, MoveUserToForeground_002, TestSize.Level1) { std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 100; - int32_t userId = 101; - OH_EXPECT_RET({1}, AbilityManagerService, SwitchToUser, int32_t, int32_t, + uint64_t displayId = 0; + int32_t userId = 100; + controller->SetCurrentUserId(userId, displayId); + userId = 101; + OH_EXPECT_RET({1}, AbilityManagerService, SwitchToUser, int32_t, int32_t, uint64_t, sptr, bool isAppRecovery = false); int32_t oldUserId = 100; int32_t newUserId = 101; sptr callback = nullptr; bool isAppRecovery = false; - EXPECT_EQ(controller->MoveUserToForeground(oldUserId, newUserId, callback, isAppRecovery), 1); -} - -/** - * @tc.name: UserBootDone_001 - * @tc.desc: Verify UserBootDone call. - * Branch item == nullptr - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, UserBootDone_001, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - std::shared_ptr item = nullptr; - controller->UserBootDone(item); - EXPECT_LOG_MATCH(LOG_ERROR, AAFwkTag::ABILITYMGR, "user_controller.cpp", "null item"); -} - -/** - * @tc.name: UserBootDone_002 - * @tc.desc: Verify UserBootDone call. - * Branch userId invalid - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, UserBootDone_002, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - std::shared_ptr item = std::make_shared(101); - AAFwk::UserState userState = AAFwk::UserState::STATE_BOOTING; - item->SetState(userState); - controller->UserBootDone(item); - EXPECT_EQ(item->GetState(), AAFwk::UserState::STATE_BOOTING); -} - -/** - * @tc.name: UserBootDone_003 - * @tc.desc: Verify UserBootDone call. - * Branch item not match - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, UserBootDone_003, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - std::shared_ptr item1 = std::make_shared(101); - std::shared_ptr item2 = std::make_shared(101); - controller->userItems_.insert({101, item2}); - AAFwk::UserState userState = AAFwk::UserState::STATE_BOOTING; - item1->SetState(userState); - controller->UserBootDone(item1); - EXPECT_EQ(item1->GetState(), AAFwk::UserState::STATE_BOOTING); -} - -/** - * @tc.name: UserBootDone_004 - * @tc.desc: Verify UserBootDone call. - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, UserBootDone_004, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - std::shared_ptr item = std::make_shared(101); - controller->userItems_.insert({101, item}); - AAFwk::UserState userState = AAFwk::UserState::STATE_BOOTING; - item->SetState(userState); - controller->UserBootDone(item); - EXPECT_EQ(item->GetState(), AAFwk::UserState::STATE_STARTED); + EXPECT_EQ(controller->MoveUserToForeground(oldUserId, newUserId, displayId, callback, isAppRecovery), 1); } /** @@ -1151,7 +1109,7 @@ HWTEST_F(UserControllerTest, BroadcastUserStopped_001, TestSize.Level1) HWTEST_F(UserControllerTest, SendSystemUserStart_001, TestSize.Level1) { std::shared_ptr controller = std::make_shared(); - controller->eventHandler_ = std::make_shared(nullptr, controller); + controller->eventHandler_ = std::make_shared(nullptr); controller->SendSystemUserStart(100); EXPECT_LOG_MATCH(LOG_DEBUG, AAFwkTag::ABILITYMGR, "user_controller.cpp", "SendEvent(EVENT_SYSTEM_USER_START)"); } @@ -1313,7 +1271,7 @@ HWTEST_F(UserControllerTest, ProcessEvent_008, TestSize.Level1) HWTEST_F(UserControllerTest, SendSystemUserCurrent_001, TestSize.Level1) { std::shared_ptr controller = std::make_shared(); - controller->eventHandler_ = std::make_shared(nullptr, controller); + controller->eventHandler_ = std::make_shared(nullptr); controller->SendSystemUserCurrent(100, 101); EXPECT_LOG_MATCH(LOG_DEBUG, AAFwkTag::ABILITYMGR, "user_controller.cpp", "SendEvent(EVENT_SYSTEM_USER_CURRENT)"); } @@ -1339,7 +1297,7 @@ HWTEST_F(UserControllerTest, SendSystemUserCurrent_002, TestSize.Level1) HWTEST_F(UserControllerTest, SendReportUserSwitch_001, TestSize.Level1) { std::shared_ptr controller = std::make_shared(); - controller->eventHandler_ = std::make_shared(nullptr, controller); + controller->eventHandler_ = std::make_shared(nullptr); std::shared_ptr usrItem = nullptr; controller->SendReportUserSwitch(100, 101, usrItem); EXPECT_LOG_MATCH(LOG_DEBUG, AAFwkTag::ABILITYMGR, "user_controller.cpp", "SendEvent(EVENT_REPORT_USER_SWITCH)"); @@ -1367,7 +1325,7 @@ HWTEST_F(UserControllerTest, SendReportUserSwitch_002, TestSize.Level1) HWTEST_F(UserControllerTest, SendUserSwitchTimeout_001, TestSize.Level1) { std::shared_ptr controller = std::make_shared(); - controller->eventHandler_ = std::make_shared(nullptr, controller); + controller->eventHandler_ = std::make_shared(nullptr); std::shared_ptr usrItem = nullptr; controller->SendUserSwitchTimeout(100, 101, usrItem); EXPECT_LOG_MATCH(LOG_DEBUG, AAFwkTag::ABILITYMGR, "user_controller.cpp", "SendEvent(EVENT_USER_SWITCH_TIMEOUT)"); @@ -1395,7 +1353,7 @@ HWTEST_F(UserControllerTest, SendUserSwitchTimeout_002, TestSize.Level1) HWTEST_F(UserControllerTest, SendContinueUserSwitch_001, TestSize.Level1) { std::shared_ptr controller = std::make_shared(); - controller->eventHandler_ = std::make_shared(nullptr, controller); + controller->eventHandler_ = std::make_shared(nullptr); std::shared_ptr usrItem = nullptr; controller->SendContinueUserSwitch(100, 101, usrItem); EXPECT_LOG_MATCH(LOG_DEBUG, AAFwkTag::ABILITYMGR, "user_controller.cpp", "SendEvent(EVENT_CONTINUE_USER_SWITCH)"); @@ -1423,7 +1381,7 @@ HWTEST_F(UserControllerTest, SendContinueUserSwitch_002, TestSize.Level1) HWTEST_F(UserControllerTest, SendUserSwitchDone_001, TestSize.Level1) { std::shared_ptr controller = std::make_shared(); - controller->eventHandler_ = std::make_shared(nullptr, controller); + controller->eventHandler_ = std::make_shared(nullptr); controller->SendUserSwitchDone(100); EXPECT_LOG_MATCH(LOG_DEBUG, AAFwkTag::ABILITYMGR, "user_controller.cpp", "SendEvent(EVENT_REPORT_USER_SWITCH_DONE)"); @@ -1450,7 +1408,7 @@ HWTEST_F(UserControllerTest, SendUserSwitchDone_002, TestSize.Level1) HWTEST_F(UserControllerTest, HandleContinueUserSwitch_001, TestSize.Level1) { std::shared_ptr controller = std::make_shared(); - controller->eventHandler_ = std::make_shared(nullptr, controller); + controller->eventHandler_ = std::make_shared(nullptr); OH_EXPECT_RET({false}, SceneBoardJudgement, IsSceneBoardEnabled); std::shared_ptr usrItem = nullptr; controller->HandleContinueUserSwitch(100, 101, usrItem); @@ -1466,7 +1424,7 @@ HWTEST_F(UserControllerTest, HandleContinueUserSwitch_001, TestSize.Level1) HWTEST_F(UserControllerTest, HandleContinueUserSwitch_002, TestSize.Level1) { std::shared_ptr controller = std::make_shared(); - controller->eventHandler_ = std::make_shared(nullptr, controller); + controller->eventHandler_ = std::make_shared(nullptr); OH_EXPECT_RET({true}, SceneBoardJudgement, IsSceneBoardEnabled); std::shared_ptr usrItem = nullptr; controller->HandleContinueUserSwitch(100, 101, usrItem); diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 5812d791db0..24302c87e8f 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -480,6 +480,7 @@ group("unittest") { "uri_utils_test:unittest", "user_controller_test:unittest", "user_event_handler_test:unittest", + "user_manager_test:unittest", "user_record_manager_test:unittest", "want_agent_helper_test:unittest", "want_agent_info_test:unittest", diff --git a/test/unittest/ability_auto_startup_service_second_test/BUILD.gn b/test/unittest/ability_auto_startup_service_second_test/BUILD.gn index 03625ff86a4..fd94c800549 100644 --- a/test/unittest/ability_auto_startup_service_second_test/BUILD.gn +++ b/test/unittest/ability_auto_startup_service_second_test/BUILD.gn @@ -52,6 +52,7 @@ ohos_unittest("ability_auto_startup_service_second_test") { "${ability_runtime_native_path}/ability/native:auto_startup_callback", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:app_util", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ diff --git a/test/unittest/ability_auto_startup_service_test/BUILD.gn b/test/unittest/ability_auto_startup_service_test/BUILD.gn index d2234861585..06467c5371d 100644 --- a/test/unittest/ability_auto_startup_service_test/BUILD.gn +++ b/test/unittest/ability_auto_startup_service_test/BUILD.gn @@ -48,6 +48,7 @@ ohos_unittest("ability_auto_startup_service_test") { "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:app_util", "${ability_runtime_services_path}/common:perm_verification", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ diff --git a/test/unittest/ability_auto_startup_service_test/ability_auto_startup_service_test.cpp b/test/unittest/ability_auto_startup_service_test/ability_auto_startup_service_test.cpp index 1af25cf1916..6308bfa55dd 100644 --- a/test/unittest/ability_auto_startup_service_test/ability_auto_startup_service_test.cpp +++ b/test/unittest/ability_auto_startup_service_test/ability_auto_startup_service_test.cpp @@ -1028,70 +1028,5 @@ HWTEST_F(AbilityAutoStartupServiceTest, IsTargetExtension_002, TestSize.Level1) EXPECT_FALSE(result); GTEST_LOG_(INFO) << "AbilityAutoStartupServiceTest IsTargetExtension_002 end"; } - -/* - * Feature: AbilityAutoStartupService - * Function: GetValidUserId - * SubFunction: NA - * FunctionPoints: AbilityAutoStartupService GetValidUserId - */ -HWTEST_F(AbilityAutoStartupServiceTest, GetValidUserId_001, TestSize.Level1) -{ - GTEST_LOG_(INFO) << "AbilityAutoStartupServiceTest GetValidUserId_001 start"; - auto abilityAutoStartupService = std::make_shared(); - EXPECT_NE(abilityAutoStartupService, nullptr); - int32_t userId = -1; - abilityAutoStartupService->GetValidUserId(userId); - GTEST_LOG_(INFO) << "AbilityAutoStartupServiceTest GetValidUserId_001 end"; -} - -/* - * Feature: AbilityAutoStartupService - * Function: GetValidUserId - * SubFunction: NA - * FunctionPoints: AbilityAutoStartupService GetValidUserId - */ -HWTEST_F(AbilityAutoStartupServiceTest, GetValidUserId_002, TestSize.Level1) -{ - GTEST_LOG_(INFO) << "AbilityAutoStartupServiceTest GetValidUserId_002 start"; - auto abilityAutoStartupService = std::make_shared(); - EXPECT_NE(abilityAutoStartupService, nullptr); - int32_t userId = 100; - auto validUserId = abilityAutoStartupService->GetValidUserId(userId); - EXPECT_EQ(userId, validUserId); - GTEST_LOG_(INFO) << "AbilityAutoStartupServiceTest GetValidUserId_002 end"; -} - -/* - * Feature: AbilityAutoStartupService - * Function: GetValidUserId - * SubFunction: NA - * FunctionPoints: AbilityAutoStartupService GetValidUserId - */ -HWTEST_F(AbilityAutoStartupServiceTest, GetValidUserId_003, TestSize.Level1) -{ - GTEST_LOG_(INFO) << "AbilityAutoStartupServiceTest GetValidUserId_003 start"; - auto abilityAutoStartupService = std::make_shared(); - EXPECT_NE(abilityAutoStartupService, nullptr); - int32_t userId = 0; - abilityAutoStartupService->GetValidUserId(userId); - GTEST_LOG_(INFO) << "AbilityAutoStartupServiceTest GetValidUserId_003 end"; -} - -/* - * Feature: AbilityAutoStartupService - * Function: GetValidUserId - * SubFunction: NA - * FunctionPoints: AbilityAutoStartupService GetValidUserId - */ -HWTEST_F(AbilityAutoStartupServiceTest, GetValidUserId_004, TestSize.Level1) -{ - GTEST_LOG_(INFO) << "AbilityAutoStartupServiceTest GetValidUserId_004 start"; - auto abilityAutoStartupService = std::make_shared(); - EXPECT_NE(abilityAutoStartupService, nullptr); - int32_t userId = 1; - abilityAutoStartupService->GetValidUserId(userId); - GTEST_LOG_(INFO) << "AbilityAutoStartupServiceTest GetValidUserId_004 end"; -} } // namespace AAFwk } // 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 1bd537f1e69..a0706aba781 100644 --- a/test/unittest/ability_auto_startup_service_third_test/BUILD.gn +++ b/test/unittest/ability_auto_startup_service_third_test/BUILD.gn @@ -39,6 +39,7 @@ ohos_unittest("ability_auto_startup_service_third_test") { "${ability_runtime_innerkits_path}/ability_manager:ability_manager", "${ability_runtime_native_path}/ability:ability_context_native", "${ability_runtime_native_path}/ability/native:auto_startup_callback", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ diff --git a/test/unittest/ability_manager_client_branch_second_test/ability_manager_stub_mock_second_test.h b/test/unittest/ability_manager_client_branch_second_test/ability_manager_stub_mock_second_test.h index 5ed51e73603..8979dcce4dc 100644 --- a/test/unittest/ability_manager_client_branch_second_test/ability_manager_stub_mock_second_test.h +++ b/test/unittest/ability_manager_client_branch_second_test/ability_manager_stub_mock_second_test.h @@ -220,7 +220,7 @@ public: return; } - int StartUser(int userId, sptr callback, bool isAppRecovery) override + int StartUser(int userId, uint64_t displayId, sptr callback, bool isAppRecovery) override { return 0; } diff --git a/test/unittest/ability_manager_client_branch_test/ability_manager_client_branch_test.cpp b/test/unittest/ability_manager_client_branch_test/ability_manager_client_branch_test.cpp index aace3c78645..63b21f13aa1 100644 --- a/test/unittest/ability_manager_client_branch_test/ability_manager_client_branch_test.cpp +++ b/test/unittest/ability_manager_client_branch_test/ability_manager_client_branch_test.cpp @@ -959,8 +959,9 @@ HWTEST_F(AbilityManagerClientBranchTest, StopSyncRemoteMissions_0100, TestSize.L HWTEST_F(AbilityManagerClientBranchTest, StartUser_0100, TestSize.Level1) { GTEST_LOG_(INFO) << "StartUser_0100 start"; - int userId = 1; - auto result = client_->StartUser(userId, nullptr); + int userId = 200; + uint64_t displayId = 0; + auto result = client_->StartUser(userId, displayId, nullptr); EXPECT_EQ(result, ERR_OK); GTEST_LOG_(INFO) << "StartUser_0100 end"; diff --git a/test/unittest/ability_manager_client_branch_test/ability_manager_stub_mock_test.h b/test/unittest/ability_manager_client_branch_test/ability_manager_stub_mock_test.h index 660d1a74450..c6d8e9c8bc7 100644 --- a/test/unittest/ability_manager_client_branch_test/ability_manager_stub_mock_test.h +++ b/test/unittest/ability_manager_client_branch_test/ability_manager_stub_mock_test.h @@ -239,7 +239,7 @@ public: return; } - int StartUser(int userId, sptr callback, bool isAppRecovery) override + int StartUser(int userId, uint64_t displayId, sptr callback, bool isAppRecovery) override { return 0; } diff --git a/test/unittest/ability_manager_client_branch_third_test/mock/include/ability_manager_stub_mock_test.h b/test/unittest/ability_manager_client_branch_third_test/mock/include/ability_manager_stub_mock_test.h index b27b0e36f80..2206897b0b0 100644 --- a/test/unittest/ability_manager_client_branch_third_test/mock/include/ability_manager_stub_mock_test.h +++ b/test/unittest/ability_manager_client_branch_third_test/mock/include/ability_manager_stub_mock_test.h @@ -203,7 +203,7 @@ public: return; } - int StartUser(int userId, sptr callback, bool isAppRecovery) override + int StartUser(int userId, uint64_t displayId, sptr callback, bool isAppRecovery) override { return 0; } diff --git a/test/unittest/ability_manager_proxy_fifth_test/ability_manager_stub_mock.h b/test/unittest/ability_manager_proxy_fifth_test/ability_manager_stub_mock.h index b9559de09e7..2c53c7a2fed 100644 --- a/test/unittest/ability_manager_proxy_fifth_test/ability_manager_stub_mock.h +++ b/test/unittest/ability_manager_proxy_fifth_test/ability_manager_stub_mock.h @@ -236,7 +236,7 @@ public: return; } - int StartUser(int userId, sptr callback, bool isAppRecovery) override + int StartUser(int userId, uint64_t displayId, sptr callback, bool isAppRecovery) override { return 0; } diff --git a/test/unittest/ability_manager_proxy_fourth_test/ability_manager_stub_mock.h b/test/unittest/ability_manager_proxy_fourth_test/ability_manager_stub_mock.h index 9c28fbf1e34..08386f6c6a8 100644 --- a/test/unittest/ability_manager_proxy_fourth_test/ability_manager_stub_mock.h +++ b/test/unittest/ability_manager_proxy_fourth_test/ability_manager_stub_mock.h @@ -236,7 +236,7 @@ public: return; } - int StartUser(int userId, sptr callback, bool isAppRecovery) override + int StartUser(int userId, uint64_t displayId, sptr callback, bool isAppRecovery) override { return 0; } diff --git a/test/unittest/ability_manager_proxy_second_test/ability_manager_stub_mock.h b/test/unittest/ability_manager_proxy_second_test/ability_manager_stub_mock.h index 6d842980b18..18143f6d6a3 100644 --- a/test/unittest/ability_manager_proxy_second_test/ability_manager_stub_mock.h +++ b/test/unittest/ability_manager_proxy_second_test/ability_manager_stub_mock.h @@ -236,7 +236,7 @@ public: return; } - int StartUser(int userId, sptr callback, bool isAppRecovery) override + int StartUser(int userId, uint64_t displayId, sptr callback, bool isAppRecovery) override { return 0; } diff --git a/test/unittest/ability_manager_proxy_sixth_test/ability_manager_stub_mock.h b/test/unittest/ability_manager_proxy_sixth_test/ability_manager_stub_mock.h index 6d842980b18..18143f6d6a3 100644 --- a/test/unittest/ability_manager_proxy_sixth_test/ability_manager_stub_mock.h +++ b/test/unittest/ability_manager_proxy_sixth_test/ability_manager_stub_mock.h @@ -236,7 +236,7 @@ public: return; } - int StartUser(int userId, sptr callback, bool isAppRecovery) override + int StartUser(int userId, uint64_t displayId, sptr callback, bool isAppRecovery) override { return 0; } diff --git a/test/unittest/ability_manager_proxy_test/ability_manager_proxy_test.cpp b/test/unittest/ability_manager_proxy_test/ability_manager_proxy_test.cpp index 49af01d529d..96a67d4c178 100644 --- a/test/unittest/ability_manager_proxy_test/ability_manager_proxy_test.cpp +++ b/test/unittest/ability_manager_proxy_test/ability_manager_proxy_test.cpp @@ -1680,8 +1680,9 @@ HWTEST_F(AbilityManagerProxyTest, AbilityManagerProxy_StartUser_001, TestSize.Le EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) .Times(1) .WillOnce(Invoke(mock_.GetRefPtr(), &AbilityManagerStubMock::InvokeSendRequest)); - int userId = 1; - auto res = proxy_->StartUser(userId, nullptr); + int userId = 200; + uint64_t displayId = 0; + auto res = proxy_->StartUser(userId, displayId, nullptr); EXPECT_EQ(static_cast(AbilityManagerInterfaceCode::START_USER), mock_->code_); EXPECT_EQ(res, NO_ERROR); } diff --git a/test/unittest/ability_manager_proxy_test/ability_manager_stub_mock.h b/test/unittest/ability_manager_proxy_test/ability_manager_stub_mock.h index 4cb5157ecff..8461bfaee1c 100644 --- a/test/unittest/ability_manager_proxy_test/ability_manager_stub_mock.h +++ b/test/unittest/ability_manager_proxy_test/ability_manager_stub_mock.h @@ -244,7 +244,7 @@ public: return; } - int StartUser(int userId, sptr callback, bool isAppRecovery) override + int StartUser(int userId, uint64_t displayId, sptr callback, bool isAppRecovery) override { return 0; } diff --git a/test/unittest/ability_manager_proxy_third_test/ability_manager_proxy_third_test.cpp b/test/unittest/ability_manager_proxy_third_test/ability_manager_proxy_third_test.cpp index 1a48b715b98..dbb3019efdf 100644 --- a/test/unittest/ability_manager_proxy_third_test/ability_manager_proxy_third_test.cpp +++ b/test/unittest/ability_manager_proxy_third_test/ability_manager_proxy_third_test.cpp @@ -1019,7 +1019,8 @@ HWTEST_F(AbilityManagerProxyTest, StartUser_3000, TestSize.Level1) EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) .Times(1) .WillOnce(Invoke(mock_.GetRefPtr(), &AbilityManagerStubMock::InvokeErrorSendRequest)); - int32_t result = proxy_->StartUser(1, callback, false); + int32_t userId = 10000; + int32_t result = proxy_->StartUser(userId, 0, callback, false); EXPECT_EQ(static_cast(AbilityManagerInterfaceCode::START_USER), mock_->code_); EXPECT_NE(result, NO_ERROR); @@ -1029,7 +1030,7 @@ HWTEST_F(AbilityManagerProxyTest, StartUser_3000, TestSize.Level1) sptr mockIUserCallback = new MockIUserCallback(); mockIUserCallback->iremoteObject_ = sptr(new (std::nothrow) MockAbilityToken()); callback = mockIUserCallback; - result = proxy_->StartUser(1, callback, false); + result = proxy_->StartUser(userId, 0, callback, false); EXPECT_EQ(static_cast(AbilityManagerInterfaceCode::START_USER), mock_->code_); EXPECT_EQ(result, NO_ERROR); @@ -1049,7 +1050,8 @@ HWTEST_F(AbilityManagerProxyTest, StopUser_3100, TestSize.Level1) EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) .Times(1) .WillOnce(Invoke(mock_.GetRefPtr(), &AbilityManagerStubMock::InvokeErrorSendRequest)); - int32_t result = proxy_->StopUser(1, callback); + int32_t userId = 10000; + int32_t result = proxy_->StopUser(userId, callback); EXPECT_EQ(static_cast(AbilityManagerInterfaceCode::STOP_USER), mock_->code_); EXPECT_NE(result, NO_ERROR); @@ -1059,7 +1061,7 @@ HWTEST_F(AbilityManagerProxyTest, StopUser_3100, TestSize.Level1) sptr mockIUserCallback = new MockIUserCallback(); mockIUserCallback->iremoteObject_ = sptr(new (std::nothrow) MockAbilityToken()); callback = mockIUserCallback; - result = proxy_->StopUser(1, callback); + result = proxy_->StopUser(userId, callback); EXPECT_EQ(static_cast(AbilityManagerInterfaceCode::STOP_USER), mock_->code_); EXPECT_EQ(result, NO_ERROR); @@ -1079,7 +1081,8 @@ HWTEST_F(AbilityManagerProxyTest, LogoutUser_3200, TestSize.Level1) EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) .Times(1) .WillOnce(Invoke(mock_.GetRefPtr(), &AbilityManagerStubMock::InvokeErrorSendRequest)); - int32_t result = proxy_->LogoutUser(1, callback); + int32_t userId = 10000; + int32_t result = proxy_->LogoutUser(userId, callback); EXPECT_EQ(static_cast(AbilityManagerInterfaceCode::LOGOUT_USER), mock_->code_); EXPECT_NE(result, NO_ERROR); @@ -1089,7 +1092,7 @@ HWTEST_F(AbilityManagerProxyTest, LogoutUser_3200, TestSize.Level1) sptr mockIUserCallback = new MockIUserCallback(); mockIUserCallback->iremoteObject_ = sptr(new (std::nothrow) MockAbilityToken()); callback = mockIUserCallback; - result = proxy_->LogoutUser(1, callback); + result = proxy_->LogoutUser(userId, callback); EXPECT_EQ(static_cast(AbilityManagerInterfaceCode::LOGOUT_USER), mock_->code_); EXPECT_EQ(result, NO_ERROR); diff --git a/test/unittest/ability_manager_proxy_third_test/ability_manager_stub_mock.h b/test/unittest/ability_manager_proxy_third_test/ability_manager_stub_mock.h index b443ad9e07c..09dda28fd27 100644 --- a/test/unittest/ability_manager_proxy_third_test/ability_manager_stub_mock.h +++ b/test/unittest/ability_manager_proxy_third_test/ability_manager_stub_mock.h @@ -208,7 +208,7 @@ public: return; } - int StartUser(int userId, sptr callback, bool isAppRecovery) override + int StartUser(int userId, uint64_t displayId, sptr callback, bool isAppRecovery) override { return 0; } diff --git a/test/unittest/ability_manager_service_account_test/ability_manager_service_account_test.cpp b/test/unittest/ability_manager_service_account_test/ability_manager_service_account_test.cpp index 088179067f9..d370b19b190 100644 --- a/test/unittest/ability_manager_service_account_test/ability_manager_service_account_test.cpp +++ b/test/unittest/ability_manager_service_account_test/ability_manager_service_account_test.cpp @@ -137,7 +137,7 @@ HWTEST_F(AbilityManagerServiceAccountTest, Account_StartAbility_001, TestSize.Le { GTEST_LOG_(INFO) << "AbilityManagerServiceAccountTest Account_StartAbility_001 start"; sptr callback = new MockIUserCallback(); - abilityMs_->StartUser(USER_ID_U100, callback); + abilityMs_->StartUser(USER_ID_U100, 0, callback); auto topAbility = GetMissionListTopAbility(abilityMs_->GetMissionListManagerByUserId(USER_ID_U100)); if (topAbility) { topAbility->SetAbilityState(AAFwk::AbilityState::FOREGROUND); @@ -149,7 +149,7 @@ HWTEST_F(AbilityManagerServiceAccountTest, Account_StartAbility_001, TestSize.Le WaitUntilTaskFinished(); EXPECT_EQ(OHOS::ERR_OK, result); - abilityMs_->StartUser(newUserId, callback); + abilityMs_->StartUser(newUserId, 0, callback); topAbility = GetMissionListTopAbility(abilityMs_->GetMissionListManagerByUserId(newUserId)); if (topAbility) { topAbility->SetAbilityState(AAFwk::AbilityState::FOREGROUND); @@ -158,7 +158,7 @@ HWTEST_F(AbilityManagerServiceAccountTest, Account_StartAbility_001, TestSize.Le result = abilityMs_->StartAbility(want, newUserId); WaitUntilTaskFinished(); EXPECT_EQ(OHOS::ERR_OK, result); - abilityMs_->StartUser(USER_ID_U100, callback); + abilityMs_->StartUser(USER_ID_U100, 0, callback); GTEST_LOG_(INFO) << "AbilityManagerServiceAccountTest Account_StartAbility_001 end"; } @@ -224,7 +224,7 @@ HWTEST_F(AbilityManagerServiceAccountTest, Account_StartAbility_003, TestSize.Le EXPECT_EQ(OHOS::ERR_OK, result); sptr callback = new MockIUserCallback(); - abilityMs_->StartUser(newUserId, callback); + abilityMs_->StartUser(newUserId, 0, callback); topAbility = GetMissionListTopAbility(abilityMs_->GetMissionListManagerByUserId(newUserId)); if (topAbility) { topAbility->SetAbilityState(AAFwk::AbilityState::FOREGROUND); @@ -232,7 +232,7 @@ HWTEST_F(AbilityManagerServiceAccountTest, Account_StartAbility_003, TestSize.Le result = abilityMs_->StartAbility(want, abilityStartSetting, nullptr, newUserId, -1); WaitUntilTaskFinished(); EXPECT_EQ(OHOS::ERR_OK, result); - abilityMs_->StartUser(USER_ID_U100, callback); + abilityMs_->StartUser(USER_ID_U100, 0, callback); GTEST_LOG_(INFO) << "AbilityManagerServiceAccountTest Account_StartAbility_003 end"; } @@ -261,7 +261,7 @@ HWTEST_F(AbilityManagerServiceAccountTest, Account_StartAbility_004, TestSize.Le EXPECT_EQ(OHOS::ERR_OK, result); sptr callback = new MockIUserCallback(); - abilityMs_->StartUser(newUserId, callback); + abilityMs_->StartUser(newUserId, 0, callback); topAbility = GetMissionListTopAbility(abilityMs_->GetMissionListManagerByUserId(newUserId)); if (topAbility) { topAbility->SetAbilityState(AAFwk::AbilityState::FOREGROUND); @@ -269,7 +269,7 @@ HWTEST_F(AbilityManagerServiceAccountTest, Account_StartAbility_004, TestSize.Le result = abilityMs_->StartAbility(want, abilityStartOptions, nullptr, newUserId, -1); WaitUntilTaskFinished(); EXPECT_EQ(OHOS::ERR_OK, result); - abilityMs_->StartUser(USER_ID_U100, callback); + abilityMs_->StartUser(USER_ID_U100, 0, callback); GTEST_LOG_(INFO) << "AbilityManagerServiceAccountTest Account_StartAbility_004 end"; } @@ -328,7 +328,7 @@ HWTEST_F(AbilityManagerServiceAccountTest, Account_StartAbility_007, TestSize.Le { GTEST_LOG_(INFO) << "AbilityManagerServiceAccountTest Account_StartAbility_007 start"; sptr callback = new MockIUserCallback(); - abilityMs_->StartUser(USER_ID_U100, callback); + abilityMs_->StartUser(USER_ID_U100, 0, callback); Want want; ElementName element("", "com.ix.hiSingleMusicInfo", "SingleMusicAbility"); want.SetElement(element); @@ -351,7 +351,7 @@ HWTEST_F(AbilityManagerServiceAccountTest, Account_StartAbility_008, TestSize.Le { GTEST_LOG_(INFO) << "AbilityManagerServiceAccountTest Account_StartAbility_008 start"; sptr callback = new MockIUserCallback(); - abilityMs_->StartUser(USER_ID_U100, callback); + abilityMs_->StartUser(USER_ID_U100, 0, callback); Want want; ElementName element("", "com.ix.hiBackgroundMusic", "hiBackgroundMusic"); want.SetElement(element); @@ -416,7 +416,7 @@ HWTEST_F(AbilityManagerServiceAccountTest, Account_StartAbility_011, TestSize.Le { GTEST_LOG_(INFO) << "AbilityManagerServiceAccountTest Account_StartAbility_011 start"; sptr callback = new MockIUserCallback(); - abilityMs_->StartUser(USER_ID_U100, callback); + abilityMs_->StartUser(USER_ID_U100, 0, callback); auto topAbility = GetMissionListTopAbility(abilityMs_->GetMissionListManagerByUserId(USER_ID_U100)); if (topAbility) { topAbility->SetAbilityState(AAFwk::AbilityState::FOREGROUND); @@ -634,7 +634,7 @@ HWTEST_F(AbilityManagerServiceAccountTest, Account_ConnectAbility_002, TestSize. { GTEST_LOG_(INFO) << "AbilityManagerServiceAccountTest Account_ConnectAbility_002 start"; sptr callback = new MockIUserCallback(); - abilityMs_->StartUser(newUserId, callback); + abilityMs_->StartUser(newUserId, 0, callback); Want want; ElementName element("", "com.ix.musicService", "MusicService"); want.SetElement(element); @@ -650,7 +650,7 @@ HWTEST_F(AbilityManagerServiceAccountTest, Account_ConnectAbility_002, TestSize. auto result2 = abilityMs_->ConnectAbility(want, callback, nullptr, newUserId); EXPECT_EQ(result2, ERR_OK); - abilityMs_->StartUser(USER_ID_U100, callback); + abilityMs_->StartUser(USER_ID_U100, 0, callback); GTEST_LOG_(INFO) << "AbilityManagerServiceAccountTest Account_ConnectAbility_002 end"; } @@ -832,7 +832,7 @@ HWTEST_F(AbilityManagerServiceAccountTest, Account_ScheduleConnectAbilityDone_00 { GTEST_LOG_(INFO) << "AbilityManagerServiceAccountTest Account_ScheduleConnectAbilityDone_003 start"; sptr callback = new MockIUserCallback(); - abilityMs_->StartUser(newUserId, callback); + abilityMs_->StartUser(newUserId, 0, callback); Want want; ElementName element("", "com.ix.musicService", "MusicService"); want.SetElement(element); @@ -858,7 +858,7 @@ HWTEST_F(AbilityManagerServiceAccountTest, Account_ScheduleConnectAbilityDone_00 auto result3 = abilityMs_->ScheduleConnectAbilityDone(service->GetToken(), callback->AsObject()); WaitUntilTaskFinished(); EXPECT_EQ(result3, ERR_OK); - abilityMs_->StartUser(USER_ID_U100, callback); + abilityMs_->StartUser(USER_ID_U100, 0, callback); GTEST_LOG_(INFO) << "AbilityManagerServiceAccountTest Account_ScheduleConnectAbilityDone_003 end"; } @@ -876,7 +876,7 @@ HWTEST_F(AbilityManagerServiceAccountTest, Account_ScheduleConnectAbilityDone_00 { GTEST_LOG_(INFO) << "AbilityManagerServiceAccountTest Account_ScheduleConnectAbilityDone_004 start"; sptr callback = new MockIUserCallback(); - abilityMs_->StartUser(newUserId, callback); + abilityMs_->StartUser(newUserId, 0, callback); auto topAbility = GetMissionListTopAbility(abilityMs_->GetMissionListManagerByUserId(newUserId)); if (topAbility) { topAbility->SetAbilityState(AAFwk::AbilityState::FOREGROUND); @@ -898,7 +898,7 @@ HWTEST_F(AbilityManagerServiceAccountTest, Account_ScheduleConnectAbilityDone_00 auto result1 = abilityMs_->ScheduleConnectAbilityDone(token, callback->AsObject()); WaitUntilTaskFinished(); EXPECT_EQ(result1, TARGET_ABILITY_NOT_SERVICE); - abilityMs_->StartUser(USER_ID_U100, callback); + abilityMs_->StartUser(USER_ID_U100, 0, callback); GTEST_LOG_(INFO) << "AbilityManagerServiceAccountTest Account_ScheduleConnectAbilityDone_004 end"; } @@ -995,7 +995,7 @@ HWTEST_F(AbilityManagerServiceAccountTest, Account_ScheduleDisconnectAbilityDone { GTEST_LOG_(INFO) << "AbilityManagerServiceAccountTest Account_ScheduleDisconnectAbilityDone_003 start"; sptr callback = new MockIUserCallback(); - abilityMs_->StartUser(newUserId, callback); + abilityMs_->StartUser(newUserId, 0, callback); auto topAbility = GetMissionListTopAbility(abilityMs_->GetMissionListManagerByUserId(newUserId)); if (topAbility) { topAbility->SetAbilityState(AAFwk::AbilityState::FOREGROUND); @@ -1017,7 +1017,7 @@ HWTEST_F(AbilityManagerServiceAccountTest, Account_ScheduleDisconnectAbilityDone auto result1 = abilityMs_->ScheduleDisconnectAbilityDone(token); WaitUntilTaskFinished(); EXPECT_EQ(result1, TARGET_ABILITY_NOT_SERVICE); - abilityMs_->StartUser(USER_ID_U100, callback); + abilityMs_->StartUser(USER_ID_U100, 0, callback); GTEST_LOG_(INFO) << "AbilityManagerServiceAccountTest Account_ScheduleDisconnectAbilityDone_003 end"; } @@ -1115,7 +1115,7 @@ HWTEST_F(AbilityManagerServiceAccountTest, Account_ScheduleCommandAbilityDone_00 { GTEST_LOG_(INFO) << "AbilityManagerServiceAccountTest Account_ScheduleCommandAbilityDone_003 start"; sptr callback = new MockIUserCallback(); - abilityMs_->StartUser(newUserId, callback); + abilityMs_->StartUser(newUserId, 0, callback); Want want; ElementName element("", "com.ix.musicService", "MusicService"); want.SetElement(element); @@ -1141,7 +1141,7 @@ HWTEST_F(AbilityManagerServiceAccountTest, Account_ScheduleCommandAbilityDone_00 auto result3 = abilityMs_->ScheduleCommandAbilityDone(service->GetToken()); WaitUntilTaskFinished(); EXPECT_EQ(result3, ERR_OK); - abilityMs_->StartUser(USER_ID_U100, callback); + abilityMs_->StartUser(USER_ID_U100, 0, callback); GTEST_LOG_(INFO) << "AbilityManagerServiceAccountTest Account_ScheduleCommandAbilityDone_003 end"; } @@ -1159,7 +1159,7 @@ HWTEST_F(AbilityManagerServiceAccountTest, Account_ScheduleCommandAbilityDone_00 { GTEST_LOG_(INFO) << "AbilityManagerServiceAccountTest Account_ScheduleCommandAbilityDone_004 start"; sptr callback = new MockIUserCallback(); - abilityMs_->StartUser(newUserId, callback); + abilityMs_->StartUser(newUserId, 0, callback); auto topAbility = GetMissionListTopAbility(abilityMs_->GetMissionListManagerByUserId(newUserId)); if (topAbility) { topAbility->SetAbilityState(AAFwk::AbilityState::FOREGROUND); @@ -1181,7 +1181,7 @@ HWTEST_F(AbilityManagerServiceAccountTest, Account_ScheduleCommandAbilityDone_00 auto result1 = abilityMs_->ScheduleCommandAbilityDone(token); WaitUntilTaskFinished(); EXPECT_EQ(result1, TARGET_ABILITY_NOT_SERVICE); - abilityMs_->StartUser(USER_ID_U100, callback); + abilityMs_->StartUser(USER_ID_U100, 0, callback); GTEST_LOG_(INFO) << "AbilityManagerServiceAccountTest Account_ScheduleCommandAbilityDone_004 end"; } @@ -1235,7 +1235,7 @@ HWTEST_F(AbilityManagerServiceAccountTest, Account_StopServiceAbility_002, TestS { GTEST_LOG_(INFO) << "AbilityManagerServiceAccountTest Account_StopServiceAbility_002 start"; sptr callback = new MockIUserCallback(); - abilityMs_->StartUser(newUserId, callback); + abilityMs_->StartUser(newUserId, 0, callback); Want want; ElementName element("", "com.ix.musicService", "MusicService"); want.SetElement(element); @@ -1260,7 +1260,7 @@ HWTEST_F(AbilityManagerServiceAccountTest, Account_StopServiceAbility_002, TestS auto result2 = abilityMs_->StopServiceAbility(want, newUserId); WaitUntilTaskFinished(); EXPECT_EQ(CHECK_PERMISSION_FAILED, result2); - abilityMs_->StartUser(USER_ID_U100, callback); + abilityMs_->StartUser(USER_ID_U100, 0, callback); GTEST_LOG_(INFO) << "AbilityManagerServiceAccountTest Account_StopServiceAbility_002 end"; } diff --git a/test/unittest/ability_manager_service_eighth_test/ability_manager_service_eighth_test.cpp b/test/unittest/ability_manager_service_eighth_test/ability_manager_service_eighth_test.cpp index f11947e1be8..0099f719bda 100644 --- a/test/unittest/ability_manager_service_eighth_test/ability_manager_service_eighth_test.cpp +++ b/test/unittest/ability_manager_service_eighth_test/ability_manager_service_eighth_test.cpp @@ -152,10 +152,6 @@ HWTEST_F(AbilityManagerServiceEighthTest, StopUser_001, TestSize.Level1) IPCSkeleton::SetCallingUid(ACCOUNT_MGR_SERVICE_UID); sptr callback1 = nullptr; EXPECT_EQ(abilityMs->StopUser(userId, callback1), 0); - abilityMs->userController_ = std::make_shared(); - EXPECT_EQ(abilityMs->StopUser(userId, callback), 0); - system::SetBoolParameter(PRODUCT_ENTERPRISE_FEATURE_SETTING_ENABLED, true); - EXPECT_EQ(abilityMs->StopUser(userId, callback), 0); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceEighthTest StopUser_001 end"); } @@ -176,10 +172,7 @@ HWTEST_F(AbilityManagerServiceEighthTest, LogoutUser_001, TestSize.Level1) sptr callback1 = new MockIUserCallback(); EXPECT_EQ(abilityMs->LogoutUser(userId, callback1), CHECK_PERMISSION_FAILED); IPCSkeleton::SetCallingUid(ACCOUNT_MGR_SERVICE_UID); - EXPECT_EQ(abilityMs->LogoutUser(userId, callback1), ERR_OK); - abilityMs->userController_ = std::make_shared(); - system::SetBoolParameter(PRODUCT_APPBOOT_SETTING_ENABLED, true); - EXPECT_NE(abilityMs->LogoutUser(userId, callback1), ERR_OK); + EXPECT_EQ(abilityMs->LogoutUser(userId, callback1), INVALID_USERID_VALUE); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceEighthTest LogoutUser_001 end"); } @@ -218,17 +211,17 @@ HWTEST_F(AbilityManagerServiceEighthTest, SwitchToUser_001, TestSize.Level1) sptr callback1 = new MockIUserCallback(); EXPECT_CALL(Rosen::SceneBoardJudgement::GetInstance(), MockIsSceneBoardEnabled()) .WillRepeatedly(Return(false)); - EXPECT_NE(abilityMs->SwitchToUser(oldUserId, userId, callback), ERR_OK); + EXPECT_NE(abilityMs->SwitchToUser(oldUserId, userId, 0, callback), ERR_OK); abilityMs->taskHandler_ = TaskHandlerWrap::CreateQueueHandler("SetTaskHandler"); - EXPECT_NE(abilityMs->SwitchToUser(oldUserId, userId, callback1), ERR_OK); + EXPECT_NE(abilityMs->SwitchToUser(oldUserId, userId, 0, callback1), ERR_OK); EXPECT_CALL(Rosen::SceneBoardJudgement::GetInstance(), MockIsSceneBoardEnabled()) .WillRepeatedly(Return(true)); - EXPECT_NE(abilityMs->SwitchToUser(oldUserId, userId, callback1), ERR_OK); + EXPECT_NE(abilityMs->SwitchToUser(oldUserId, userId, 0, callback1), ERR_OK); AmsConfigurationParameter::GetInstance().multiUserType_ = 1; // multiUserType_ = 1 - EXPECT_NE(abilityMs->SwitchToUser(oldUserId, userId, callback1), ERR_OK); + EXPECT_NE(abilityMs->SwitchToUser(oldUserId, userId, 0, callback1), ERR_OK); EXPECT_CALL(Rosen::SceneBoardJudgement::GetInstance(), MockIsSceneBoardEnabled()) .WillRepeatedly(Return(false)); - EXPECT_NE(abilityMs->SwitchToUser(oldUserId, userId, callback1), ERR_OK); + EXPECT_NE(abilityMs->SwitchToUser(oldUserId, userId, 0, callback1), ERR_OK); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceEighthTest SwitchToUser_001 end"); } diff --git a/test/unittest/ability_manager_service_fourteenth_test/BUILD.gn b/test/unittest/ability_manager_service_fourteenth_test/BUILD.gn index c8712a741a3..c4eb15835d6 100644 --- a/test/unittest/ability_manager_service_fourteenth_test/BUILD.gn +++ b/test/unittest/ability_manager_service_fourteenth_test/BUILD.gn @@ -262,6 +262,7 @@ ohos_unittest("ability_manager_service_fourteenth_test") { "${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/test/unittest/ability_manager_service_second_test/BUILD.gn b/test/unittest/ability_manager_service_second_test/BUILD.gn index 0528a8c6826..1b8aa5984b2 100644 --- a/test/unittest/ability_manager_service_second_test/BUILD.gn +++ b/test/unittest/ability_manager_service_second_test/BUILD.gn @@ -263,6 +263,7 @@ ohos_unittest("ability_manager_service_second_test") { "${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/test/unittest/ability_manager_service_second_test/ability_manager_service_second_test.cpp b/test/unittest/ability_manager_service_second_test/ability_manager_service_second_test.cpp index 4cd845f1704..d9592a63314 100644 --- a/test/unittest/ability_manager_service_second_test/ability_manager_service_second_test.cpp +++ b/test/unittest/ability_manager_service_second_test/ability_manager_service_second_test.cpp @@ -125,9 +125,6 @@ HWTEST_F(AbilityManagerServiceSecondTest, StartSwitchUserDialog_001, TestSize.Le auto abilityMs_ = std::make_shared(); EXPECT_NE(abilityMs_, nullptr); abilityMs_->StartSwitchUserDialog(); - - abilityMs_->userController_ = nullptr; - abilityMs_->StartSwitchUserDialog(); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSecondTest StartSwitchUserDialog_001 end"); } @@ -159,9 +156,6 @@ HWTEST_F(AbilityManagerServiceSecondTest, StopSwitchUserDialog_001, TestSize.Lev auto abilityMs_ = std::make_shared(); EXPECT_NE(abilityMs_, nullptr); abilityMs_->StopSwitchUserDialog(); - - abilityMs_->userController_ = nullptr; - abilityMs_->StopSwitchUserDialog(); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSecondTest StopSwitchUserDialog_001 end"); } @@ -1672,20 +1666,6 @@ HWTEST_F(AbilityManagerServiceSecondTest, GetEventHandler_001, TestSize.Level1) TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSecondTest GetEventHandler_001 end"); } -/* - * Feature: AbilityManagerService - * Function: GetUserId - * SubFunction: NA - * FunctionPoints: AbilityManagerService GetUserId - */ -HWTEST_F(AbilityManagerServiceSecondTest, GetUserId_001, TestSize.Level1) -{ - TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSecondTest GetUserId_001 start"); - auto abilityMs_ = std::make_shared(); - EXPECT_NE(abilityMs_->GetUserId(), 100); - TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSecondTest GetUserId_001 end"); -} - /* * Feature: AbilityManagerService * Function: GenerateAbilityRequest @@ -1884,6 +1864,24 @@ HWTEST_F(AbilityManagerServiceSecondTest, UpdateKeepAliveEnableState_001, TestSi TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSecondTest UpdateKeepAliveEnableState_001 end"); } +/* + * Feature: AbilityManagerService + * Name: GetCallerUserId_001 + * Function: GetCallerUserId + * SubFunction: NA + * FunctionPoints: AbilityManagerService GetCallerUserId + */ +HWTEST_F(AbilityManagerServiceSecondTest, GetCallerUserId_001, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSecondTest GetCallerUserId_001 start"); + auto abilityMs_ = std::make_shared(); + EXPECT_NE(abilityMs_, nullptr); + auto userId = abilityMs_->GetCallerUserId(); + int32_t invalidUseId = 1000; + EXPECT_NE(userId, invalidUseId); + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSecondTest GetCallerUserId_001 end"); +} + #ifdef SUPPORT_AUTO_FILL /** * @tc.name: CheckCallAutoFillExtensionPermission_001 diff --git a/test/unittest/ability_manager_service_sixth_test/ability_manager_service_sixth_test.cpp b/test/unittest/ability_manager_service_sixth_test/ability_manager_service_sixth_test.cpp index d9689a4e0ec..8a308677a55 100644 --- a/test/unittest/ability_manager_service_sixth_test/ability_manager_service_sixth_test.cpp +++ b/test/unittest/ability_manager_service_sixth_test/ability_manager_service_sixth_test.cpp @@ -1634,7 +1634,6 @@ HWTEST_F(AbilityManagerServiceSixthTest, VerifyAccountPermission_001, TestSize.L EXPECT_EQ(ret, ERR_OK); userId = USER_ID_U100; ret = abilityMs->VerifyAccountPermission(userId); - abilityMs->userController_ = std::make_shared(); ret = abilityMs->VerifyAccountPermission(userId); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSixthTest VerifyAccountPermission_001 end"); } diff --git a/test/unittest/ability_manager_service_tenth_test/ability_manager_service_tenth_test.cpp b/test/unittest/ability_manager_service_tenth_test/ability_manager_service_tenth_test.cpp index 9211523299c..cd19cba8110 100644 --- a/test/unittest/ability_manager_service_tenth_test/ability_manager_service_tenth_test.cpp +++ b/test/unittest/ability_manager_service_tenth_test/ability_manager_service_tenth_test.cpp @@ -592,7 +592,7 @@ HWTEST_F(AbilityManagerServiceTenhtTest, StartHighestPriorityAbility_001, TestSi int32_t userId = 1; bool isBoot = false; bool isAppRecovery = true; - auto ret = abilityMs_->StartHighestPriorityAbility(userId, isBoot, isAppRecovery); + auto ret = abilityMs_->StartHighestPriorityAbility(userId, 0, isBoot, isAppRecovery); EXPECT_EQ(ret, RESOLVE_ABILITY_ERR); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceTenhtTest StartHighestPriorityAbility_001 end"); } diff --git a/test/unittest/ability_manager_service_third_test/BUILD.gn b/test/unittest/ability_manager_service_third_test/BUILD.gn index 3184a5ee67f..bb0203923c7 100644 --- a/test/unittest/ability_manager_service_third_test/BUILD.gn +++ b/test/unittest/ability_manager_service_third_test/BUILD.gn @@ -91,6 +91,7 @@ ohos_unittest("ability_manager_service_third_test") { "${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}/mock/services_abilitymgr_test/libs/aakit:aakit_mock", ] diff --git a/test/unittest/ability_manager_service_third_test/ability_manager_service_third_test.cpp b/test/unittest/ability_manager_service_third_test/ability_manager_service_third_test.cpp index 5ef97093c07..dca029725a6 100644 --- a/test/unittest/ability_manager_service_third_test/ability_manager_service_third_test.cpp +++ b/test/unittest/ability_manager_service_third_test/ability_manager_service_third_test.cpp @@ -735,10 +735,7 @@ HWTEST_F(AbilityManagerServiceThirdTest, JudgeMultiUserConcurrency_001, TestSize auto abilityMs_ = std::make_shared(); EXPECT_TRUE(abilityMs_->JudgeMultiUserConcurrency(0)); - auto temp = abilityMs_->userController_; - abilityMs_->userController_ = nullptr; EXPECT_FALSE(abilityMs_->JudgeMultiUserConcurrency(100)); - abilityMs_->userController_ = temp; TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceThirdTest JudgeMultiUserConcurrency_001 end"); } diff --git a/test/unittest/ability_manager_service_thirteenth_test/BUILD.gn b/test/unittest/ability_manager_service_thirteenth_test/BUILD.gn index d4cbe09ed85..b52df36a5a5 100644 --- a/test/unittest/ability_manager_service_thirteenth_test/BUILD.gn +++ b/test/unittest/ability_manager_service_thirteenth_test/BUILD.gn @@ -263,6 +263,7 @@ ohos_unittest("ability_manager_service_thirteenth_test") { "${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/test/unittest/ability_manager_service_twelfth_test/ability_manager_service_twelfth_test.cpp b/test/unittest/ability_manager_service_twelfth_test/ability_manager_service_twelfth_test.cpp index 1fad5b98907..06481a1fe4c 100644 --- a/test/unittest/ability_manager_service_twelfth_test/ability_manager_service_twelfth_test.cpp +++ b/test/unittest/ability_manager_service_twelfth_test/ability_manager_service_twelfth_test.cpp @@ -545,7 +545,7 @@ HWTEST_F(AbilityManagerServiceTwelfthTest, StartUser_001, TestSize.Level1) int userId = 0; sptr callback = new MockIUserCallback(); bool isAppRecovery = false; - auto retCode = abilityMs_->StartUser(userId, callback, isAppRecovery); + auto retCode = abilityMs_->StartUser(userId, 0, callback, isAppRecovery); EXPECT_EQ(retCode, CHECK_PERMISSION_FAILED); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceTwelfthTest StartUser_001 end"); } @@ -622,8 +622,6 @@ HWTEST_F(AbilityManagerServiceTwelfthTest, IsSceneBoardReady_001, TestSize.Level int32_t userId = -1; auto abilityMs = std::make_shared(); EXPECT_NE(abilityMs, nullptr); - abilityMs->userController_ = std::make_shared(); - EXPECT_NE(abilityMs->userController_, nullptr); abilityMs->subManagersHelper_ = std::make_shared(nullptr, nullptr); EXPECT_NE(abilityMs->subManagersHelper_, nullptr); bool result = abilityMs->IsSceneBoardReady(userId); @@ -644,7 +642,6 @@ HWTEST_F(AbilityManagerServiceTwelfthTest, IsSceneBoardReady_002, TestSize.Level int32_t userId = 100; auto abilityMs = std::make_shared(); EXPECT_NE(abilityMs, nullptr); - abilityMs->userController_ = nullptr; abilityMs->subManagersHelper_ = nullptr; bool result = abilityMs->IsSceneBoardReady(userId); EXPECT_FALSE(result); diff --git a/test/unittest/ability_manager_stub_test/ability_manager_stub_impl_mock.h b/test/unittest/ability_manager_stub_test/ability_manager_stub_impl_mock.h index cc1dac2376a..57e9c0b150c 100644 --- a/test/unittest/ability_manager_stub_test/ability_manager_stub_impl_mock.h +++ b/test/unittest/ability_manager_stub_test/ability_manager_stub_impl_mock.h @@ -283,7 +283,7 @@ public: { return 0; } - int StartUser(int userId, sptr callback, bool isAppRecovery) override + int StartUser(int userId, uint64_t displayId, sptr callback, bool isAppRecovery) override { return 0; } diff --git a/test/unittest/ability_manager_test/ability_manager_stub_mock.h b/test/unittest/ability_manager_test/ability_manager_stub_mock.h index f87fe1e2e18..d4997667757 100644 --- a/test/unittest/ability_manager_test/ability_manager_stub_mock.h +++ b/test/unittest/ability_manager_test/ability_manager_stub_mock.h @@ -223,7 +223,7 @@ public: return 0; } - int StartUser(int userId, sptr callback, bool isAppRecovery) override + int StartUser(int userId, uint64_t displayId, sptr callback, bool isAppRecovery) override { return 0; } diff --git a/test/unittest/ability_permission_util_second_test/mock/include/mock_app_mgr_service.h b/test/unittest/ability_permission_util_second_test/mock/include/mock_app_mgr_service.h index 988782453e3..e5691f38e04 100644 --- a/test/unittest/ability_permission_util_second_test/mock/include/mock_app_mgr_service.h +++ b/test/unittest/ability_permission_util_second_test/mock/include/mock_app_mgr_service.h @@ -91,8 +91,8 @@ public: MOCK_METHOD3(GetRunningProcessInformation, int32_t(const std::string & bundleName, int32_t userId, std::vector &info)); MOCK_METHOD1(GetAllRunningInstanceKeysBySelf, int32_t(std::vector &instanceKeys)); - MOCK_METHOD3(GetAllRunningInstanceKeysByBundleName, int32_t(const std::string &bundleName, - std::vector &instanceKeys, int32_t userId)); + MOCK_METHOD2(GetAllRunningInstanceKeysByBundleName, int32_t(const std::string &bundleName, + std::vector &instanceKeys)); MOCK_METHOD2(IsApplicationRunning, int32_t(const std::string &bundleName, bool &isRunning)); MOCK_METHOD3(IsAppRunning, int32_t(const std::string &bundleName, int32_t appCloneIndex, bool &isRunning)); diff --git a/test/unittest/ams_ability_running_record_test/BUILD.gn b/test/unittest/ams_ability_running_record_test/BUILD.gn index 7064b15201a..2443ba8cfcd 100644 --- a/test/unittest/ams_ability_running_record_test/BUILD.gn +++ b/test/unittest/ams_ability_running_record_test/BUILD.gn @@ -68,6 +68,7 @@ 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", ] @@ -106,7 +107,11 @@ ohos_unittest("AmsAbilityRunningRecordTest") { } if (ability_runtime_graphics) { - external_deps += [ "window_manager:libwm" ] + external_deps += [ + "window_manager:libdm", + "window_manager:libwm", + "window_manager:libwsutils", + ] } if (ability_runtime_upms) { deps += [ 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 8ceefa8055c..a5e51fd131d 100644 --- a/test/unittest/ams_service_load_ability_process_test/BUILD.gn +++ b/test/unittest/ams_service_load_ability_process_test/BUILD.gn @@ -77,6 +77,7 @@ 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", ] @@ -121,6 +122,7 @@ ohos_unittest("AmsServiceLoadAbilityProcessTest") { } if (ability_runtime_graphics) { external_deps += [ + "window_manager:libdm", "window_manager:libwm", "window_manager:libwsutils", ] diff --git a/test/unittest/ams_service_startup_test/BUILD.gn b/test/unittest/ams_service_startup_test/BUILD.gn index 1ba09810280..7af0586e5dd 100644 --- a/test/unittest/ams_service_startup_test/BUILD.gn +++ b/test/unittest/ams_service_startup_test/BUILD.gn @@ -69,6 +69,7 @@ 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", ] @@ -109,7 +110,11 @@ ohos_unittest("AmsServiceStartupTest") { ] } if (ability_runtime_graphics) { - external_deps += [ "window_manager:libwm" ] + external_deps += [ + "window_manager:libdm", + "window_manager:libwm", + "window_manager:libwsutils", + ] } if (ability_runtime_upms) { deps += [ diff --git a/test/unittest/app_mgr_proxy_test/app_mgr_proxy_test.cpp b/test/unittest/app_mgr_proxy_test/app_mgr_proxy_test.cpp index 1ce51c9df87..764900bb948 100644 --- a/test/unittest/app_mgr_proxy_test/app_mgr_proxy_test.cpp +++ b/test/unittest/app_mgr_proxy_test/app_mgr_proxy_test.cpp @@ -943,7 +943,7 @@ HWTEST_F(AppMgrProxyTest, GetAllRunningInstanceKeysByBundleName_001, TestSize.Le int32_t userId = -1; data.WriteInt32(userId); - EXPECT_CALL(*mockAppMgrService_, GetAllRunningInstanceKeysByBundleName(_, _, _)).Times(1); + EXPECT_CALL(*mockAppMgrService_, GetAllRunningInstanceKeysByBundleName(_, _)).Times(1); auto result = mockAppMgrService_->OnRemoteRequest( static_cast(AppMgrInterfaceCode::GET_All_RUNNING_INSTANCE_KEYS_BY_BUNDLENAME), data, reply, option); 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 f10ab814e2e..32bd151db7c 100644 --- a/test/unittest/app_mgr_service_event_handler_test/BUILD.gn +++ b/test/unittest/app_mgr_service_event_handler_test/BUILD.gn @@ -73,6 +73,7 @@ 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", ] @@ -119,6 +120,7 @@ ohos_unittest("AMSEventHandlerTest") { } if (ability_runtime_graphics) { external_deps += [ + "window_manager:libdm", "window_manager:libwm", "window_manager:libwsutils", ] diff --git a/test/unittest/app_mgr_service_fourth_test/BUILD.gn b/test/unittest/app_mgr_service_fourth_test/BUILD.gn index 3acb0107ed8..0c4e8e0b2c8 100644 --- a/test/unittest/app_mgr_service_fourth_test/BUILD.gn +++ b/test/unittest/app_mgr_service_fourth_test/BUILD.gn @@ -63,6 +63,7 @@ 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 = [ @@ -91,6 +92,7 @@ ohos_unittest("app_mgr_service_fourth_test") { "safwk:system_ability_fwk", "samgr:samgr_proxy", "selinux_adapter:librestorecon", + "window_manager:libdm", ] defines = [] 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 136073f96b8..c3d4bdc8e4b 100644 --- a/test/unittest/app_mgr_service_inner_eighth_test/BUILD.gn +++ b/test/unittest/app_mgr_service_inner_eighth_test/BUILD.gn @@ -105,6 +105,7 @@ 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 = [ @@ -152,6 +153,7 @@ ohos_unittest("app_mgr_service_inner_eighth_test") { defines += [ "SUPPORT_GRAPHICS" ] external_deps += [ "i18n:intl_util", + "window_manager:libdm", "window_manager:libwm", "window_manager:libwsutils", ] diff --git a/test/unittest/app_mgr_service_inner_eighth_test/app_mgr_service_inner_eighth_test.cpp b/test/unittest/app_mgr_service_inner_eighth_test/app_mgr_service_inner_eighth_test.cpp index 04921fd1e58..f40113da3dd 100644 --- a/test/unittest/app_mgr_service_inner_eighth_test/app_mgr_service_inner_eighth_test.cpp +++ b/test/unittest/app_mgr_service_inner_eighth_test/app_mgr_service_inner_eighth_test.cpp @@ -587,38 +587,6 @@ HWTEST_F(AppMgrServiceInnerEighthTest, StartNativeProcessForDebugger_006, TestSi TAG_LOGI(AAFwkTag::TEST, "StartNativeProcessForDebugger_006 end"); } -/** - * @tc.name: GetCurrentAccountId_001 - * @tc.desc: test GetCurrentAccountId_001 - * @tc.type: FUNC - */ -HWTEST_F(AppMgrServiceInnerEighthTest, GetCurrentAccountId_001, TestSize.Level1) -{ - TAG_LOGI(AAFwkTag::TEST, "GetCurrentAccountId_001 start"); - auto appMgrServiceInner = std::make_shared(); - AAFwk::MyStatus::GetInstance().queryActiveOsAccountIds_ = ERR_NO_INIT; - - auto ret = appMgrServiceInner->GetCurrentAccountId(); - EXPECT_EQ(ret, DEFAULT_USER_ID); - TAG_LOGI(AAFwkTag::TEST, "GetCurrentAccountId_001 end"); -} - -/** - * @tc.name: GetCurrentAccountId_002 - * @tc.desc: test GetCurrentAccountId_002 - * @tc.type: FUNC - */ -HWTEST_F(AppMgrServiceInnerEighthTest, GetCurrentAccountId_002, TestSize.Level1) -{ - TAG_LOGI(AAFwkTag::TEST, "GetCurrentAccountId_002 start"); - auto appMgrServiceInner = std::make_shared(); - AAFwk::MyStatus::GetInstance().queryActiveOsAccountIds_ = ERR_OK; - - auto ret = appMgrServiceInner->GetCurrentAccountId(); - EXPECT_EQ(ret, DEFAULT_USER_ID); - TAG_LOGI(AAFwkTag::TEST, "GetCurrentAccountId_002 end"); -} - /** * @tc.name: SetCurrentUserId_001 * @tc.desc: test SetCurrentUserId_001 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 0ad3739a084..98c1013fa47 100644 --- a/test/unittest/app_mgr_service_inner_ninth_test/BUILD.gn +++ b/test/unittest/app_mgr_service_inner_ninth_test/BUILD.gn @@ -104,6 +104,7 @@ 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 = [ @@ -142,6 +143,7 @@ ohos_unittest("app_mgr_service_inner_ninth_test") { "safwk:system_ability_fwk", "samgr:samgr_proxy", "selinux_adapter:librestorecon", + "window_manager:libdm", "window_manager:session_manager_lite", ] defines = [] diff --git a/test/unittest/app_mgr_service_inner_second_test/app_mgr_service_inner_second_test.cpp b/test/unittest/app_mgr_service_inner_second_test/app_mgr_service_inner_second_test.cpp index 037621bbfbd..865ff47ffa0 100644 --- a/test/unittest/app_mgr_service_inner_second_test/app_mgr_service_inner_second_test.cpp +++ b/test/unittest/app_mgr_service_inner_second_test/app_mgr_service_inner_second_test.cpp @@ -474,7 +474,8 @@ HWTEST_F(AppMgrServiceInnerSecondTest, GetAllRunningInstanceKeysByBundleName_010 EXPECT_NE(appMgrServiceInner, nullptr); std::string bundleName = "testBundleName"; std::vector instanceKeys; - auto ret = appMgrServiceInner->GetAllRunningInstanceKeysByBundleName(bundleName, instanceKeys); + int32_t userId = 100; + auto ret = appMgrServiceInner->GetAllRunningInstanceKeysByBundleName(bundleName, instanceKeys, userId); EXPECT_NE(ret, ERR_OK); TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleName_0100 end"); } @@ -1229,14 +1230,15 @@ HWTEST_F(AppMgrServiceInnerSecondTest, GetAllRunningInstanceKeysByBundleName_100 std::string bundleName = ""; std::vector instanceKeys; auto appMgrServiceInner = std::make_shared(); - auto res = appMgrServiceInner->GetAllRunningInstanceKeysByBundleName(bundleName, instanceKeys); + int32_t userId = 100; + auto res = appMgrServiceInner->GetAllRunningInstanceKeysByBundleName(bundleName, instanceKeys, userId); EXPECT_EQ(res, AAFwk::INVALID_PARAMETERS_ERR); bundleName = TEST_BUNDLE_NAME; appMgrServiceInner->remoteClientManager_ = nullptr; - res = appMgrServiceInner->GetAllRunningInstanceKeysByBundleName(bundleName, instanceKeys); + res = appMgrServiceInner->GetAllRunningInstanceKeysByBundleName(bundleName, instanceKeys, userId); EXPECT_EQ(res, ERR_INVALID_VALUE); appMgrServiceInner->remoteClientManager_ = std::make_shared(); - res = appMgrServiceInner->GetAllRunningInstanceKeysByBundleName(bundleName, instanceKeys); + res = appMgrServiceInner->GetAllRunningInstanceKeysByBundleName(bundleName, instanceKeys, userId); TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceInnerSecondTest_GetAllRunningInstanceKeysByBundleName_1000 end"); } 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 b5a2dfff8d4..c81ab32d022 100644 --- a/test/unittest/app_mgr_service_inner_seventh_test/BUILD.gn +++ b/test/unittest/app_mgr_service_inner_seventh_test/BUILD.gn @@ -104,6 +104,7 @@ 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 = [ @@ -150,6 +151,7 @@ ohos_unittest("app_mgr_service_inner_seventh_test") { defines += [ "SUPPORT_GRAPHICS" ] external_deps += [ "i18n:intl_util", + "window_manager:libdm", "window_manager:libwm", "window_manager:libwsutils", ] diff --git a/test/unittest/app_mgr_service_inner_seventh_test/app_mgr_service_inner_seventh_test.cpp b/test/unittest/app_mgr_service_inner_seventh_test/app_mgr_service_inner_seventh_test.cpp index 103ea96ebb6..300ec6f82cc 100644 --- a/test/unittest/app_mgr_service_inner_seventh_test/app_mgr_service_inner_seventh_test.cpp +++ b/test/unittest/app_mgr_service_inner_seventh_test/app_mgr_service_inner_seventh_test.cpp @@ -542,43 +542,24 @@ HWTEST_F(AppMgrServiceInnerSeventhTest, GetAllRunningInstanceKeysByBundleName_00 TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleName_001 start"); auto appMgrServiceInner = std::make_shared(); AAFwk::MyStatus::GetInstance().verifyCallingPermission_ = false; - - std::string bundleName = ""; - std::vector instanceKeys; - int32_t userId = 0; - int32_t ret = appMgrServiceInner->GetAllRunningInstanceKeysByBundleName(bundleName, instanceKeys, userId); - EXPECT_EQ(ret, ERR_PERMISSION_DENIED); - TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleName_001 end"); -} - -/** -* @tc.name: GetAllRunningInstanceKeysByBundleNameInner_001 -* @tc.desc: test GetAllRunningInstanceKeysByBundleNameInner_001 -* @tc.type: FUNC -*/ -HWTEST_F(AppMgrServiceInnerSeventhTest, GetAllRunningInstanceKeysByBundleNameInner_001, TestSize.Level1) -{ - TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleNameInner_001 start"); - auto appMgrServiceInner = std::make_shared(); - AAFwk::MyStatus::GetInstance().verifyCallingPermission_ = false; AAFwk::MyStatus::GetInstance().getBundleManagerHelper_ = nullptr; std::string bundleName = "111"; std::vector instanceKeys; int32_t userId = 0; - int32_t ret = appMgrServiceInner->GetAllRunningInstanceKeysByBundleNameInner(bundleName, instanceKeys, userId); + int32_t ret = appMgrServiceInner->GetAllRunningInstanceKeysByBundleName(bundleName, instanceKeys, userId); EXPECT_EQ(ret, ERR_INVALID_VALUE); - TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleNameInner_001 end"); + TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleName_001 end"); } /** -* @tc.name: GetAllRunningInstanceKeysByBundleNameInner_002 -* @tc.desc: test GetAllRunningInstanceKeysByBundleNameInner_002 +* @tc.name: GetAllRunningInstanceKeysByBundleName_002 +* @tc.desc: test GetAllRunningInstanceKeysByBundleName_002 * @tc.type: FUNC */ -HWTEST_F(AppMgrServiceInnerSeventhTest, GetAllRunningInstanceKeysByBundleNameInner_002, TestSize.Level1) +HWTEST_F(AppMgrServiceInnerSeventhTest, GetAllRunningInstanceKeysByBundleName_002, TestSize.Level1) { - TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleNameInner_002 start"); + TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleName_002 start"); auto appMgrServiceInner = std::make_shared(); appMgrServiceInner->appRunningManager_ = nullptr; AAFwk::MyStatus::GetInstance().getBundleManagerHelper_ = std::make_shared(); @@ -591,19 +572,19 @@ HWTEST_F(AppMgrServiceInnerSeventhTest, GetAllRunningInstanceKeysByBundleNameInn std::string bundleName = "111"; std::vector instanceKeys; int32_t userId = 0; - int32_t ret = appMgrServiceInner->GetAllRunningInstanceKeysByBundleNameInner(bundleName, instanceKeys, userId); + int32_t ret = appMgrServiceInner->GetAllRunningInstanceKeysByBundleName(bundleName, instanceKeys, userId); EXPECT_EQ(ret, ERR_INVALID_VALUE); - TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleNameInner_002 end"); + TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleName_002 end"); } /** -* @tc.name: GetAllRunningInstanceKeysByBundleNameInner_003 -* @tc.desc: test GetAllRunningInstanceKeysByBundleNameInner_003 +* @tc.name: GetAllRunningInstanceKeysByBundleName_003 +* @tc.desc: test GetAllRunningInstanceKeysByBundleName_003 * @tc.type: FUNC */ -HWTEST_F(AppMgrServiceInnerSeventhTest, GetAllRunningInstanceKeysByBundleNameInner_003, TestSize.Level1) +HWTEST_F(AppMgrServiceInnerSeventhTest, GetAllRunningInstanceKeysByBundleName_003, TestSize.Level1) { - TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleNameInner_003 start"); + TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleName_003 start"); auto appMgrServiceInner = std::make_shared(); AAFwk::MyStatus::GetInstance().verifyCallingPermission_ = false; AAFwk::MyStatus::GetInstance().getBundleManagerHelper_ = std::make_shared(); @@ -614,19 +595,19 @@ HWTEST_F(AppMgrServiceInnerSeventhTest, GetAllRunningInstanceKeysByBundleNameInn std::string bundleName = "111"; std::vector instanceKeys; int32_t userId = 0; - int32_t ret = appMgrServiceInner->GetAllRunningInstanceKeysByBundleNameInner(bundleName, instanceKeys, userId); + int32_t ret = appMgrServiceInner->GetAllRunningInstanceKeysByBundleName(bundleName, instanceKeys, userId); EXPECT_EQ(ret, ERR_MULTI_INSTANCE_NOT_SUPPORTED); - TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleNameInner_003 end"); + TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleName_003 end"); } /** -* @tc.name: GetAllRunningInstanceKeysByBundleNameInner_004 -* @tc.desc: test GetAllRunningInstanceKeysByBundleNameInner_004 +* @tc.name: GetAllRunningInstanceKeysByBundleName_004 +* @tc.desc: test GetAllRunningInstanceKeysByBundleName_004 * @tc.type: FUNC */ -HWTEST_F(AppMgrServiceInnerSeventhTest, GetAllRunningInstanceKeysByBundleNameInner_004, TestSize.Level1) +HWTEST_F(AppMgrServiceInnerSeventhTest, GetAllRunningInstanceKeysByBundleName_004, TestSize.Level1) { - TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleNameInner_004 start"); + TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleName_004 start"); auto appMgrServiceInner = std::make_shared(); AAFwk::MyStatus::GetInstance().verifyCallingPermission_ = false; AAFwk::MyStatus::GetInstance().getBundleManagerHelper_ = std::make_shared(); @@ -640,19 +621,19 @@ HWTEST_F(AppMgrServiceInnerSeventhTest, GetAllRunningInstanceKeysByBundleNameInn std::string bundleName = "111"; std::vector instanceKeys; int32_t userId = 0; - int32_t ret = appMgrServiceInner->GetAllRunningInstanceKeysByBundleNameInner(bundleName, instanceKeys, userId); + int32_t ret = appMgrServiceInner->GetAllRunningInstanceKeysByBundleName(bundleName, instanceKeys, userId); EXPECT_EQ(ret, ERR_OK); - TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleNameInner_004 end"); + TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleName_004 end"); } /** -* @tc.name: GetAllRunningInstanceKeysByBundleNameInner_005 -* @tc.desc: test GetAllRunningInstanceKeysByBundleNameInner_005 +* @tc.name: GetAllRunningInstanceKeysByBundleName_005 +* @tc.desc: test GetAllRunningInstanceKeysByBundleName_005 * @tc.type: FUNC */ -HWTEST_F(AppMgrServiceInnerSeventhTest, GetAllRunningInstanceKeysByBundleNameInner_005, TestSize.Level1) +HWTEST_F(AppMgrServiceInnerSeventhTest, GetAllRunningInstanceKeysByBundleName_005, TestSize.Level1) { - TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleNameInner_005 start"); + TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleName_005 start"); auto appMgrServiceInner = std::make_shared(); AAFwk::MyStatus::GetInstance().verifyCallingPermission_ = false; AAFwk::MyStatus::GetInstance().getBundleManagerHelper_ = std::make_shared(); @@ -670,19 +651,19 @@ HWTEST_F(AppMgrServiceInnerSeventhTest, GetAllRunningInstanceKeysByBundleNameInn std::string bundleName = "111"; std::vector instanceKeys; int32_t userId = 0; - int32_t ret = appMgrServiceInner->GetAllRunningInstanceKeysByBundleNameInner(bundleName, instanceKeys, userId); + int32_t ret = appMgrServiceInner->GetAllRunningInstanceKeysByBundleName(bundleName, instanceKeys, userId); EXPECT_EQ(ret, ERR_OK); - TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleNameInner_005 end"); + TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleName_005 end"); } /** -* @tc.name: GetAllRunningInstanceKeysByBundleNameInner_006 -* @tc.desc: test GetAllRunningInstanceKeysByBundleNameInner_006 +* @tc.name: GetAllRunningInstanceKeysByBundleName_006 +* @tc.desc: test GetAllRunningInstanceKeysByBundleName_006 * @tc.type: FUNC */ -HWTEST_F(AppMgrServiceInnerSeventhTest, GetAllRunningInstanceKeysByBundleNameInner_006, TestSize.Level1) +HWTEST_F(AppMgrServiceInnerSeventhTest, GetAllRunningInstanceKeysByBundleName_006, TestSize.Level1) { - TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleNameInner_006 start"); + TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleName_006 start"); auto appMgrServiceInner = std::make_shared(); AAFwk::MyStatus::GetInstance().verifyCallingPermission_ = false; AAFwk::MyStatus::GetInstance().getBundleManagerHelper_ = std::make_shared(); @@ -699,10 +680,10 @@ HWTEST_F(AppMgrServiceInnerSeventhTest, GetAllRunningInstanceKeysByBundleNameInn std::string bundleName = "111"; std::vector instanceKeys; - int32_t userId = 1; - int32_t ret = appMgrServiceInner->GetAllRunningInstanceKeysByBundleNameInner(bundleName, instanceKeys, userId); + int32_t userId = 100; + int32_t ret = appMgrServiceInner->GetAllRunningInstanceKeysByBundleName(bundleName, instanceKeys, userId); EXPECT_EQ(ret, ERR_OK); - TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleNameInner_006 end"); + TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleName_006 end"); } /** 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 e8bb5daeb20..73f0921899c 100644 --- a/test/unittest/app_mgr_service_inner_tenth_test/BUILD.gn +++ b/test/unittest/app_mgr_service_inner_tenth_test/BUILD.gn @@ -109,6 +109,7 @@ 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 = [ @@ -146,6 +147,7 @@ ohos_unittest("app_mgr_service_inner_tenth_test") { "safwk:system_ability_fwk", "samgr:samgr_proxy", "selinux_adapter:librestorecon", + "window_manager:libdm", "window_manager:session_manager_lite", ] defines = [] diff --git a/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp b/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp index 5e71b1afaed..1ea9e5ff6e5 100644 --- a/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp +++ b/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp @@ -5666,7 +5666,8 @@ HWTEST_F(AppMgrServiceInnerTest, GetAllRunningInstanceKeysByBundleName_001, Test std::string bundleName = "testBundleName"; std::vector instanceKeys; - int32_t ret = appMgrServiceInner->GetAllRunningInstanceKeysByBundleName(bundleName, instanceKeys); + int32_t userId = 100; + int32_t ret = appMgrServiceInner->GetAllRunningInstanceKeysByBundleName(bundleName, instanceKeys, userId); EXPECT_NE(ret, ERR_OK); TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleName_001 end"); diff --git a/test/unittest/app_mgr_stub_test/app_mgr_stub_test.cpp b/test/unittest/app_mgr_stub_test/app_mgr_stub_test.cpp index 4902d04b182..94cd7b99ea5 100644 --- a/test/unittest/app_mgr_stub_test/app_mgr_stub_test.cpp +++ b/test/unittest/app_mgr_stub_test/app_mgr_stub_test.cpp @@ -793,7 +793,7 @@ HWTEST_F(AppMgrStubTest, GetAllRunningInstanceKeysByBundleName_001, TestSize.Lev int32_t userId = -1; data.WriteInt32(userId); - EXPECT_CALL(*mockAppMgrService_, GetAllRunningInstanceKeysByBundleName(_, _, _)).Times(1); + EXPECT_CALL(*mockAppMgrService_, GetAllRunningInstanceKeysByBundleName(_, _)).Times(1); auto result = mockAppMgrService_->OnRemoteRequest( static_cast(AppMgrInterfaceCode::GET_All_RUNNING_INSTANCE_KEYS_BY_BUNDLENAME), data, reply, option); diff --git a/test/unittest/app_service_extension_context_test/ability_manager_stub_mock.h b/test/unittest/app_service_extension_context_test/ability_manager_stub_mock.h index a1966874fbb..5a830a13156 100644 --- a/test/unittest/app_service_extension_context_test/ability_manager_stub_mock.h +++ b/test/unittest/app_service_extension_context_test/ability_manager_stub_mock.h @@ -194,7 +194,7 @@ public: return; } - int StartUser(int userId, sptr callback, bool isAppRecovery) override + int StartUser(int userId, uint64_t displayId, sptr callback, bool isAppRecovery) override { return 0; } diff --git a/test/unittest/cache_process_manager_second_test/BUILD.gn b/test/unittest/cache_process_manager_second_test/BUILD.gn index 7e9b86f4e81..855c317480d 100644 --- a/test/unittest/cache_process_manager_second_test/BUILD.gn +++ b/test/unittest/cache_process_manager_second_test/BUILD.gn @@ -118,6 +118,7 @@ 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 = [ @@ -183,6 +184,7 @@ ohos_unittest("cache_process_manager_second_test") { external_deps += [ "i18n:i18n_sa_client", "i18n:intl_util", + "window_manager:libdm", "window_manager:libwm", "window_manager:libwsutils", ] diff --git a/test/unittest/frameworks_kits_ability_ability_runtime_test/mock_ability_manager_client.cpp b/test/unittest/frameworks_kits_ability_ability_runtime_test/mock_ability_manager_client.cpp index b46525e93d3..ad8fa786874 100644 --- a/test/unittest/frameworks_kits_ability_ability_runtime_test/mock_ability_manager_client.cpp +++ b/test/unittest/frameworks_kits_ability_ability_runtime_test/mock_ability_manager_client.cpp @@ -564,7 +564,8 @@ ErrCode AbilityManagerClient::StopSyncRemoteMissions(const std::string &devId) return ERR_OK; } -ErrCode AbilityManagerClient::StartUser(int accountId, sptr callback, bool isAppRecovery) +ErrCode AbilityManagerClient::StartUser(int accountId, uint64_t displayId, sptr callback, + bool isAppRecovery) { return ERR_OK; } diff --git a/test/unittest/keep_alive_process_manager_test/mock/include/ability_manager_service.h b/test/unittest/keep_alive_process_manager_test/mock/include/ability_manager_service.h index 4fe12fc613f..acfcb6ed89c 100644 --- a/test/unittest/keep_alive_process_manager_test/mock/include/ability_manager_service.h +++ b/test/unittest/keep_alive_process_manager_test/mock/include/ability_manager_service.h @@ -50,12 +50,6 @@ public: bool IsSceneBoardReady(int32_t userId); - /** - * get the user id. - * - */ - int32_t GetUserId() const; - /** * Starts a new ability with specific start options. * @@ -88,6 +82,8 @@ public: int32_t userId = DEFAULT_INVAL_VALUE, AppExecFwk::ExtensionAbilityType extensionType = AppExecFwk::ExtensionAbilityType::UNSPECIFIED); + int32_t GetCallerUserId() const; + public: static bool isInStatusBarResult; static bool isSupportStatusBarResult; diff --git a/test/unittest/keep_alive_process_manager_test/mock/src/ability_manager_service.cpp b/test/unittest/keep_alive_process_manager_test/mock/src/ability_manager_service.cpp index dffa2d0e0cd..7be7e287e19 100644 --- a/test/unittest/keep_alive_process_manager_test/mock/src/ability_manager_service.cpp +++ b/test/unittest/keep_alive_process_manager_test/mock/src/ability_manager_service.cpp @@ -56,11 +56,6 @@ bool AbilityManagerService::IsSceneBoardReady(int32_t userId) return isSceneBoardReadyResult; } -int32_t AbilityManagerService::GetUserId() const -{ - return userId_; -} - int32_t AbilityManagerService::StartAbility(const Want &want, const StartOptions &startOptions, const sptr &callerToken, int32_t userId, int requestCode) { @@ -77,5 +72,11 @@ int32_t AbilityManagerService::StartExtensionAbility(const Want &want, const spt usedStartExtensionAbilityTimes++; return startExtensionAbilityResult; } + +int32_t AbilityManagerService::GetCallerUserId() const +{ + int32_t userId = 100; + return userId; +} } // namespace AAFwk } // namespace OHOS diff --git a/test/unittest/multi_app_utils_test/include/mock_app_mgr_service.h b/test/unittest/multi_app_utils_test/include/mock_app_mgr_service.h index c11b4ec4954..b4c11a5ffe5 100644 --- a/test/unittest/multi_app_utils_test/include/mock_app_mgr_service.h +++ b/test/unittest/multi_app_utils_test/include/mock_app_mgr_service.h @@ -92,8 +92,8 @@ public: MOCK_METHOD3(GetRunningProcessInformation, int32_t(const std::string & bundleName, int32_t userId, std::vector &info)); MOCK_METHOD1(GetAllRunningInstanceKeysBySelf, int32_t(std::vector &instanceKeys)); - MOCK_METHOD3(GetAllRunningInstanceKeysByBundleName, int32_t(const std::string &bundleName, - std::vector &instanceKeys, int32_t userId)); + MOCK_METHOD2(GetAllRunningInstanceKeysByBundleName, int32_t(const std::string &bundleName, + std::vector &instanceKeys)); MOCK_METHOD2(IsApplicationRunning, int32_t(const std::string &bundleName, bool &isRunning)); MOCK_METHOD3(IsAppRunning, int32_t(const std::string &bundleName, int32_t appCloneIndex, bool &isRunning)); diff --git a/test/unittest/service_extension_context_test/ability_manager_stub_mock.h b/test/unittest/service_extension_context_test/ability_manager_stub_mock.h index a1966874fbb..5a830a13156 100644 --- a/test/unittest/service_extension_context_test/ability_manager_stub_mock.h +++ b/test/unittest/service_extension_context_test/ability_manager_stub_mock.h @@ -194,7 +194,7 @@ public: return; } - int StartUser(int userId, sptr callback, bool isAppRecovery) override + int StartUser(int userId, uint64_t displayId, sptr callback, bool isAppRecovery) override { return 0; } diff --git a/test/unittest/sys_mgr_client_test/mock_ability_manager_service.h b/test/unittest/sys_mgr_client_test/mock_ability_manager_service.h index 7085639344e..d7dc02281d9 100644 --- a/test/unittest/sys_mgr_client_test/mock_ability_manager_service.h +++ b/test/unittest/sys_mgr_client_test/mock_ability_manager_service.h @@ -151,7 +151,7 @@ public: MOCK_METHOD4(ShareDataDone, int32_t(const sptr &token, const int32_t &resultCode, const int32_t &uniqueId, WantParams &wantParam)); - int StartUser(int userId, sptr callback, bool isAppRecovery) override + int StartUser(int userId, uint64_t displayId, sptr callback, bool isAppRecovery) override { return 0; } diff --git a/test/unittest/ui_ability_lifecycle_manager_test/ui_ability_lifecycle_manager_test.cpp b/test/unittest/ui_ability_lifecycle_manager_test/ui_ability_lifecycle_manager_test.cpp index c88cbeb4de3..d50a4028346 100644 --- a/test/unittest/ui_ability_lifecycle_manager_test/ui_ability_lifecycle_manager_test.cpp +++ b/test/unittest/ui_ability_lifecycle_manager_test/ui_ability_lifecycle_manager_test.cpp @@ -3161,7 +3161,7 @@ HWTEST_F(UIAbilityLifecycleManagerTest, GetActiveAbilityList_002, TestSize.Level abilityRequest.abilityInfo.bundleName = "com.example.unittest"; abilityRequest.abilityInfo.applicationInfo.uid = TEST_UID; auto abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest); - abilityRecord->SetOwnerMissionUserId(DelayedSingleton::GetInstance()->GetUserId()); + abilityRecord->SetOwnerMissionUserId(DelayedSingleton::GetInstance()->GetCallerUserId()); uiAbilityLifecycleManager->sessionAbilityMap_.emplace(1, abilityRecord); std::vector abilityList; int32_t pid = 100; diff --git a/test/unittest/ui_ability_lifecycle_manager_third_test/mock/include/mock_app_mgr_service.h b/test/unittest/ui_ability_lifecycle_manager_third_test/mock/include/mock_app_mgr_service.h index 25a36af0fa2..893e268203f 100644 --- a/test/unittest/ui_ability_lifecycle_manager_third_test/mock/include/mock_app_mgr_service.h +++ b/test/unittest/ui_ability_lifecycle_manager_third_test/mock/include/mock_app_mgr_service.h @@ -92,8 +92,8 @@ public: MOCK_METHOD3(GetRunningProcessInformation, int32_t(const std::string & bundleName, int32_t userId, std::vector &info)); MOCK_METHOD1(GetAllRunningInstanceKeysBySelf, int32_t(std::vector &instanceKeys)); - MOCK_METHOD3(GetAllRunningInstanceKeysByBundleName, int32_t(const std::string &bundleName, - std::vector &instanceKeys, int32_t userId)); + MOCK_METHOD2(GetAllRunningInstanceKeysByBundleName, int32_t(const std::string &bundleName, + std::vector &instanceKeys)); MOCK_METHOD2(IsApplicationRunning, int32_t(const std::string &bundleName, bool &isRunning)); MOCK_METHOD3(IsAppRunning, int32_t(const std::string &bundleName, int32_t appCloneIndex, bool &isRunning)); diff --git a/test/unittest/user_controller_test/user_controller_test.cpp b/test/unittest/user_controller_test/user_controller_test.cpp index 83088ea5f10..3b483a87371 100644 --- a/test/unittest/user_controller_test/user_controller_test.cpp +++ b/test/unittest/user_controller_test/user_controller_test.cpp @@ -93,9 +93,9 @@ HWTEST_F(UserControllerTest, StartUserTest_0100, TestSize.Level0) { UserController userController; userController.GetOrCreateUserItem(1000); - userController.SetCurrentUserId(1000); + userController.SetCurrentUserId(1000, 0); sptr callback = new TestUserCallback(); - userController.StartUser(1000, callback); + userController.StartUser(1000, 0, callback); EXPECT_TRUE(callback->errCode_ == 0); } @@ -109,7 +109,7 @@ HWTEST_F(UserControllerTest, StartUserTest_0200, TestSize.Level0) { UserController userController; sptr callback = new TestUserCallback(); - userController.StartUser(666, callback); + userController.StartUser(666, 0, callback); EXPECT_TRUE(callback->errCode_ != 0); } @@ -192,11 +192,9 @@ HWTEST_F(UserControllerTest, StopUserTest_0300, TestSize.Level0) HWTEST_F(UserControllerTest, LogoutUserTest_0100, TestSize.Level1) { UserController userController; - auto result = userController.LogoutUser(-1, nullptr); - if (!Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { - EXPECT_EQ(result, INVALID_USERID_VALUE); - } - EXPECT_TRUE(userController.GetCurrentUserId() == 0); + int32_t displayId = -1; + auto result = userController.LogoutUser(displayId, nullptr); + EXPECT_EQ(result, INVALID_USERID_VALUE); } /** @@ -208,11 +206,9 @@ HWTEST_F(UserControllerTest, LogoutUserTest_0100, TestSize.Level1) HWTEST_F(UserControllerTest, LogoutUserTest_0200, TestSize.Level1) { UserController userController; - auto result = userController.LogoutUser(666, nullptr); - if (!Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { - EXPECT_EQ(result, INVALID_USERID_VALUE); - } - EXPECT_TRUE(userController.GetCurrentUserId() == 0); + int32_t displayId = 666; + auto result = userController.LogoutUser(displayId, nullptr); + EXPECT_EQ(result, INVALID_USERID_VALUE); } /** @@ -240,7 +236,8 @@ HWTEST_F(UserControllerTest, HandleContinueUserSwitchTest_0100, TestSize.Level2) UserController userController; auto userItem = std::make_shared(1000); userController.HandleContinueUserSwitch(1000, 1000, userItem); - auto result = userController.GetCurrentUserId(); + int32_t displayId = 666; + auto result = userController.GetCurrentUserId(displayId); EXPECT_TRUE(result == 0); } @@ -256,7 +253,8 @@ HWTEST_F(UserControllerTest, SendUserSwitchDoneTest_0100, TestSize.Level2) userController.SendUserSwitchDone(1000); userController.Init(); userController.SendUserSwitchDone(1001); - auto result = userController.GetCurrentUserId(); + int32_t displayId = 666; + auto result = userController.GetCurrentUserId(displayId); EXPECT_TRUE(result == 0); } @@ -273,7 +271,8 @@ HWTEST_F(UserControllerTest, SendContinueUserSwitchTest_0200, TestSize.Level2) userController.SendContinueUserSwitch(1000, 1000, userItem); userController.Init(); userController.SendContinueUserSwitch(1000, 1000, userItem); - auto result = userController.GetCurrentUserId(); + int32_t displayId = 666; + auto result = userController.GetCurrentUserId(displayId); EXPECT_TRUE(result == 0); } @@ -290,7 +289,8 @@ HWTEST_F(UserControllerTest, SendUserSwitchTimeoutTest_0100, TestSize.Level2) userController.SendUserSwitchTimeout(1000, 1000, userItem); userController.Init(); userController.SendUserSwitchTimeout(1000, 1000, userItem); - auto result = userController.GetCurrentUserId(); + int32_t displayId = 666; + auto result = userController.GetCurrentUserId(displayId); EXPECT_TRUE(result == 0); } @@ -307,7 +307,8 @@ HWTEST_F(UserControllerTest, SendReportUserSwitchTest_0100, TestSize.Level2) userController.SendReportUserSwitch(1000, 1000, userItem); userController.Init(); userController.SendReportUserSwitch(1000, 1000, userItem); - auto result = userController.GetCurrentUserId(); + int32_t displayId = 666; + auto result = userController.GetCurrentUserId(displayId); EXPECT_TRUE(result == 0); } @@ -323,7 +324,8 @@ HWTEST_F(UserControllerTest, SendSystemUserCurrentTest_0100, TestSize.Level2) userController.SendSystemUserCurrent(1000, 1000); userController.Init(); userController.SendSystemUserCurrent(1000, 1000); - auto result = userController.GetCurrentUserId(); + int32_t displayId = 666; + auto result = userController.GetCurrentUserId(displayId); EXPECT_TRUE(result == 0); } @@ -339,8 +341,57 @@ HWTEST_F(UserControllerTest, SendSystemUserStartTest_0100, TestSize.Level2) userController.SendSystemUserStart(1000); userController.Init(); userController.SendSystemUserStart(1000); - auto result = userController.GetCurrentUserId(); + int32_t displayId = 666; + auto result = userController.GetCurrentUserId(displayId); EXPECT_TRUE(result == 0); } + +/** + * @tc.name: GetDisplayIdByUserIdTest_0100 + * @tc.desc: GetDisplayIdByUserId Test + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(UserControllerTest, GetDisplayIdByUserId_0100, TestSize.Level1) +{ + UserController userController; + int32_t userId = 201; + uint64_t displayIdParam = 11; + userController.SetCurrentUserId(userId, displayIdParam); + uint64_t displayId = 0; + auto ret = userController.GetDisplayIdByUserId(userId, displayId); + EXPECT_EQ(displayId, displayIdParam); +} + +/** + * @tc.name: IsCurrentUserTest_0100 + * @tc.desc: IsCurrentUser Test + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(UserControllerTest, IsCurrentUser_0100, TestSize.Level1) +{ + UserController userController; + int32_t userId = 201; + uint64_t displayIdParam = 11; + userController.SetCurrentUserId(userId, displayIdParam); + auto result = userController.IsCurrentUser(userId, displayIdParam); + EXPECT_TRUE(result); +} + +/** + * @tc.name: IsCurrentUserTest_0200 + * @tc.desc: IsCurrentUser Test + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(UserControllerTest, IsCurrentUser_0200, TestSize.Level1) +{ + UserController userController; + int32_t userId = 202; + uint64_t displayIdParam = 11; + auto result = userController.IsCurrentUser(userId, displayIdParam); + EXPECT_FALSE(result); +} } // namespace AAFwk } // namespace OHOS diff --git a/test/unittest/user_event_handler_test/user_event_handler_test.cpp b/test/unittest/user_event_handler_test/user_event_handler_test.cpp index 687bf381299..37a1a65c02b 100755 --- a/test/unittest/user_event_handler_test/user_event_handler_test.cpp +++ b/test/unittest/user_event_handler_test/user_event_handler_test.cpp @@ -50,8 +50,7 @@ void UserEventHandlerTest::TearDown(void) HWTEST_F(UserEventHandlerTest, ProcessEvent_001, TestSize.Level1) { std::shared_ptr runner; - std::weak_ptr owner; - std::shared_ptr handler = std::make_shared(runner, owner); + std::shared_ptr handler = std::make_shared(runner); EventWrap event(0); handler->ProcessEvent(event); EXPECT_TRUE(handler != nullptr); diff --git a/test/unittest/user_manager_test/BUILD.gn b/test/unittest/user_manager_test/BUILD.gn new file mode 100644 index 00000000000..1c0b34e85f0 --- /dev/null +++ b/test/unittest/user_manager_test/BUILD.gn @@ -0,0 +1,62 @@ +# Copyright (c) 2025 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. + +import("//build/test.gni") +import("//foundation/ability/ability_runtime/ability_runtime.gni") + +module_output_path = "ability_runtime/ability_runtime/abilitymgr" + +ohos_unittest("user_manager_test") { + module_out_path = module_output_path + + sources = [ "user_manager_test.cpp" ] + + configs = [ "${ability_runtime_services_path}/abilitymgr:abilityms_config" ] + + deps = [ + "${ability_runtime_innerkits_path}/ability_manager:ability_manager", + "${ability_runtime_services_path}/abilitymgr:abilityms", + "${ability_runtime_services_path}/common:user_controller", + ] + + external_deps = [ + "ability_base:session_info", + "ability_base:want", + "ability_runtime:ability_deps_wrapper", + "ability_runtime:app_manager", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "common_event_service:cesfwk_innerkits", + "eventhandler:libeventhandler", + "ffrt:libffrt", + "hilog:libhilog", + "hisysevent:libhisysevent", + "image_framework:image_native", + "ipc:ipc_core", + "safwk:api_cache_manager", + ] + + if (ability_runtime_graphics) { + external_deps += [ + "window_manager:libwsutils", + "window_manager:scene_session", + ] + } +} + +group("unittest") { + testonly = true + + deps = [ ":user_manager_test" ] +} diff --git a/test/unittest/user_manager_test/user_manager_test.cpp b/test/unittest/user_manager_test/user_manager_test.cpp new file mode 100644 index 00000000000..c94bba1aa9f --- /dev/null +++ b/test/unittest/user_manager_test/user_manager_test.cpp @@ -0,0 +1,128 @@ +/* + * 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. + */ + +#include + +#define private public +#include "user_controller/user_manager.h" +#undef private +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace AbilityRuntime { +class UserManagerTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp() override; + void TearDown() override; +}; + +void UserManagerTest::SetUpTestCase() {} +void UserManagerTest::TearDownTestCase() {} +void UserManagerTest::SetUp() {} +void UserManagerTest::TearDown() {} + +/** + * @tc.name: ClearUserId_0100 + * @tc.desc: ClearUserId Test + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(UserManagerTest, ClearUserId_0100, TestSize.Level1) +{ + int32_t userId = 201; + uint64_t displayIdParam = 11; + UserManager::GetInstance().SetCurrentUserId(userId, displayIdParam); + int32_t mapSize = UserManager::GetInstance().displayIdMap_.size(); + UserManager::GetInstance().ClearUserId(userId); + EXPECT_EQ(UserManager::GetInstance().displayIdMap_.size(), (mapSize - 1)); +} + +/** + * @tc.name: IsCurrentUserTest_0100 + * @tc.desc: IsCurrentUser Test + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(UserManagerTest, IsCurrentUser_0100, TestSize.Level1) +{ + int32_t userId = 202; + auto result = UserManager::GetInstance().IsCurrentUser(userId); + EXPECT_FALSE(result); +} + +/** + * @tc.name: IsCurrentUserTest_0200 + * @tc.desc: IsCurrentUser Test + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(UserManagerTest, IsCurrentUser_0200, TestSize.Level1) +{ + int32_t userId = 201; + uint64_t displayIdParam = 11; + UserManager::GetInstance().SetCurrentUserId(userId, displayIdParam); + auto result = UserManager::GetInstance().IsCurrentUser(userId); + EXPECT_TRUE(result); +} + +/** + * @tc.name: GetCurrentUserId_0100 + * @tc.desc: GetCurrentUserId Test + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(UserManagerTest, GetCurrentUserId_0100, TestSize.Level1) +{ + int32_t userIdParam = 201; + uint64_t displayId = 11; + UserManager::GetInstance().SetCurrentUserId(userIdParam, displayId); + auto useId = UserManager::GetInstance().GetCurrentUserId(displayId); + EXPECT_EQ(useId, userIdParam); +} + +/** + * @tc.name: GetDisplayIdByUserIdTest_0100 + * @tc.desc: GetDisplayIdByUserId Test + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(UserManagerTest, GetDisplayIdByUserId_0100, TestSize.Level1) +{ + int32_t userId = 202; + uint64_t displayId = 0; + auto ret = UserManager::GetInstance().GetDisplayIdByUserId(userId, displayId); + EXPECT_EQ(displayId, 0); +} + +/** + * @tc.name: GetDisplayIdByUserIdTest_0200 + * @tc.desc: GetDisplayIdByUserId Test + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(UserManagerTest, GetDisplayIdByUserId_0200, TestSize.Level1) +{ + int32_t userId = 201; + uint64_t displayIdParam = 11; + UserManager::GetInstance().SetCurrentUserId(userId, displayIdParam); + uint64_t displayId = 0; + auto ret = UserManager::GetInstance().GetDisplayIdByUserId(userId, displayId); + EXPECT_EQ(displayId, displayIdParam); +} +} // namespace AAFwk +} // namespace OHOS diff --git a/tools/test/mock/mock_ability_manager_stub.h b/tools/test/mock/mock_ability_manager_stub.h index 0f0e3a697c5..217fcdc52de 100644 --- a/tools/test/mock/mock_ability_manager_stub.h +++ b/tools/test/mock/mock_ability_manager_stub.h @@ -146,7 +146,7 @@ public: return 0; } - int StartUser(int userId, sptr callback, bool isAppRecovery) override + int StartUser(int userId, uint64_t displayId, sptr callback, bool isAppRecovery) override { return 0; } -- Gitee