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 52bcb2d2f08217293331b7deb025f90d3451ec09..09cf94cef55cbac6bba9ec36f19e46c7a6027bf8 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_client.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_client.h @@ -999,11 +999,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 4d576a8f5043743b07fb52f0bf550a1b7e519d7d..5a9b6d877700030916ae22dc3836c55a83960d4b 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_interface.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_interface.h @@ -1052,10 +1052,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 64107d3c7e7744895934d180f5d19caef4caa120..0affb0c6f9f552af9b302b1c5007e9f1602a5849 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 @@ -279,11 +279,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 24a2fa8b5f7ab97becaefda63a6c0ca587632375..6a99820ed873a5b7da198195454ccc73d6723c66 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 @@ -180,11 +180,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 ef07c9093e005fd56953b47f4c2cf39003211655..11173cdf1da4dead50d59d5f9f4653c6384120d8 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 @@ -150,11 +150,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 232f8be1f975aab0cb2d2dc30292f200690fb8b4..018cce76cc1b2ba1ba782109aac2a6e3c0dfe07d 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 @@ -483,11 +483,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 7e462bbc760a1694c51103bcc4315a75ae0fa9ca..ab4d367c622ae912ed741c24ce7d9225b282b811 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 @@ -241,7 +241,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; @@ -250,7 +250,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 dfb99f71cddb6cc200cfcc5adb2030d39eaa8470..113ee52fb4b939632957ab909144b11bc0d64d89 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 @@ -545,9 +545,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 b0fd3beeac876bf5434115ebc2555215b245e4e8..df3c2640c56f0624aa0abea8bdd44a33f95a1ee3 100644 --- a/services/abilitymgr/BUILD.gn +++ b/services/abilitymgr/BUILD.gn @@ -151,6 +151,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_manager_proxy.h b/services/abilitymgr/include/ability_manager_proxy.h index 19d4bf6155ae102cb1f29da7b13d8811ef111e12..233825c5e9e83be5ccd29b0d6c1b85e954c0ad64 100644 --- a/services/abilitymgr/include/ability_manager_proxy.h +++ b/services/abilitymgr/include/ability_manager_proxy.h @@ -840,10 +840,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 24ff8c79fa2486dc07311ecd2813e3ef8f214dea..6d4b2d617546d0f339671b982e4258633b130269 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -1203,7 +1203,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; @@ -1583,7 +1584,7 @@ public: * get the user id. * */ - int32_t GetUserId() const; + int32_t GetCallerUserId() const; virtual int32_t RegisterStatusBarDelegate(sptr delegate) override; @@ -2162,7 +2163,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. @@ -2271,7 +2272,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(); @@ -2679,7 +2680,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 c516fb9206ae69ed6f61eade304529cd81c74bf6..44906a110963aa2ac1686196c4ba4d2552301789 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,7 +95,9 @@ public: */ int32_t LogoutUser(int32_t userId, sptr callback = nullptr); - int32_t GetCurrentUserId(); + int32_t GetCurrentUserId(uint64_t displayId); + + bool GetDisplayIdByUserId(int32_t userId, uint64_t &displayId); std::shared_ptr GetUserItem(int32_t userId); @@ -104,12 +109,15 @@ 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); @@ -138,8 +146,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 49b53eb9244f0149c8a6525618f4da132a7d2ca7..75aeab581592c4ce44a907969904000b3888c451 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 65832ba509c48e23ca58f51e98f1379b4acff835..5eaf3884b631b5b7c312af9ad9f2a24ed7dd420e 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 374063092a4836cd6ea62efb366d3327ce58960c..c2dabeecb8a0dd4291fcdebe7136320a6608c9a0 100644 --- a/services/abilitymgr/src/ability_auto_startup_service.cpp +++ b/services/abilitymgr/src/ability_auto_startup_service.cpp @@ -425,7 +425,7 @@ bool AbilityAutoStartupService::GetBundleInfo(const std::string &bundleName, TAG_LOGE(AAFwkTag::AUTO_STARTUP, "null abilityMgr"); return false; } - userId = abilityMgr->GetUserId(); + userId = abilityMgr->GetCallerUserId(); } TAG_LOGD(AAFwkTag::AUTO_STARTUP, "bundleName: %{public}s, userId: %{public}d, appIndex: %{public}d", bundleName.c_str(), userId, appIndex); diff --git a/services/abilitymgr/src/ability_connect_manager.cpp b/services/abilitymgr/src/ability_connect_manager.cpp index 9e9ea24d5b63211802f8c47f6d04322b478a4400..117cdbbb622bf36051eb08c95c128dc9d45b1d82 100644 --- a/services/abilitymgr/src/ability_connect_manager.cpp +++ b/services/abilitymgr/src/ability_connect_manager.cpp @@ -1733,7 +1733,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; @@ -2321,8 +2321,7 @@ void AbilityConnectManager::CleanActivatingTimeoutAbility(std::shared_ptrIsSceneBoard() || - DelayedSingleton::GetInstance()->GetUserId() == userId_) { + if (!abilityRecord->IsSceneBoard() || UserController::GetInstance().IsCurrentUser(userId_)) { RestartAbility(abilityRecord, userId_); } } @@ -2638,6 +2637,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("ohos.ability.displayId", 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 725fe34e76ff658d22d61659dc817a6f6cb839b4..187642d608e285254f87f91b4fb5efa782f412c3 100644 --- a/services/abilitymgr/src/ability_manager_client.cpp +++ b/services/abilitymgr/src/ability_manager_client.cpp @@ -1222,13 +1222,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 0a126a60808d930d560de5bc0a49844ba70aab2e..976cb4a4f05a363f49b2d5dc8c45cc0abe9e93eb 100644 --- a/services/abilitymgr/src/ability_manager_proxy.cpp +++ b/services/abilitymgr/src/ability_manager_proxy.cpp @@ -3039,7 +3039,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) { MessageParcel data; if (!WriteInterfaceToken(data)) { @@ -3049,6 +3049,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 c5e3ccdc9ba15788d51d76d8e7d446170798a0d8..ebed0ec1510b4afe82943ddddd036ded99c32f57 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -299,6 +299,7 @@ constexpr const char* BOOTEVENT_BOOT_COMPLETED = "bootevent.boot.completed"; constexpr const char* BOOTEVENT_BOOT_ANIMATION_STARTED = "bootevent.bootanimation.started"; constexpr const char* BOOTEVENT_BOOT_ANIMATION_READY = "bootevent.bootanimation.ready"; constexpr const char* NEED_STARTINGWINDOW = "ohos.ability.NeedStartingWindow"; +constexpr const char* DISPLAY_ID = "ohos.ability.displayId"; constexpr const char* PERMISSIONMGR_BUNDLE_NAME = "com.ohos.permissionmanager"; constexpr const char* PERMISSIONMGR_ABILITY_NAME = "com.ohos.permissionmanager.GrantAbility"; constexpr const char* SCENEBOARD_BUNDLE_NAME = "com.ohos.sceneboard"; @@ -396,8 +397,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_); @@ -906,7 +906,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); @@ -946,7 +946,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) { @@ -1186,7 +1186,7 @@ int AbilityManagerService::StartAbilityInner(const Want &want, const sptrShouldBlockAllAppStart(); }; - 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); @@ -1333,7 +1333,7 @@ int AbilityManagerService::StartAbilityInner(const Want &want, const sptr(abilityInfo), isStartAsCaller, appIndex); result = afterCheckExecuter_ == nullptr ? ERR_INVALID_VALUE : afterCheckExecuter_->DoProcess(afterCheckParam); @@ -1345,12 +1345,12 @@ 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); @@ -1670,7 +1670,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) { @@ -1912,7 +1912,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); @@ -2100,7 +2100,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_INVALID_VALUE : afterCheckExecuter_->DoProcess(afterCheckParam); @@ -2112,12 +2112,12 @@ int AbilityManagerService::StartAbilityForOptionInner(const Want &want, const St } #ifdef SUPPORT_SCREEN if (result != ERR_OK && isReplaceWantExist) { - 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_GRAPHICS auto backFlag = StartAbilityUtils::ermsSupportBackToCallerFlag; @@ -2234,7 +2234,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); @@ -2282,7 +2282,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) { @@ -2502,7 +2502,7 @@ int AbilityManagerService::StartUIAbilityBySCBDefault(sptr sessionI } Want newWant = abilityRequest.want; RemoveUnauthorizedLaunchReasonMessage(sessionInfo->want, abilityRequest, sessionInfo->callerToken); - 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); @@ -2607,7 +2607,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; } @@ -3239,7 +3239,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); @@ -3324,7 +3324,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); @@ -3578,7 +3578,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); @@ -3646,7 +3646,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); @@ -3774,7 +3774,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; } @@ -3785,9 +3785,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; } @@ -4496,7 +4496,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); @@ -4646,7 +4646,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); @@ -4856,7 +4856,7 @@ int32_t AbilityManagerService::ConnectLocalAbility(const Want &want, const int32 return TARGET_ABILITY_NOT_SERVICE; } - 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); @@ -6012,7 +6012,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; @@ -6077,7 +6077,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; @@ -6807,18 +6807,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(); @@ -6868,6 +6859,7 @@ int AbilityManagerService::StartHighestPriorityAbility(int32_t userId, bool isBo #ifdef SUPPORT_GRAPHICS abilityWant.SetParam(NEED_STARTINGWINDOW, false); + abilityWant.SetParam(DISPLAY_ID, static_cast(displayId)); // wait BOOT_ANIMATION_STARTED to start LAUNCHER WaitBootAnimationStart(); #endif @@ -7128,14 +7120,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"); @@ -7179,7 +7171,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), @@ -7728,7 +7720,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; @@ -8118,7 +8110,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); + GetCallerUserId(), appIndex, callerToken); if (checkRet != ERR_OK) { return checkRet; } @@ -8127,9 +8119,9 @@ 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(); }; - AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(want, 0, GetUserId(), true, nullptr, + AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(want, 0, GetCallerUserId(), true, nullptr, shouldBlockFunc); auto result = interceptorExecuter_ == nullptr ? ERR_INVALID_VALUE : interceptorExecuter_->DoProcess(interceptorParam); @@ -8159,7 +8151,7 @@ int AbilityManagerService::StartAbilityByCallWithErrMsg(const Want &want, const abilityRequest.startSetting = nullptr; 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; @@ -8179,7 +8171,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); @@ -8282,9 +8274,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; @@ -8301,10 +8293,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) @@ -8319,11 +8308,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); } @@ -8360,12 +8346,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( @@ -8492,7 +8475,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; } @@ -8810,7 +8793,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)); @@ -8868,10 +8851,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) { @@ -8880,7 +8859,7 @@ void AbilityManagerService::StartSwitchUserDialog() } Want dialogWant = sysDialog->GetSwitchUserDialogWant(); - StartSwitchUserDialogInner(dialogWant, userController_->GetFreezingNewUserId()); + StartSwitchUserDialogInner(dialogWant, UserController::GetInstance().GetFreezingNewUserId()); #endif // SUPPORT_GRAPHICS } @@ -8956,8 +8935,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__, @@ -8970,7 +8949,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); } @@ -8998,9 +8977,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"); @@ -9086,7 +9062,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; @@ -9186,7 +9162,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))) { @@ -9201,7 +9177,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( @@ -9367,15 +9343,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(); } void AbilityManagerService::SendExtensionReport(EventInfo &eventInfo, int32_t errCode, bool isService) @@ -9654,7 +9626,7 @@ void AbilityManagerService::GetAbilityRunningInfo(std::vectorGetCurrentUserId() == userId))) { + if (userId < 0 || GetCallerUserId() == userId) { return ERR_OK; } return AAFwk::PermissionVerification::GetInstance()->VerifyAccountPermission(); @@ -11118,7 +11090,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)); @@ -11282,7 +11254,7 @@ void AbilityManagerService::StartSpecifiedAbilityBySCB(const Want &want) TAG_LOGE(AAFwkTag::ABILITYMGR, "invalid app clone index"); } (void)AbilityPermissionUtil::GetInstance().CheckMultiInstanceAndAppClone(const_cast(want), - GetUserId(), appIndex, nullptr); + GetCallerUserId(), appIndex, nullptr); auto uiAbilityManager = GetUIAbilityManagerByUid(IPCSkeleton::GetCallingUid()); CHECK_POINTER(uiAbilityManager); uiAbilityManager->StartSpecifiedAbilityBySCB(want); @@ -11510,7 +11482,7 @@ int32_t AbilityManagerService::QueryAllAutoStartupApplications(std::vectorQueryAllAutoStartupApplications(infoList, GetUserId()); + return abilityAutoStartupService_->QueryAllAutoStartupApplications(infoList, GetCallerUserId()); } int AbilityManagerService::PrepareTerminateAbilityBySCB(const sptr &sessionInfo, bool &isTerminate) @@ -11765,7 +11737,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; @@ -12039,19 +12011,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); } } @@ -12065,9 +12033,9 @@ void AbilityManagerService::NotifyStartResidentProcess(std::vectorStartResidentProcessWithMainElement( - bundleInfosForCurrentUser, currentUser); - if (!bundleInfosForCurrentUser.empty()) { - residentProcessMgr->StartResidentProcess(bundleInfosForCurrentUser); + bundleInfosForcallerUser, callerUser); + if (!bundleInfosForcallerUser.empty()) { + residentProcessMgr->StartResidentProcess(bundleInfosForcallerUser); } } @@ -12077,7 +12045,7 @@ void AbilityManagerService::NotifyStartKeepAliveProcess(std::vector bundleInfosForCurrentUser; for (const auto &item: bundleInfos) { if (item.uid / BASE_USER_RANGE == userId) { @@ -12286,7 +12254,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; @@ -12324,7 +12292,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); @@ -12729,14 +12697,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, @@ -12772,7 +12740,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); @@ -12784,7 +12752,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; @@ -13369,7 +13337,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); @@ -13421,7 +13389,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); @@ -13433,12 +13401,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 @@ -13925,7 +13893,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, @@ -14257,7 +14225,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 = UserController::GetInstance().GetCurrentUserId(DisplayUtil::ObtainDefaultDisplayId()); + } + return callerUser; } int32_t AbilityManagerService::RestartSelfAtomicService(sptr callerToken) diff --git a/services/abilitymgr/src/ability_manager_stub.cpp b/services/abilitymgr/src/ability_manager_stub.cpp index 2e5e177fdacbf766d071b95e053cd36854fe4616..c0914668804b0562e609f75e9eb747e2d9908e22 100644 --- a/services/abilitymgr/src/ability_manager_stub.cpp +++ b/services/abilitymgr/src/ability_manager_stub.cpp @@ -2428,6 +2428,7 @@ int AbilityManagerStub::ReleaseCallInner(MessageParcel &data, MessageParcel &rep int AbilityManagerStub::StartUserInner(MessageParcel &data, MessageParcel &reply) { int32_t userId = data.ReadInt32(); + auto displayId = data.ReadUint64(); sptr callback = nullptr; if (data.ReadBool()) { callback = iface_cast(data.ReadRemoteObject()); @@ -2436,7 +2437,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 e397275968c428245e38b709bfdd8c2e1931e94c..e22891edc53e7290bcf1d0b3e336d5da5ffcaaa9 100644 --- a/services/abilitymgr/src/keep_alive/ability_keep_alive_service.cpp +++ b/services/abilitymgr/src/keep_alive/ability_keep_alive_service.cpp @@ -110,7 +110,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 63e4b127e153ac3f98d28aaa45d0c5c08d5f3611..107b764101632516e0f1377f10cafe24511405f4 100644 --- a/services/abilitymgr/src/keep_alive/keep_alive_process_manager.cpp +++ b/services/abilitymgr/src/keep_alive/keep_alive_process_manager.cpp @@ -218,7 +218,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 28ce10e3feb309c01e30f24f99d2d73d98b0a3ab..aa68445ed2143cb84ec6522188c68ce3729c2066 100644 --- a/services/abilitymgr/src/resident_process/resident_process_manager.cpp +++ b/services/abilitymgr/src/resident_process/resident_process_manager.cpp @@ -205,7 +205,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 6ad9e0dfbd589a9b5c7379efc0e8170f20fa5b24..1dc008005165a1dc0eab6fb22b3d7e7df6a01fe1 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 { @@ -54,12 +55,10 @@ UserState UserItem::GetState() return curState_; } -UserController::UserController() -{ -} - -UserController::~UserController() +UserController& UserController::GetInstance() { + static UserController instance; + return instance; } void UserController::Init() @@ -72,18 +71,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) { + 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); @@ -95,7 +95,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); callback->OnStartUserDone(userId, ERR_OK); return ERR_OK; @@ -114,13 +114,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) { @@ -129,7 +129,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); @@ -138,7 +138,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 @@ -246,18 +246,19 @@ 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 UserManager::GetInstance().GetCurrentUserId(displayId); +} + +bool UserController::GetDisplayIdByUserId(int32_t userId, uint64_t &displayId) +{ + return UserManager::GetInstance().GetDisplayIdByUserId(userId, displayId); } std::shared_ptr UserController::GetUserItem(int32_t userId) @@ -271,19 +272,21 @@ std::shared_ptr UserController::GetUserItem(int32_t userId) return nullptr; } -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 UserManager::GetInstance().IsCurrentUser(userId); +} + bool UserController::IsExistOsAccount(int32_t userId) const { bool isExist = false; @@ -304,22 +307,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); + 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); } diff --git a/services/abilitymgr/src/user_event_handler.cpp b/services/abilitymgr/src/user_event_handler.cpp index 416b02f11ddbe3b7e757b290f566244582167476..7ad88450db9538a41bf1bbdf0f95599527b4d890 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 81f2ddcdac9ad40f2bd2ad30be8a98b388c027d4..d28182586f1c35f5215ed7daeee4857abeef59b1 100644 --- a/services/appmgr/BUILD.gn +++ b/services/appmgr/BUILD.gn @@ -116,6 +116,7 @@ ohos_shared_library("libappms") { "${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 = [ @@ -176,6 +177,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 59e20caafb63588402ea8c5287d0761d4e2b6fae..a07b6e28a42f00c2db06e8ce254eec40604307fe 100644 --- a/services/appmgr/include/app_mgr_service.h +++ b/services/appmgr/include/app_mgr_service.h @@ -175,11 +175,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 7ec23b29aa46377b03cce1d6a80e9b0ddd1b6d24..327a05842126ff732d795716cbbfbe626a654ca5 100644 --- a/services/appmgr/include/app_mgr_service_inner.h +++ b/services/appmgr/include/app_mgr_service_inner.h @@ -430,7 +430,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. @@ -1965,7 +1965,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(); @@ -2003,8 +2002,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 IsAllowedNWebPreload(const std::string &processName); diff --git a/services/appmgr/src/app_mgr_service.cpp b/services/appmgr/src/app_mgr_service.cpp index 4a2fd8a7b5bc9f9da7093d3f881e9511e6547e8e..befa46ab7cc54570e0a3cd3da6bdad6df4ffe1e5 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" @@ -399,8 +401,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; } @@ -421,11 +423,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); } @@ -435,6 +445,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 da097a5f2d7e6f2a65fe99e94109b5810fa75be4..2715548cf97bef108bb41ec472f7fc85d7e1ee27 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -44,6 +44,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" @@ -103,6 +104,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" @@ -117,6 +119,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; @@ -279,7 +282,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; @@ -528,8 +530,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"); @@ -2053,16 +2058,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"); } @@ -2078,9 +2082,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, @@ -2178,17 +2179,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(); @@ -2216,9 +2217,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; @@ -2239,7 +2241,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 @@ -2267,25 +2269,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"); @@ -5975,7 +5964,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) { @@ -7182,8 +7175,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, @@ -7218,11 +7214,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); } @@ -7233,7 +7224,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"); @@ -7313,23 +7307,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) { @@ -7682,8 +7659,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; @@ -7933,7 +7911,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; @@ -7978,10 +7957,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() && - isDefaultInstance && (userId == 0 || 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 df47a684901ad9a759f0ef9f30e1f6e14ebfabdf..3072db1fb8a1f4d260867d3227f3664e9ffde740 100644 --- a/services/common/BUILD.gn +++ b/services/common/BUILD.gn @@ -215,3 +215,32 @@ ohos_shared_library("record_cost_time_util") { 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 eb22fda5f3d69897e2021d4c83be8020b54a2ebe..897a4c6f051f603eeab37b34bc337bdc5c2a021b 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 0000000000000000000000000000000000000000..5b9c7b67c76b7bce777c15f29ad078a37f9a6752 --- /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 0000000000000000000000000000000000000000..9f9bf6312e58dd74700353ba51f557bab01efd70 --- /dev/null +++ b/services/common/src/user_controller/user_manager.cpp @@ -0,0 +1,80 @@ +/* + * 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 + +#include "hilog_tag_wrapper.h" + +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/abilitymanagerservicefourth_fuzzer/abilitymanagerservicefourth_fuzzer.cpp b/test/fuzztest/abilitymanagerservicefourth_fuzzer/abilitymanagerservicefourth_fuzzer.cpp index 61dd7800ee8c7ea07ab9739164c8efa54035f931..caeddfac2c4d0f93ab84e24d1e5df0b5906ee7c0 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 a47343fac8f8f74c5bc4787cc94cadabe04bb3d7..4b1890151dfc6c36a77b09db96ff59e377b6cfc4 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 4c9cc15bbb7e0ceb54339adc403c6bba85707c94..a4b308cac0c01c0372d5d8a8b753efcd00e2931c 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 20db92c230f04c8595d6c048fe06f83fb0929f61..f02299dc907f2e83dfe7d2e9f429e8c00f542afe 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 @@ -306,14 +306,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 29dba8d1927d2ae5b090f63728d87802346d4bb2..120fc68d9ae6ace15605025a41602b265dfeb90e 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 24e645bb0d9c0a9bb84b158d81fc105e2a7912c6..87dd0a9432a640390e857d7184b14e6de23d8c65 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 0a27e428fd79c3859a257d3d85106a9b3bdc4822..75dcc435fd4f35e07094e261725b6ff21eefc124 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 59b307afb2aec80bcbb5abb381e52fa002fb3188..36902477e1e9f5cb8f5699adb10c35fd18154890 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; @@ -305,7 +305,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_test/AMS/mock_ability_manager_service.h b/test/mock/frameworks_kits_test/AMS/mock_ability_manager_service.h index eeddb8c204d6a4b8fa0fc56df5458f664c0f77c4..1a0ca792d62e4de817dad9de9d71d5bd5d17262d 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 6a8d1dcce4c882e02efa610ecfa8782874c694d5..c43ce0c258d9b25f3a31cb579355f688e821852f 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 0a473259fc323f6aae3cb68e011c5121e9c86624..b6c2c13ed37e01b109a6255d69f659b0e6d16da3 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 8578c55375f426f2a2070e6a9af556315c1abf6e..4905359a8a29716a6c2a7b4d993d1421b7a2e953 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 63cddf3d63876e4e4eb64f8f1818ac4df20d9829..cea9bf6adcc01823374dbe333e8084585d308c3c 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 ba47fb140a38577d84e1b0fe3be72edb7a9d17fd..d8b45521a26fe5dad6d67924965553a412785fba 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 3b1167e5522e77ba4a0239665185d8d434d390d0..fad5325e4eab477d4512c27a43360468f17294bf 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 88f72c52ba1b4a463fbf9328fe9595111ca2e1e2..b63d46ef706d5c916c603a14d8c6ab1094180b6a 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 c2f04fb65e7aa5da0350237d26a01855710b2c6a..aef41a7da219c9a1bca43b3a56806be46db88dc2 100644 --- a/test/moduletest/common/ams/ability_running_record_test/BUILD.gn +++ b/test/moduletest/common/ams/ability_running_record_test/BUILD.gn @@ -32,6 +32,7 @@ ohos_moduletest("AmsAbilityRunningRecordModuleTest") { "${ability_runtime_services_path}/common:app_util", "${ability_runtime_services_path}/common:perm_verification", "${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("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 1a31bba8cac2c4bd375b3183af72411797cc2a09..6cd39434ab6d167c2794f37924af48867f0e7855 100644 --- a/test/moduletest/common/ams/app_mgr_service_test/BUILD.gn +++ b/test/moduletest/common/ams/app_mgr_service_test/BUILD.gn @@ -42,6 +42,7 @@ ohos_moduletest("AmsAppMgrServiceModuleTest") { "${ability_runtime_services_path}/common:app_util", "${ability_runtime_services_path}/common:perm_verification", "${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", ] @@ -65,6 +66,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 19bbcedcf5138641fd9a216282d3f435dcac9568..2f50cd637d45c3ab8e2add76efbeb9aa71ded74d 100644 --- a/test/moduletest/common/ams/app_recent_list_test/BUILD.gn +++ b/test/moduletest/common/ams/app_recent_list_test/BUILD.gn @@ -34,6 +34,7 @@ ohos_moduletest("AmsAppRecentListModuleTest") { "${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", "${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 e7ffc1cc1585e24b9e970ae54cf6bb34de7ba2b6..aaaaca2b28cd3877f5b4e8222d5aaac1fc9c039e 100644 --- a/test/moduletest/common/ams/app_service_flow_test/BUILD.gn +++ b/test/moduletest/common/ams/app_service_flow_test/BUILD.gn @@ -37,6 +37,7 @@ ohos_moduletest("AmsAppServiceFlowModuleTest") { "${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", "${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 ec213b07e27455c9e6c8b5dfda017ddab0308aab..251e76c8d083637af7cf17a915cc9509ee67574b 100644 --- a/test/moduletest/common/ams/ipc_ams_mgr_test/BUILD.gn +++ b/test/moduletest/common/ams/ipc_ams_mgr_test/BUILD.gn @@ -43,6 +43,7 @@ ohos_moduletest("AmsIpcAmsmgrModuleTest") { "${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", "${ability_runtime_test_path}/moduletest/common/ams:appmgr_mst_source", "${ability_runtime_test_path}/unittest:appmgr_test_source", ] @@ -66,7 +67,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 6288715037226ff485031404b05ed84494653afd..c64bec85ceb8342a49dac835b90fabc5cf737e21 100644 --- a/test/moduletest/common/ams/ipc_app_mgr_test/BUILD.gn +++ b/test/moduletest/common/ams/ipc_app_mgr_test/BUILD.gn @@ -34,6 +34,7 @@ ohos_moduletest("AmsIpcAppmgrModuleTest") { "${ability_runtime_services_path}/common:app_util", "${ability_runtime_services_path}/common:perm_verification", "${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", ] @@ -59,6 +60,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 f28a13cbde7d138b95cedfe1b31419257afc21a4..8b0b2f78d91ce9fb18e71d8ec37db3d75d8752b4 100644 --- a/test/moduletest/common/ams/ipc_app_scheduler_test/BUILD.gn +++ b/test/moduletest/common/ams/ipc_app_scheduler_test/BUILD.gn @@ -34,6 +34,7 @@ ohos_moduletest("AmsIpcAppSchedulerModuleTest") { "${ability_runtime_services_path}/common:app_util", "${ability_runtime_services_path}/common:perm_verification", "${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", ] @@ -59,6 +60,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 7387986da1df6bcb70e5f7085bd2209f0f18b05e..fb5d8c9c268de339a9734b5474ecda697757f1e3 100644 --- a/test/moduletest/common/ams/service_start_process_test/BUILD.gn +++ b/test/moduletest/common/ams/service_start_process_test/BUILD.gn @@ -34,6 +34,7 @@ ohos_moduletest("AmsServiceStartModuleTest") { "${ability_runtime_services_path}/common:app_util", "${ability_runtime_services_path}/common:perm_verification", "${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", ] @@ -53,6 +54,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 cb18960c7ed88d49d035686878fa70cd7ff3a0bb..0bb51831b34a708cf9045940a57c80da07cea33f 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 04408b97aa3a2c2832dfbf84e817b03d673d0925..8971e095122a340ac7e8ea5ac4e551cd8ed80481 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 82cb2a1de86dcbbe81b7f9aad2658b087be196de..dbd0f9735083e2f7464f0b113176dfb7b0018c55 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 4b554b108b44b48033cc807a618b72a92363a7dd..d924b4eb8188fc438b5edd5606caa44ad8703595 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/unittest/BUILD.gn b/test/unittest/BUILD.gn index c2ce241226c11d4e830ab1fd67708e1157020eef..7914eddc065a88e1295a2f2f45aa0823bdfe19c9 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -448,6 +448,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_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 4b3a201ff546cc0ed90eb7148649b39a63d39516..64765a448e8ebe4158a8df54af73e239706bce08 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 59f75f80d70744b7c51fe66367a8d42d4c875804..8b846d62b0f8da7cb4177f4f14637374b9e5928c 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 88be7d651abc2892b1577afe93b36782105b17dc..fff1ad2f8c3de8df318f704c6d1f36fd54748af6 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 @@ -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_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 713087051ffff0fcaaccc90c9a7b0db5930d9768..98cd89457986aa87c6d2e4631b6d126020fefa73 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 43afa4a80990cf1f14b11bdbc29c23880e53c44d..44a922022e2b2eb2d2a11104f8987dde2395277d 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 d0b8cf2318ed3e9fb3bed0e051ed3bf29fcf8eb9..dbb7586b1ec862abeb8fd30a640fff5c81e9dd5a 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 22d05973eeaef87d268fe11cb7b59d66c614a331..86f18d3578859b8dbe9257b7e9ff2453b77760df 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 22d05973eeaef87d268fe11cb7b59d66c614a331..86f18d3578859b8dbe9257b7e9ff2453b77760df 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 55a4c04e092d9fd3b159456cddb9bd110311110a..a253ce699d0b67adb0bffaf0719ff2d8efc0a6ac 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 @@ -1554,8 +1554,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 98fd67005320c76ab466d4a42cd66d2ba29725a3..8455cdf599f861eeb803c12eaa55bfadd4b448eb 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 @@ -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_third_test/ability_manager_proxy_third_test.cpp b/test/unittest/ability_manager_proxy_third_test/ability_manager_proxy_third_test.cpp index 1a48b715b980fb73a1db49f66451261b340bb302..dbb3019efdf0c61781356e156e020a217825e230 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 1513472afd550f115d6c9e0878909595c40fc407..15a6131c4da79a2a4124d894dcc4ccb83867f329 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 088179067f95ca8fb259e37e37d9ec5f78fad381..d370b19b190dfd0f36bc1a00a08cde46cd586079 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 3984f0a987a4fd3de186279ae941bc021e2db083..1366bea4ad5dbf80c76d8a87803ff6f494da58c3 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"); } @@ -177,9 +173,6 @@ HWTEST_F(AbilityManagerServiceEighthTest, LogoutUser_001, TestSize.Level1) 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); 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_second_test/ability_manager_service_second_test.cpp b/test/unittest/ability_manager_service_second_test/ability_manager_service_second_test.cpp index a4b04ea34be6af71ed1dee4abc30e174d8036737..ae3a19c7f48171ff75b5eb39317c8b096e77dddc 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"); } @@ -1668,20 +1662,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 @@ -1880,6 +1860,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 69f9c12c0e9550e75bd317616e23ee9f6ca494cd..a1846f62a1815d392453948ca31f8e93cc07ee5a 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 @@ -1574,7 +1574,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 f2ebe8f34795d35febc393037a627809caf5e843..2ad066a82c937781ce17e0ae095140730c1ff59c 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 @@ -590,7 +590,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/ability_manager_service_third_test.cpp b/test/unittest/ability_manager_service_third_test/ability_manager_service_third_test.cpp index d429c069a805c406a1c207c9e4b42852fb0e6e01..13b5935fc1867b3df99204e00689d23188cc25d3 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 @@ -725,10 +725,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_twelfth_test/ability_manager_service_twelfth_test.cpp b/test/unittest/ability_manager_service_twelfth_test/ability_manager_service_twelfth_test.cpp index 5ab40511bcc5f024e0a17176f70cb1aa58395a0b..cb007b80fe82fda961b4faef290464cbe965cb21 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 @@ -526,7 +526,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"); } @@ -603,8 +603,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); @@ -625,7 +623,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 8f993136f1062aab2efc16931a164b02efa30bc1..63cfa1e11dc0be1ac606166358271fd4e8a299a2 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 60088fc8f2070291f45742d9e30364c5c544639f..ae80234b98e1c2d4ccf4af8d4d5d9b347df6ebd2 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/ams_ability_running_record_test/BUILD.gn b/test/unittest/ams_ability_running_record_test/BUILD.gn index 5403becfe77332bd63a4d6105eacac1b3b3ec763..bd9e687206b665e65b2df44cdb302209de1d1371 100644 --- a/test/unittest/ams_ability_running_record_test/BUILD.gn +++ b/test/unittest/ams_ability_running_record_test/BUILD.gn @@ -67,6 +67,7 @@ ohos_unittest("AmsAbilityRunningRecordTest") { "${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", "${ability_runtime_test_path}/unittest:appmgr_test_source", ] @@ -105,7 +106,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 6e21ffaa9de439eb1642d9d677d4a8ca5a62aca1..47ab32cc339a5d326c4a892ea4adca9b0233be74 100644 --- a/test/unittest/ams_service_load_ability_process_test/BUILD.gn +++ b/test/unittest/ams_service_load_ability_process_test/BUILD.gn @@ -76,6 +76,7 @@ ohos_unittest("AmsServiceLoadAbilityProcessTest") { "${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", "${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 08b5487daa1f9ffbdee2d972a8b3aa32fcdb9f3a..28fbc6e72a85ecb3cd29de81d4587a5679843282 100644 --- a/test/unittest/ams_service_startup_test/BUILD.gn +++ b/test/unittest/ams_service_startup_test/BUILD.gn @@ -68,6 +68,7 @@ ohos_unittest("AmsServiceStartupTest") { "${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", "${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_exit_reason_helper_fourth_test/mock/include/mock_iapp_mgr.h b/test/unittest/app_exit_reason_helper_fourth_test/mock/include/mock_iapp_mgr.h index 7f99daa31769d89852c1c80c01a6264308942a49..4b36f9c5b6fc6f82239d35a955e57a8f4ba528db 100644 --- a/test/unittest/app_exit_reason_helper_fourth_test/mock/include/mock_iapp_mgr.h +++ b/test/unittest/app_exit_reason_helper_fourth_test/mock/include/mock_iapp_mgr.h @@ -93,7 +93,7 @@ public: } virtual int32_t GetAllRunningInstanceKeysByBundleName( - const std::string& bundleName, std::vector& instanceKeys, int32_t userId = -1) + const std::string& bundleName, std::vector& instanceKeys) { return 0; } 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 dcc5295348fe9d358b0fb4d80ccc62d38e5e7249..1a2a0c8abd2d9670081b7a9cbd07fe6b00969b06 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 @@ -907,7 +907,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 f3de08cff105b04d302496de03db99b8a4d744ae..748a03b1978bc02d38b8f4f61ec79fde6ebff3cf 100644 --- a/test/unittest/app_mgr_service_event_handler_test/BUILD.gn +++ b/test/unittest/app_mgr_service_event_handler_test/BUILD.gn @@ -72,6 +72,7 @@ ohos_unittest("AMSEventHandlerTest") { "${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", "${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_inner_eighth_test/BUILD.gn b/test/unittest/app_mgr_service_inner_eighth_test/BUILD.gn index 041b4ea9eb9b32e2bf1c9833b9b7a64a89d8e916..3b041dbc5604a83f502a4c370dadcb0bd77ea90a 100644 --- a/test/unittest/app_mgr_service_inner_eighth_test/BUILD.gn +++ b/test/unittest/app_mgr_service_inner_eighth_test/BUILD.gn @@ -101,6 +101,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 = [ @@ -149,6 +150,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 a76ce33ce28c21a19d21319feeb2f433c99a6332..330b858cefd5cc8291a837defb66859d41f13369 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 @@ -586,38 +586,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_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 8fd19e76c54338cc20d652e18a3155f0329c3949..f7c04c541f87f42fee38cb2fe90ee9823825eac2 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 @@ -471,7 +471,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"); } @@ -1226,14 +1227,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 773704f9c646761ef8b269e38e645dca12f364db..0f41b7614954798e49b36f9ca0468ea187c585c5 100644 --- a/test/unittest/app_mgr_service_inner_seventh_test/BUILD.gn +++ b/test/unittest/app_mgr_service_inner_seventh_test/BUILD.gn @@ -100,6 +100,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 = [ @@ -148,6 +149,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 65aa161005ff1c310678c365d9806260c3a0c296..69558bcd75858ff9567cd0d8ce1c374056a8c9e2 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 @@ -539,43 +539,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(); @@ -588,19 +569,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(); @@ -611,19 +592,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(); @@ -637,19 +618,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(); @@ -667,19 +648,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(); @@ -696,10 +677,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_test/app_mgr_service_inner_test.cpp b/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp index f505856eedb5c30e17d34bf324c47f2a8935d66f..bae2a8c016310efd8e6629092aca121e05e916c0 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 @@ -5535,7 +5535,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 7cdbab6100cb6b8934dde76ddf2957e339c410c8..262fcadcdbe0bef1ff8339551e3a1e9e25896b14 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 @@ -771,7 +771,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 2e7647f5a1d507ebcb58199afb6bf90716309257..c6240414baf7f02f1d5174fa30fa1ed926c7b431 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 c567462d1f302bb24efa074c8875636d1328f7a1..5b13b08c350049f9d4d265346066f920b98fb7a4 100644 --- a/test/unittest/cache_process_manager_second_test/BUILD.gn +++ b/test/unittest/cache_process_manager_second_test/BUILD.gn @@ -117,6 +117,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 b7968fbfcfccb91a3aea334fe2b254d9a03f23bf..2c4ba95013dddb942cd022e08b8a307da82cfe4a 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 c31f0886910e64bf72ca2a28cee3498ae60a101f..799abd9f1540766b7269b3005525caea6c7192ef 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 @@ -47,12 +47,6 @@ public: bool IsSceneBoardReady(int32_t userId); - /** - * get the user id. - * - */ - int32_t GetUserId() const; - /** * Starts a new ability with specific start options. * @@ -70,6 +64,8 @@ public: int32_t userId = -1, int requestCode = -1); + 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 34a1b31e83e609fa6b725b2cdd9c28c36a87008b..710805d741c2692d45b48c2a5bf7802f9badd165 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 @@ -43,15 +43,16 @@ bool AbilityManagerService::IsSceneBoardReady(int32_t userId) return false; } -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) { return startAbilityResult; } + +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 6f90b43c9e41b98ddd66bcf4999ef8d6b348ae0c..4fb2e98f53de2d914b7d22eb6a3b98091a26344b 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 2e7647f5a1d507ebcb58199afb6bf90716309257..c6240414baf7f02f1d5174fa30fa1ed926c7b431 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 e861fc08628aeb9326038be952a335112b6fda18..a7ff1a0f81c1be7e5e18d92d019edf1ac9e4e9a1 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 3c4627832e2d208570cf72fbd15d7157eb0b9d13..cabd383c4361163489582c35a24932909d16f6a2 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 @@ -3030,7 +3030,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/user_controller_test/user_controller_test.cpp b/test/unittest/user_controller_test/user_controller_test.cpp index 83088ea5f10fdfdfc3c842f210dd0f100dd4a3ef..db3b0e233dcf94a526a039f9653ad875bd58e4ab 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); } @@ -196,7 +196,7 @@ HWTEST_F(UserControllerTest, LogoutUserTest_0100, TestSize.Level1) if (!Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { EXPECT_EQ(result, INVALID_USERID_VALUE); } - EXPECT_TRUE(userController.GetCurrentUserId() == 0); + EXPECT_TRUE(userController.GetCurrentUserId(0) == 0); } /** @@ -212,7 +212,7 @@ HWTEST_F(UserControllerTest, LogoutUserTest_0200, TestSize.Level1) if (!Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { EXPECT_EQ(result, INVALID_USERID_VALUE); } - EXPECT_TRUE(userController.GetCurrentUserId() == 0); + EXPECT_TRUE(userController.GetCurrentUserId(0) == 0); } /** @@ -240,7 +240,7 @@ HWTEST_F(UserControllerTest, HandleContinueUserSwitchTest_0100, TestSize.Level2) UserController userController; auto userItem = std::make_shared(1000); userController.HandleContinueUserSwitch(1000, 1000, userItem); - auto result = userController.GetCurrentUserId(); + auto result = userController.GetCurrentUserId(0); EXPECT_TRUE(result == 0); } @@ -256,7 +256,7 @@ HWTEST_F(UserControllerTest, SendUserSwitchDoneTest_0100, TestSize.Level2) userController.SendUserSwitchDone(1000); userController.Init(); userController.SendUserSwitchDone(1001); - auto result = userController.GetCurrentUserId(); + auto result = userController.GetCurrentUserId(0); EXPECT_TRUE(result == 0); } @@ -273,7 +273,7 @@ HWTEST_F(UserControllerTest, SendContinueUserSwitchTest_0200, TestSize.Level2) userController.SendContinueUserSwitch(1000, 1000, userItem); userController.Init(); userController.SendContinueUserSwitch(1000, 1000, userItem); - auto result = userController.GetCurrentUserId(); + auto result = userController.GetCurrentUserId(0); EXPECT_TRUE(result == 0); } @@ -290,7 +290,7 @@ HWTEST_F(UserControllerTest, SendUserSwitchTimeoutTest_0100, TestSize.Level2) userController.SendUserSwitchTimeout(1000, 1000, userItem); userController.Init(); userController.SendUserSwitchTimeout(1000, 1000, userItem); - auto result = userController.GetCurrentUserId(); + auto result = userController.GetCurrentUserId(0); EXPECT_TRUE(result == 0); } @@ -307,7 +307,7 @@ HWTEST_F(UserControllerTest, SendReportUserSwitchTest_0100, TestSize.Level2) userController.SendReportUserSwitch(1000, 1000, userItem); userController.Init(); userController.SendReportUserSwitch(1000, 1000, userItem); - auto result = userController.GetCurrentUserId(); + auto result = userController.GetCurrentUserId(0); EXPECT_TRUE(result == 0); } @@ -323,7 +323,7 @@ HWTEST_F(UserControllerTest, SendSystemUserCurrentTest_0100, TestSize.Level2) userController.SendSystemUserCurrent(1000, 1000); userController.Init(); userController.SendSystemUserCurrent(1000, 1000); - auto result = userController.GetCurrentUserId(); + auto result = userController.GetCurrentUserId(0); EXPECT_TRUE(result == 0); } @@ -339,8 +339,87 @@ HWTEST_F(UserControllerTest, SendSystemUserStartTest_0100, TestSize.Level2) userController.SendSystemUserStart(1000); userController.Init(); userController.SendSystemUserStart(1000); - auto result = userController.GetCurrentUserId(); + auto result = userController.GetCurrentUserId(0); 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); +} + +/** + * @tc.name: IsCurrentUserTest_0300 + * @tc.desc: IsCurrentUser Test + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(UserControllerTest, IsCurrentUser_0300, TestSize.Level1) +{ + UserController userController; + int32_t userId = 202; + int32_t displayIdParam = 11; + auto result = userController.IsCurrentUser(userId); + EXPECT_TRUE(result); +} + +/** + * @tc.name: MoveUserToForegroundTest_0100 + * @tc.desc: MoveUserToForeground Test + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(UserControllerTest, MoveUserToForeground_0100, TestSize.Level1) +{ + UserController userController; + int32_t oldUserId = 0; + int32_t newUserId = 100; + int32_t displayId = 0; + auto result = userController.MoveUserToForeground(oldUserId, newUserId, displayId, nullptr, false); + EXPECT_EQ(result, 0); +} } // 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 687bf3812993e672811e520e33834c6387d015e5..37a1a65c02b6c6baef5847958d3c7a4494c85cc2 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 0000000000000000000000000000000000000000..1c0b34e85f06394db2f7859747d2ceef52a2297a --- /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 0000000000000000000000000000000000000000..c94bba1aa9f47e2e06f014f9837c835e3e47a8a6 --- /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 c3f7267ac551f068e9be364bbcefad5a76cce22f..19b5c395f587c22d5e80ba31f17f1a7ad41d5d9e 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; }