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 cddd807658f47480776a5a2afef363ab0de57593..43adbeae2c2ed2a42f7faf1bd58f208d5e0665ca 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_client.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_client.h @@ -1010,11 +1010,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 51a85cb8b1661f3a933b143ce1edab23c5dcb226..2608a1b92ea9537d72259ec3d2e388c6fbb0f4a3 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_interface.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_interface.h @@ -1095,10 +1095,11 @@ public: /** * @brief start user. * @param accountId accountId. + * @param displayId logical screen id. * @param isAppRecovery is appRecovery or not. * @return Returns ERR_OK on success, others on failure. */ - virtual int StartUser(int userId, sptr callback, bool isAppRecovery = false) = 0; + virtual int StartUser(int userId, uint64_t displayId, sptr callback, bool isAppRecovery = false) = 0; /** * @brief stop user. diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_client.h b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_client.h index 79cf2e45f76136740616eecd4144a30728be353a..f64e8875cd33e396b4c1e61b9e5a081d5033fe56 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_client.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_client.h @@ -284,11 +284,10 @@ public: * * @param bundlename, bundle name in Application record. * @param instanceKeys, output instance keys of the multi-instance app. - * @param userId, user id. * @return ERR_OK ,return back success,others fail. */ virtual AppMgrResultCode GetAllRunningInstanceKeysByBundleName(const std::string &bundleName, - std::vector &instanceKeys, int32_t userId = -1); + std::vector &instanceKeys); /** * GetAllRenderProcesses, call GetAllRenderProcesses() through proxy project. diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h index 89d21a37c36778b870504ab65b580c42318b48d7..c0bd1abed1e02f30b34ca7d838192347dc30dad0 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h @@ -189,11 +189,10 @@ public: * * @param bundlename, bundle name in Application record. * @param instanceKeys, output instance keys of the multi-instance app. - * @param userId, user id. * @return ERR_OK ,return back success,others fail. */ virtual int32_t GetAllRunningInstanceKeysByBundleName(const std::string &bundleName, - std::vector &instanceKeys, int32_t userId = -1) = 0; + std::vector &instanceKeys) = 0; /** * GetRunningProcessesByBundleType, call GetRunningProcessesByBundleType() through proxy project. diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_proxy.h b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_proxy.h index ad22fd3f5aadc9e7f44987503acafdb386019d1a..448ec1c112291f4877002f2960d3931609d14030 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_proxy.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_proxy.h @@ -157,11 +157,10 @@ public: * * @param bundlename, bundle name in Application record. * @param instanceKeys, output instance keys of the multi-instance app. - * @param userId, user id. * @return ERR_OK ,return back success,others fail. */ virtual int32_t GetAllRunningInstanceKeysByBundleName(const std::string &bundleName, - std::vector &instanceKeys, int32_t userId = -1) override; + std::vector &instanceKeys) override; /** * GetRunningProcessesByBundleType, call GetRunningProcessesByBundleType() through proxy project. diff --git a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_client.cpp b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_client.cpp index b68623bb98329c34c1b5bfa16a9e10abc9019322..eff387946adf1e2beed6757f28037131f57d76bf 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_client.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_client.cpp @@ -514,11 +514,11 @@ AppMgrResultCode AppMgrClient::GetAllRunningInstanceKeysBySelf(std::vector &instanceKeys, int32_t userId) + std::vector &instanceKeys) { sptr service = iface_cast(mgrHolder_->GetRemoteObject()); if (service != nullptr) { - int32_t result = service->GetAllRunningInstanceKeysByBundleName(bundleName, instanceKeys, userId); + int32_t result = service->GetAllRunningInstanceKeysByBundleName(bundleName, instanceKeys); if (result == ERR_OK) { return AppMgrResultCode::RESULT_OK; } diff --git a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_proxy.cpp b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_proxy.cpp index 7fb1b2880ae0e9aa2f3b90f90d75b3372f97f0e4..d4f9041a0e54c7b439ff68d6e329e30662349cab 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_proxy.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_proxy.cpp @@ -256,7 +256,7 @@ int32_t AppMgrProxy::GetAllRunningInstanceKeysBySelf(std::vector &i } int32_t AppMgrProxy::GetAllRunningInstanceKeysByBundleName(const std::string &bundleName, - std::vector &instanceKeys, int32_t userId) + std::vector &instanceKeys) { MessageParcel data; MessageParcel reply; @@ -265,7 +265,6 @@ int32_t AppMgrProxy::GetAllRunningInstanceKeysByBundleName(const std::string &bu return ERR_FLATTEN_OBJECT; } PARCEL_UTIL_WRITE_RET_INT(data, String, bundleName); - PARCEL_UTIL_WRITE_RET_INT(data, Int32, userId); PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::GET_All_RUNNING_INSTANCE_KEYS_BY_BUNDLENAME, data, reply, option); if (!reply.ReadStringVector(&instanceKeys)) { diff --git a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_stub.cpp b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_stub.cpp index 216814a12a0a367c523b38919c41d29147c249d1..18f8b7ee6588b1717673229dfcceee6ddedd3d04 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_stub.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_stub.cpp @@ -564,9 +564,8 @@ int32_t AppMgrStub::HandleGetAllRunningInstanceKeysBySelf(MessageParcel &data, M int32_t AppMgrStub::HandleGetAllRunningInstanceKeysByBundleName(MessageParcel &data, MessageParcel &reply) { std::string bundleName = data.ReadString(); - int32_t userId = data.ReadInt32(); std::vector instanceKeys; - int32_t result = GetAllRunningInstanceKeysByBundleName(bundleName, instanceKeys, userId); + int32_t result = GetAllRunningInstanceKeysByBundleName(bundleName, instanceKeys); if (!reply.WriteStringVector(instanceKeys)) { TAG_LOGE(AAFwkTag::APPMGR, "failed to write isntanceKeys"); return ERR_INVALID_VALUE; diff --git a/services/abilitymgr/BUILD.gn b/services/abilitymgr/BUILD.gn index b10ee5e68d53931919bfd377e327beedd8e2f3ad..465e42562334d119bff608dd379be288a9063b49 100644 --- a/services/abilitymgr/BUILD.gn +++ b/services/abilitymgr/BUILD.gn @@ -153,6 +153,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 e961c374ed81d9244d8ff45f6ede29f9b1b71ae3..a930b4baface6a25b09058d284024e887991ff44 100644 --- a/services/abilitymgr/include/ability_manager_proxy.h +++ b/services/abilitymgr/include/ability_manager_proxy.h @@ -853,10 +853,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 823be80a204242d01ab3edaddb048ef7cb0d75c4..bad623e864adba64c9e0785621bac550b3a14fbb 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -1223,7 +1223,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; @@ -1596,7 +1597,7 @@ public: * get the user id. * */ - int32_t GetUserId() const; + int32_t GetCallerUserId() const; virtual int32_t RegisterStatusBarDelegate(sptr delegate) override; @@ -2221,7 +2222,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. @@ -2330,7 +2331,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(); @@ -2750,7 +2751,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 43a83c7600606d3c743b3fcf06c5832584a97cfb..b76ce3641e0eacc2116e97567926d764e0b373b8 100644 --- a/services/abilitymgr/src/ability_auto_startup_service.cpp +++ b/services/abilitymgr/src/ability_auto_startup_service.cpp @@ -415,7 +415,12 @@ int32_t AbilityAutoStartupService::GetValidUserId(int32_t userId) validUserId = IPCSkeleton::GetCallingUid() / AppExecFwk::Constants::BASE_USER_RANGE; } if (validUserId == U0_USER_ID || validUserId == U1_USER_ID) { - validUserId = DelayedSingleton::GetInstance()->GetUserId(); + auto abilityMgr = DelayedSingleton::GetInstance(); + if (abilityMgr == nullptr) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "null abilityMgr"); + return false; + } + validUserId = abilityMgr->GetCallerUserId(); } return validUserId; } diff --git a/services/abilitymgr/src/ability_connect_manager.cpp b/services/abilitymgr/src/ability_connect_manager.cpp index 301f76e21dc33857e0c2194d05faebafc12b4787..0e06525f41b39465a43a6a46c5ec88b0a435c69c 100644 --- a/services/abilitymgr/src/ability_connect_manager.cpp +++ b/services/abilitymgr/src/ability_connect_manager.cpp @@ -1886,7 +1886,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; @@ -2478,8 +2478,7 @@ void AbilityConnectManager::CleanActivatingTimeoutAbility(std::shared_ptrIsSceneBoard() || - DelayedSingleton::GetInstance()->GetUserId() == userId_) { + if (!abilityRecord->IsSceneBoard() || UserController::GetInstance().IsCurrentUser(userId_)) { RestartAbility(abilityRecord, userId_); } } @@ -2797,6 +2796,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 9e6d817ab10031b07725a5cc3a00a58e3423a4fc..4cc2c3140ddcf1b82eef8355ef42489d864f24e5 100644 --- a/services/abilitymgr/src/ability_manager_client.cpp +++ b/services/abilitymgr/src/ability_manager_client.cpp @@ -1235,13 +1235,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 fe4781cf93247d5328eaf7463ea019e72dc4536f..83fe6495cf08c7e8bbeaeee202eeb132a12ab0ff 100644 --- a/services/abilitymgr/src/ability_manager_proxy.cpp +++ b/services/abilitymgr/src/ability_manager_proxy.cpp @@ -3149,7 +3149,7 @@ int AbilityManagerProxy::MoveMissionsToBackground(const std::vector& mi return reply.ReadInt32(); } -int AbilityManagerProxy::StartUser(int userId, sptr callback, bool isAppRecovery) +int AbilityManagerProxy::StartUser(int userId, uint64_t displayId, sptr callback, bool isAppRecovery) { Ability_MANAGER_HITRACE_CHAIN_NAME("StartUser", HITRACE_FLAG_INCLUDE_ASYNC); MessageParcel data; @@ -3160,6 +3160,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 faf7a2c839102631c3c5e715dc0e3ab63178bab8..a2894bced3ad0efe317a774ae33fd994563391c6 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -308,6 +308,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"; @@ -406,8 +407,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_); @@ -896,7 +896,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); @@ -934,7 +934,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) { @@ -1212,7 +1212,7 @@ int AbilityManagerService::StartAbilityInner(const Want &want, const sptrShouldBlockAllAppStart(); }; - AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(want, requestCode, GetUserId(), + AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(want, requestCode, GetCallerUserId(), true, nullptr, shouldBlockFunc); result = interceptorExecuter_ == nullptr ? ERR_NULL_INTERCEPTOR_EXECUTER : interceptorExecuter_->DoProcess(interceptorParam); @@ -1383,7 +1383,7 @@ int AbilityManagerService::StartAbilityInner(const Want &want, const sptr(abilityInfo), isStartAsCaller, appIndex); result = afterCheckExecuter_ == nullptr ? ERR_INVALID_VALUE : afterCheckExecuter_->DoProcess(afterCheckParam); @@ -1396,14 +1396,14 @@ int AbilityManagerService::StartAbilityInner(const Want &want, const sptrShouldBlockAllAppStart(); }; - AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(want, requestCode, GetUserId(), + AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(want, requestCode, GetCallerUserId(), true, nullptr, shouldBlockFunc); result = interceptorExecuter_ == nullptr ? ERR_NULL_INTERCEPTOR_EXECUTER : interceptorExecuter_->DoProcess(interceptorParam); @@ -1734,7 +1734,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) { @@ -1972,7 +1972,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); @@ -2166,7 +2166,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); @@ -2179,14 +2179,14 @@ int AbilityManagerService::StartAbilityForOptionInner(const Want &want, const St } #ifdef SUPPORT_SCREEN if (result != ERR_OK && isReplaceWantExist) { - result = DialogSessionManager::GetInstance().HandleErmsResult(abilityRequest, GetUserId(), newWant); + result = DialogSessionManager::GetInstance().HandleErmsResult(abilityRequest, GetCallerUserId(), newWant); eventHelper_.SendStartAbilityErrorEvent(eventInfo, result, "HandleErmsResult failed"); return result; } if (result == ERR_OK && - DialogSessionManager::GetInstance().IsCreateCloneSelectorDialog(abilityInfo.bundleName, GetUserId())) { + DialogSessionManager::GetInstance().IsCreateCloneSelectorDialog(abilityInfo.bundleName, GetCallerUserId())) { TAG_LOGI(AAFwkTag::ABILITYMGR, "create clone selector dialog"); - result = CreateCloneSelectorDialog(abilityRequest, GetUserId()); + result = CreateCloneSelectorDialog(abilityRequest, GetCallerUserId()); eventHelper_.SendStartAbilityErrorEvent(eventInfo, result, "CreateCloneSelectorDialog failed"); return result; } @@ -2529,7 +2529,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); @@ -2577,7 +2577,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) { @@ -2805,8 +2805,8 @@ int AbilityManagerService::StartUIAbilityBySCBDefault(sptr sessionI Want newWant = abilityRequest.want; auto callerTokenId = IPCSkeleton::GetCallingTokenID(); RemoveUnauthorizedLaunchReasonMessage(sessionInfo->want, abilityRequest, callerTokenId); - AbilityInterceptorParam afterCheckParam = AbilityInterceptorParam(newWant, requestCode, GetUserId(), true, - sessionInfo->callerToken, std::make_shared(abilityInfo), false, appIndex); + AbilityInterceptorParam afterCheckParam = AbilityInterceptorParam(newWant, requestCode, GetCallerUserId(), true, + callerTokenId, std::make_shared(abilityInfo), false, appIndex); result = afterCheckExecuter_ == nullptr ? ERR_INVALID_VALUE : afterCheckExecuter_->DoProcess(afterCheckParam); bool isReplaceWantExist = newWant.GetBoolParam("queryWantFromErms", false); @@ -2912,7 +2912,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; } @@ -3558,7 +3558,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); @@ -3647,7 +3647,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); @@ -3908,7 +3908,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); @@ -3979,7 +3979,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); @@ -4106,7 +4106,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; } @@ -4117,9 +4117,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; } @@ -4829,7 +4829,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); @@ -4980,7 +4980,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); @@ -5193,7 +5193,7 @@ int32_t AbilityManagerService::ConnectLocalAbility(const Want &want, const int32 return result; } - AbilityInterceptorParam afterCheckParam = AbilityInterceptorParam(abilityRequest.want, 0, GetUserId(), + AbilityInterceptorParam afterCheckParam = AbilityInterceptorParam(abilityRequest.want, 0, GetCallerUserId(), false, callerToken, std::make_shared(abilityInfo)); result = afterCheckExecuter_ == nullptr ? ERR_INVALID_VALUE : afterCheckExecuter_->DoProcess(afterCheckParam); @@ -6358,7 +6358,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; @@ -6423,7 +6423,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; @@ -7154,18 +7154,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(); @@ -7222,6 +7213,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 @@ -7486,14 +7478,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"); @@ -7537,7 +7529,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), @@ -8091,7 +8083,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; @@ -8473,7 +8465,7 @@ int AbilityManagerService::StartAbilityByCallWithErrMsg(const Want &want, const return ERR_APP_CLONE_INDEX_INVALID; } auto checkRet = AbilityPermissionUtil::GetInstance().CheckMultiInstanceAndAppClone(const_cast(want), - GetUserId(), appIndex, callerToken, false); + GetCallerUserId(), appIndex, callerToken, false); if (checkRet != ERR_OK) { return checkRet; } @@ -8482,9 +8474,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); @@ -8514,7 +8506,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; @@ -8538,7 +8530,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); @@ -8639,9 +8631,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; @@ -8658,10 +8650,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) @@ -8676,11 +8665,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); } @@ -8722,12 +8708,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( @@ -8870,7 +8853,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; } @@ -9188,7 +9171,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)); @@ -9246,10 +9229,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) { @@ -9258,7 +9237,7 @@ void AbilityManagerService::StartSwitchUserDialog() } Want dialogWant = sysDialog->GetSwitchUserDialogWant(); - StartSwitchUserDialogInner(dialogWant, userController_->GetFreezingNewUserId()); + StartSwitchUserDialogInner(dialogWant, UserController::GetInstance().GetFreezingNewUserId()); #endif // SUPPORT_GRAPHICS } @@ -9334,8 +9313,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__, @@ -9348,7 +9327,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); } @@ -9376,9 +9355,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"); @@ -9464,7 +9440,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; @@ -9564,7 +9540,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))) { @@ -9579,7 +9555,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( @@ -9745,15 +9721,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) @@ -10032,7 +10004,7 @@ void AbilityManagerService::GetAbilityRunningInfo(std::vectorGetCurrentUserId() == userId))) { + if (userId < 0 || GetCallerUserId() == userId) { return ERR_OK; } return AAFwk::PermissionVerification::GetInstance()->VerifyAccountPermission(); @@ -11503,7 +11475,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)); @@ -11669,7 +11641,7 @@ int32_t AbilityManagerService::StartSpecifiedAbilityBySCB(const Want &want) return ERR_APP_CLONE_INDEX_INVALID; } auto result = AbilityPermissionUtil::GetInstance().CheckMultiInstanceAndAppClone(const_cast(want), - GetUserId(), appIndex, nullptr, true); + GetCallerUserId(), appIndex, nullptr, true); if (result != ERR_OK) { return result; } @@ -11936,7 +11908,7 @@ int32_t AbilityManagerService::QueryAllAutoStartupApplications(std::vectorQueryAllAutoStartupApplications(infoList, GetUserId()); + return abilityAutoStartupService_->QueryAllAutoStartupApplications(infoList, GetCallerUserId()); } int AbilityManagerService::PrepareTerminateAbilityBySCB(const sptr &sessionInfo, bool &isTerminate) @@ -12191,7 +12163,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; @@ -12463,19 +12435,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); } } @@ -12489,9 +12457,9 @@ void AbilityManagerService::NotifyStartResidentProcess(std::vectorStartResidentProcessWithMainElement( - bundleInfosForCurrentUser, currentUser); - if (!bundleInfosForCurrentUser.empty()) { - residentProcessMgr->StartResidentProcess(bundleInfosForCurrentUser); + bundleInfosForcallerUser, callerUser); + if (!bundleInfosForcallerUser.empty()) { + residentProcessMgr->StartResidentProcess(bundleInfosForcallerUser); } } @@ -12501,7 +12469,7 @@ void AbilityManagerService::NotifyStartKeepAliveProcess(std::vector bundleInfosForCurrentUser; std::vector bundleInfosForU1; for (const auto &item: bundleInfos) { @@ -12702,7 +12670,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; @@ -12740,7 +12708,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); @@ -13145,14 +13113,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, @@ -13188,7 +13156,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); @@ -13200,7 +13168,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; @@ -13785,7 +13753,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); @@ -13841,7 +13809,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); @@ -13853,12 +13821,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 @@ -14403,7 +14371,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, @@ -14790,7 +14758,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 8e759eb4ce924f4cd93b4694f9542117564d66d4..4b7d4e3e0ae7ee6d78488323d6823694ddf98f36 100644 --- a/services/abilitymgr/src/ability_manager_stub.cpp +++ b/services/abilitymgr/src/ability_manager_stub.cpp @@ -2542,6 +2542,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()); @@ -2550,7 +2551,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 0d7afe01f05364b6df4941e49a49a892158225c9..d1a4aef58b44f6f32f324587af1c7c37bb56084d 100644 --- a/services/abilitymgr/src/keep_alive/ability_keep_alive_service.cpp +++ b/services/abilitymgr/src/keep_alive/ability_keep_alive_service.cpp @@ -111,7 +111,7 @@ void AbilityKeepAliveService::GetValidUserId(int32_t &userId) } if (userId < 0) { - userId = abilityMgr->GetUserId(); + userId = abilityMgr->GetCallerUserId(); } } diff --git a/services/abilitymgr/src/keep_alive/keep_alive_process_manager.cpp b/services/abilitymgr/src/keep_alive/keep_alive_process_manager.cpp index 3b9ecc8b48045d4b7c4b4dcb7df1ffa4d1f49679..b33f0ddb2f226c865de352226f43df2ce3ca6025 100644 --- a/services/abilitymgr/src/keep_alive/keep_alive_process_manager.cpp +++ b/services/abilitymgr/src/keep_alive/keep_alive_process_manager.cpp @@ -219,7 +219,7 @@ int32_t KeepAliveProcessManager::SetApplicationKeepAlive(const std::string &bund auto bms = AbilityUtil::GetBundleManagerHelper(); CHECK_POINTER_AND_RETURN(bms, INNER_ERR); - userId = userId < 0 ? DelayedSingleton::GetInstance()->GetUserId() : userId; + userId = userId < 0 ? DelayedSingleton::GetInstance()->GetCallerUserId() : userId; AppExecFwk::BundleInfo bundleInfo; if (!IN_PROCESS_CALL(bms->GetBundleInfo( bundleName, AppExecFwk::BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo, userId))) { diff --git a/services/abilitymgr/src/resident_process/resident_process_manager.cpp b/services/abilitymgr/src/resident_process/resident_process_manager.cpp index a6f77c07a111d3646705f27dc8fe0b9aed57251c..f61df71d246b6c7594b9b65b83ee177efcba7044 100644 --- a/services/abilitymgr/src/resident_process/resident_process_manager.cpp +++ b/services/abilitymgr/src/resident_process/resident_process_manager.cpp @@ -211,7 +211,7 @@ void ResidentProcessManager::UpdateResidentProcessesStatus( } AppExecFwk::BundleInfo bundleInfo; - auto currentUser = DelayedSingleton::GetInstance()->GetUserId(); + auto currentUser = DelayedSingleton::GetInstance()->GetCallerUserId(); std::set users{0, currentUser}; for (const auto &userId: users) { diff --git a/services/abilitymgr/src/user_controller.cpp b/services/abilitymgr/src/user_controller.cpp index c1b8408e95a15321ee61d48523980a640566a780..ab0884a52c12916cb9dd46d27ce7eaa49e2c01e4 100644 --- a/services/abilitymgr/src/user_controller.cpp +++ b/services/abilitymgr/src/user_controller.cpp @@ -20,6 +20,7 @@ #include "mock_session_manager_service.h" #include "os_account_manager_wrapper.h" #include "scene_board_judgement.h" +#include "user_controller/user_manager.h" namespace OHOS { namespace AAFwk { @@ -53,12 +54,10 @@ UserState UserItem::GetState() return curState_; } -UserController::UserController() -{ -} - -UserController::~UserController() +UserController& UserController::GetInstance() { + static UserController instance; + return instance; } void UserController::Init() @@ -71,18 +70,19 @@ void UserController::Init() if (eventHandler_) { return; } - eventHandler_ = std::make_shared(handler, shared_from_this()); + eventHandler_ = std::make_shared(handler); } void UserController::ClearAbilityUserItems(int32_t userId) { + UserManager::GetInstance().ClearUserId(userId); std::lock_guard guard(userLock_); if (userItems_.count(userId)) { userItems_.erase(userId); } } -int UserController::StartUser(int32_t userId, sptr callback, bool isAppRecovery) +int UserController::StartUser(int32_t userId, uint64_t displayId, sptr callback, bool isAppRecovery) { if (userId == U1_USER_ID) { return StartNoHeadUser(userId, callback); @@ -96,7 +96,7 @@ int UserController::StartUser(int32_t userId, sptr callback, bool return INVALID_USERID_VALUE; } - if (IsCurrentUser(userId)) { + if (IsCurrentUser(userId, displayId)) { TAG_LOGW(AAFwkTag::ABILITYMGR, "StartUser current:%{public}d", userId); if (callback != nullptr) { callback->OnStartUserDone(userId, ERR_OK); @@ -119,13 +119,13 @@ int UserController::StartUser(int32_t userId, sptr callback, bool return INVALID_USERID_VALUE; } - if (GetCurrentUserId() != USER_ID_NO_HEAD && !Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { + auto oldUserId = GetCurrentUserId(displayId); + if (oldUserId != USER_ID_NO_HEAD && !Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { // start freezing screen SetFreezingNewUserId(userId); DelayedSingleton::GetInstance()->StartFreezingScreen(); } - auto oldUserId = GetCurrentUserId(); auto userItem = GetOrCreateUserItem(userId); auto state = userItem->GetState(); if (state == STATE_STOPPING || state == STATE_SHUTDOWN) { @@ -136,7 +136,7 @@ int UserController::StartUser(int32_t userId, sptr callback, bool return ERR_DEAD_OBJECT; } - SetCurrentUserId(userId); + SetCurrentUserId(userId, displayId); if (state == STATE_BOOTING) { // send user start msg. SendSystemUserStart(userId); @@ -145,7 +145,7 @@ int UserController::StartUser(int32_t userId, sptr callback, bool SendSystemUserCurrent(oldUserId, userId); SendReportUserSwitch(oldUserId, userId, userItem); SendUserSwitchTimeout(oldUserId, userId, userItem); - return MoveUserToForeground(oldUserId, userId, callback, isAppRecovery); + return MoveUserToForeground(oldUserId, userId, displayId, callback, isAppRecovery); } int32_t UserController::StartNoHeadUser(int32_t userId, sptr callback) const @@ -253,18 +253,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) @@ -278,19 +279,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; @@ -311,22 +314,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 b04e33496832623b6ddcfdb0749854d0566c54bb..8e36582d34ca26e1db11900d451a821401bd300b 100644 --- a/services/appmgr/include/app_mgr_service.h +++ b/services/appmgr/include/app_mgr_service.h @@ -182,11 +182,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 2ffa80980ccc246e94d7949c7863ae71bb54ad7b..1d9bd5864e6986ba244ff1c76d9598c0d8f2acbe 100644 --- a/services/appmgr/include/app_mgr_service_inner.h +++ b/services/appmgr/include/app_mgr_service_inner.h @@ -447,7 +447,7 @@ public: * @return ERR_OK ,return back success,others fail. */ virtual int32_t GetAllRunningInstanceKeysByBundleName(const std::string &bundleName, - std::vector &instanceKeys, int32_t userId = -1); + std::vector &instanceKeys, int32_t userId); /** * GetRunningProcessesByBundleType, Obtains information about application processes by bundle type. @@ -2033,7 +2033,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(); @@ -2071,8 +2070,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 1b907c9f6016724cefdee598cf5bbae9421285d7..e5da0bc34a1dd130763acdbf0551ed45088e2fa0 100644 --- a/services/appmgr/src/app_mgr_service.cpp +++ b/services/appmgr/src/app_mgr_service.cpp @@ -26,6 +26,7 @@ #include "app_death_recipient.h" #include "app_mgr_constants.h" #include "datetime_ex.h" +#include "display_util.h" #include "fd_guard.h" #include "freeze_util.h" #include "global_constant.h" @@ -37,6 +38,7 @@ #include "permission_constants.h" #include "permission_verification.h" #include "system_ability_definition.h" +#include "user_controller/user_manager.h" #include "accesstoken_kit.h" #include "app_mgr_service_const.h" #include "app_mgr_service_dump_error_code.h" @@ -414,8 +416,8 @@ int32_t AppMgrService::GetRunningMultiAppInfoByBundleName(const std::string &bun return ERR_INVALID_OPERATION; } - if (!AAFwk::PermissionVerification::GetInstance()->JudgeCallerIsAllowedToUseSystemAPI()) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "caller is not SA"); + if (!AAFwk::PermissionVerification::GetInstance()->IsSystemAppCall()) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "caller is not system app"); return ERR_INVALID_OPERATION; } @@ -436,11 +438,19 @@ int32_t AppMgrService::GetAllRunningInstanceKeysBySelf(std::vector } int32_t AppMgrService::GetAllRunningInstanceKeysByBundleName(const std::string &bundleName, - std::vector &instanceKeys, int32_t userId) + std::vector &instanceKeys) { if (!IsReady()) { return ERR_INVALID_OPERATION; } + bool isCallingPermission = + AAFwk::PermissionVerification::GetInstance()->CheckSpecificSystemAbilityAccessPermission(FOUNDATION_PROCESS); + if (!isCallingPermission) { + TAG_LOGE(AAFwkTag::APPMGR, "verification failed"); + return ERR_PERMISSION_DENIED; + } + int32_t userId = AbilityRuntime::UserManager::GetInstance().GetCurrentUserId( + AAFwk::DisplayUtil::ObtainDefaultDisplayId()); return appMgrServiceInner_->GetAllRunningInstanceKeysByBundleName(bundleName, instanceKeys, userId); } @@ -450,6 +460,10 @@ int32_t AppMgrService::GetRunningProcessesByBundleType(BundleType bundleType, if (!IsReady()) { return ERR_INVALID_OPERATION; } + if (!AAFwk::PermissionVerification::GetInstance()->IsSystemAppCall()) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "caller is not system app"); + return AAFwk::ERR_NOT_SYSTEM_APP; + } return appMgrServiceInner_->GetRunningProcessesByBundleType(bundleType, info); } diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index 57a75bd32d9afa27f7b3d521a107b1331e88e424..d3a684a17e4f6ba07cf9cc712c0236c562263657 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -45,6 +45,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" @@ -104,6 +105,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" @@ -118,6 +120,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; @@ -282,7 +285,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; @@ -571,8 +573,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"); @@ -2291,16 +2296,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"); } @@ -2316,9 +2320,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, @@ -2416,17 +2417,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(); @@ -2454,9 +2455,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; @@ -2477,7 +2479,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 @@ -2505,25 +2507,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"); @@ -6283,7 +6272,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) { @@ -7494,8 +7487,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, @@ -7530,11 +7526,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); } @@ -7545,7 +7536,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"); @@ -7625,23 +7619,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) { @@ -7994,8 +7971,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; @@ -8245,7 +8223,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; @@ -8290,9 +8269,10 @@ void AppMgrServiceInner::ClearNonResidentKeepAliveAppRunningData(const std::shar } auto userId = GetUserIdByUid(appRecord->GetUid()); + bool isCurentUserId = UserManager::GetInstance().IsCurrentUser(userId); bool isDefaultInstance = appRecord->GetInstanceKey().empty() || appRecord->GetInstanceKey() == APP_INSTANCE_KEY_0; if (!appRecord->GetRestartAppFlag() && (appRecord->IsKeepAliveDkv() || appRecord->IsKeepAliveAppService()) && - isDefaultInstance && (userId == 0 || userId == 1 ||userId == currentUserId_) && + isDefaultInstance && (userId == 0 || userId == 1 || isCurentUserId) && appRecord->GetBundleName() != SCENE_BOARD_BUNDLE_NAME) { if (ExitResidentProcessManager::GetInstance().IsKilledForUpgradeWeb(appRecord->GetBundleName())) { TAG_LOGI(AAFwkTag::APPMGR, "is killed for upgrade web"); diff --git a/services/common/BUILD.gn b/services/common/BUILD.gn index 99a2194892bec0f560f1963597145df59db1a3ff..fa6213774fa1200d14e975c87877c07f0b14f42f 100644 --- a/services/common/BUILD.gn +++ b/services/common/BUILD.gn @@ -222,6 +222,36 @@ ohos_shared_library("record_cost_time_util") { 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" +} + ohos_shared_library("rate_limiter") { sanitize = { integer_overflow = true 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 cc089fbb6c697617a9ed76833c9740e0cb1a6afc..f173f6bd4fae69e7c25c8770306beb57c70be1bf 100644 --- a/test/mock/frameworks_kits_ability_ability_runtime_test/AMS/mock_ability_manager_client.cpp +++ b/test/mock/frameworks_kits_ability_ability_runtime_test/AMS/mock_ability_manager_client.cpp @@ -326,14 +326,15 @@ ErrCode AbilityManagerClient::StopSyncRemoteMissions(const std::string& devId) return abms->StopSyncRemoteMissions(devId); } -ErrCode AbilityManagerClient::StartUser(int accountId, sptr callback, bool isAppRecovery) +ErrCode AbilityManagerClient::StartUser(int accountId, uint64_t displayId, sptr callback, + bool isAppRecovery) { if (g_remoteObject == nullptr) { return ABILITY_SERVICE_NOT_CONNECTED; } sptr abms = iface_cast(g_remoteObject); - return abms->StartUser(accountId, callback); + return abms->StartUser(accountId, displayId, callback); } ErrCode AbilityManagerClient::StopUser(int accountId, sptr callback) diff --git a/test/mock/frameworks_kits_ability_ability_runtime_test/AMS/mock_serviceability_manager_service.h b/test/mock/frameworks_kits_ability_ability_runtime_test/AMS/mock_serviceability_manager_service.h index 4973fd976754230ee81b06faf436c2b715071b6b..e2233fb5fa59b7d1d68cab76a92db4fdd731451c 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 e4f2843c8708404a750c2adb75df52041da85fbf..76da26e1d5c4b7641d75638aaefc056c685fb415 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 be458c7cfb9a9dc329ea3c8b55161bed4e66281b..795e3ada00e975e7a0425bf4edc10a41aa2425a4 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 3aad74681d750f37651977ccf04a536f0b73d39c..4bf00248b2072bc7fdc6f755798189b3c2463d18 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 6f831357fed2abd695d1aa1dd3e667201697dd96..4013a37026305f28d5ea0d5fe2d32c699d9e46a9 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 859875dbefab05aa0f44b806af6c35083c2ea56e..939aa2e06797640abea822ff5cf740a93eaa8200 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 d952e784aa63d013ae9b465e49398fce7a15dc33..2269ba76baa52247c2d195e580bf1db194e670d9 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 fcff77e2efed240514302ee00aec55a603ac7750..1ca2625d8a2e1daf4f6e008bb4d33b83c0e5667b 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 53d5c33d78b64bd93c4b5957bc140031c624542d..c16fc34e047013dc4f84928b3a422a12ecf59bae 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 02ed081a2e5b0419c02bf3e55f5f7e9b6ff6a3ae..f9d4e18369e618a142ccc2234cd5e12cd6dd3c15 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -479,6 +479,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 e5481123507c3ac483a269ea8167a72d00961df7..0f5256d4065461ae1b84a687fa8dc19aaf561014 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 aace3c78645c526523fcc9cb6fd02c114b5baedb..63b21f13aa11b3208d922e06e874819077bf12be 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 3863558db5d399908e72c1a4ea97ce68cffd2531..e8148e042cda03eafedd65f4bcf1fd2e04d9ead6 100644 --- a/test/unittest/ability_manager_client_branch_test/ability_manager_stub_mock_test.h +++ b/test/unittest/ability_manager_client_branch_test/ability_manager_stub_mock_test.h @@ -239,7 +239,7 @@ public: return; } - int StartUser(int userId, sptr callback, bool isAppRecovery) override + int StartUser(int userId, uint64_t displayId, sptr callback, bool isAppRecovery) override { return 0; } diff --git a/test/unittest/ability_manager_client_branch_third_test/mock/include/ability_manager_stub_mock_test.h b/test/unittest/ability_manager_client_branch_third_test/mock/include/ability_manager_stub_mock_test.h index 916b58700fe34c1b2b3de186b0a3657c16c1dcd0..9181ba8a765a615d1313bfc555d8d95578bbdbb4 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 9643e1fb1f848e27e233b0f289d96c94e03542a3..0ccdaeb169650f0fcdd958a2a046a8afec228473 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 001d1dc358514546e250ce449e7a3ec88d425afc..aa3e35e3b93abaee6bac161064b9a262b65340de 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 de1d65e657ab6ac334bf029fe2a8d68bbeff1b68..376e14e142abbe6d89bfc5d7500e3f8c9e436006 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 de1d65e657ab6ac334bf029fe2a8d68bbeff1b68..376e14e142abbe6d89bfc5d7500e3f8c9e436006 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 8760b8b53cbb9ac585ba419542c7c2103a1a65d5..9920ace952e7b615fffae97e60de7a4cfeac4ecf 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 @@ -1660,8 +1660,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 0fa986f62274ecf86265189b53b2acade44397d0..7b6907409cd157085a18c120fa8e760918689414 100644 --- a/test/unittest/ability_manager_proxy_test/ability_manager_stub_mock.h +++ b/test/unittest/ability_manager_proxy_test/ability_manager_stub_mock.h @@ -244,7 +244,7 @@ public: return; } - int StartUser(int userId, sptr callback, bool isAppRecovery) override + int StartUser(int userId, uint64_t displayId, sptr callback, bool isAppRecovery) override { return 0; } diff --git a/test/unittest/ability_manager_proxy_third_test/ability_manager_proxy_third_test.cpp b/test/unittest/ability_manager_proxy_third_test/ability_manager_proxy_third_test.cpp index 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 b12fdc033e98d3a0e3dc9f4645d0c80cdd9b1255..3d230f6983b74db4a6e92a4a73724b4300af4b17 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 f11947e1be8875da533996764a5cbcadc516106b..502a93e0ddf6e8fdcb1ceff388f9a69eafa20df8 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 4cd845f1704f2f4d75ef571f3524eea379fe4720..d9592a63314216d007ec59937b33497f22088b3a 100644 --- a/test/unittest/ability_manager_service_second_test/ability_manager_service_second_test.cpp +++ b/test/unittest/ability_manager_service_second_test/ability_manager_service_second_test.cpp @@ -125,9 +125,6 @@ HWTEST_F(AbilityManagerServiceSecondTest, StartSwitchUserDialog_001, TestSize.Le auto abilityMs_ = std::make_shared(); EXPECT_NE(abilityMs_, nullptr); abilityMs_->StartSwitchUserDialog(); - - abilityMs_->userController_ = nullptr; - abilityMs_->StartSwitchUserDialog(); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSecondTest StartSwitchUserDialog_001 end"); } @@ -159,9 +156,6 @@ HWTEST_F(AbilityManagerServiceSecondTest, StopSwitchUserDialog_001, TestSize.Lev auto abilityMs_ = std::make_shared(); EXPECT_NE(abilityMs_, nullptr); abilityMs_->StopSwitchUserDialog(); - - abilityMs_->userController_ = nullptr; - abilityMs_->StopSwitchUserDialog(); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSecondTest StopSwitchUserDialog_001 end"); } @@ -1672,20 +1666,6 @@ HWTEST_F(AbilityManagerServiceSecondTest, GetEventHandler_001, TestSize.Level1) TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSecondTest GetEventHandler_001 end"); } -/* - * Feature: AbilityManagerService - * Function: GetUserId - * SubFunction: NA - * FunctionPoints: AbilityManagerService GetUserId - */ -HWTEST_F(AbilityManagerServiceSecondTest, GetUserId_001, TestSize.Level1) -{ - TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSecondTest GetUserId_001 start"); - auto abilityMs_ = std::make_shared(); - EXPECT_NE(abilityMs_->GetUserId(), 100); - TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSecondTest GetUserId_001 end"); -} - /* * Feature: AbilityManagerService * Function: GenerateAbilityRequest @@ -1884,6 +1864,24 @@ HWTEST_F(AbilityManagerServiceSecondTest, UpdateKeepAliveEnableState_001, TestSi TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSecondTest UpdateKeepAliveEnableState_001 end"); } +/* + * Feature: AbilityManagerService + * Name: GetCallerUserId_001 + * Function: GetCallerUserId + * SubFunction: NA + * FunctionPoints: AbilityManagerService GetCallerUserId + */ +HWTEST_F(AbilityManagerServiceSecondTest, GetCallerUserId_001, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSecondTest GetCallerUserId_001 start"); + auto abilityMs_ = std::make_shared(); + EXPECT_NE(abilityMs_, nullptr); + auto userId = abilityMs_->GetCallerUserId(); + int32_t invalidUseId = 1000; + EXPECT_NE(userId, invalidUseId); + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSecondTest GetCallerUserId_001 end"); +} + #ifdef SUPPORT_AUTO_FILL /** * @tc.name: CheckCallAutoFillExtensionPermission_001 diff --git a/test/unittest/ability_manager_service_sixth_test/ability_manager_service_sixth_test.cpp b/test/unittest/ability_manager_service_sixth_test/ability_manager_service_sixth_test.cpp index d506e1db9148538d64ff2d5a2b0746d552bfe043..55fb75bc9275c7bafaedc0f62b127ff631fc79fc 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 @@ -1629,7 +1629,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 9211523299c3935d43d9e0f920f630db021bfa93..cd19cba8110c65d8efe93def40874c7cdb329317 100644 --- a/test/unittest/ability_manager_service_tenth_test/ability_manager_service_tenth_test.cpp +++ b/test/unittest/ability_manager_service_tenth_test/ability_manager_service_tenth_test.cpp @@ -592,7 +592,7 @@ HWTEST_F(AbilityManagerServiceTenhtTest, StartHighestPriorityAbility_001, TestSi int32_t userId = 1; bool isBoot = false; bool isAppRecovery = true; - auto ret = abilityMs_->StartHighestPriorityAbility(userId, isBoot, isAppRecovery); + auto ret = abilityMs_->StartHighestPriorityAbility(userId, 0, isBoot, isAppRecovery); EXPECT_EQ(ret, RESOLVE_ABILITY_ERR); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceTenhtTest StartHighestPriorityAbility_001 end"); } diff --git a/test/unittest/ability_manager_service_third_test/ability_manager_service_third_test.cpp b/test/unittest/ability_manager_service_third_test/ability_manager_service_third_test.cpp index 5ef97093c07127ee2bf56af65459d16485e9916b..dca029725a62284593cf6ad9335d21015ff8e2ca 100644 --- a/test/unittest/ability_manager_service_third_test/ability_manager_service_third_test.cpp +++ b/test/unittest/ability_manager_service_third_test/ability_manager_service_third_test.cpp @@ -735,10 +735,7 @@ HWTEST_F(AbilityManagerServiceThirdTest, JudgeMultiUserConcurrency_001, TestSize auto abilityMs_ = std::make_shared(); EXPECT_TRUE(abilityMs_->JudgeMultiUserConcurrency(0)); - auto temp = abilityMs_->userController_; - abilityMs_->userController_ = nullptr; EXPECT_FALSE(abilityMs_->JudgeMultiUserConcurrency(100)); - abilityMs_->userController_ = temp; TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceThirdTest JudgeMultiUserConcurrency_001 end"); } diff --git a/test/unittest/ability_manager_service_twelfth_test/ability_manager_service_twelfth_test.cpp b/test/unittest/ability_manager_service_twelfth_test/ability_manager_service_twelfth_test.cpp index 4cca6a082fcb3fff1dc7d3ade67edd9550b5ad8a..1bed41f371fb3b5cc016102c82f2cc1e8153f9c1 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 @@ -543,7 +543,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"); } @@ -620,8 +620,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); @@ -642,7 +640,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 3b447c5fceae38eaee69209e8389806cc7415ab5..d77b38cd87e8d3ccff7eab004042749cd1c3adfe 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 20e1a0749f63f18a4066a40ad5975f6261584357..26b3041f2d46cf3bcab53037fd0c8664a4494154 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 7ee8b3694f2cb1f4f9f31a5338e4a70c5eb02462..84f408c50e89845432d4f32466065ec8da21e5d1 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", ] @@ -120,6 +121,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 5c1ed7303c22b4466ae4a61c0c7480d4ccf30d34..e4843fe87860d33097fd68e215bbcd8276092ee4 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", ] @@ -108,7 +109,11 @@ ohos_unittest("AmsServiceStartupTest") { ] } if (ability_runtime_graphics) { - external_deps += [ "window_manager:libwm" ] + external_deps += [ + "window_manager:libdm", + "window_manager:libwm", + "window_manager:libwsutils", + ] } if (ability_runtime_upms) { deps += [ diff --git a/test/unittest/app_mgr_proxy_test/app_mgr_proxy_test.cpp b/test/unittest/app_mgr_proxy_test/app_mgr_proxy_test.cpp index 1ce51c9df870d020cc6e169200d3605b46a86d72..764900bb9484261ec76b1d59760c3e592f31d88d 100644 --- a/test/unittest/app_mgr_proxy_test/app_mgr_proxy_test.cpp +++ b/test/unittest/app_mgr_proxy_test/app_mgr_proxy_test.cpp @@ -943,7 +943,7 @@ HWTEST_F(AppMgrProxyTest, GetAllRunningInstanceKeysByBundleName_001, TestSize.Le int32_t userId = -1; data.WriteInt32(userId); - EXPECT_CALL(*mockAppMgrService_, GetAllRunningInstanceKeysByBundleName(_, _, _)).Times(1); + EXPECT_CALL(*mockAppMgrService_, GetAllRunningInstanceKeysByBundleName(_, _)).Times(1); auto result = mockAppMgrService_->OnRemoteRequest( static_cast(AppMgrInterfaceCode::GET_All_RUNNING_INSTANCE_KEYS_BY_BUNDLENAME), data, reply, option); diff --git a/test/unittest/app_mgr_service_event_handler_test/BUILD.gn b/test/unittest/app_mgr_service_event_handler_test/BUILD.gn index b614432777064ae766e4dd8192d4d97cf4ec04c5..5bb4c68bafbce9dbbab8152da33fbb4d53994a6e 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", ] @@ -118,6 +119,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 4e733fee508e2c81da2f2de910627d2b7bf59f4a..a916a1e2298d36cacc1cc461efe76826223ce4b1 100644 --- a/test/unittest/app_mgr_service_inner_eighth_test/BUILD.gn +++ b/test/unittest/app_mgr_service_inner_eighth_test/BUILD.gn @@ -104,6 +104,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 = [ @@ -151,6 +152,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 04921fd1e58c84b558557ccaa668dfb623e5f3cc..f40113da3dd1195a509869989d9635c309d175c4 100644 --- a/test/unittest/app_mgr_service_inner_eighth_test/app_mgr_service_inner_eighth_test.cpp +++ b/test/unittest/app_mgr_service_inner_eighth_test/app_mgr_service_inner_eighth_test.cpp @@ -587,38 +587,6 @@ HWTEST_F(AppMgrServiceInnerEighthTest, StartNativeProcessForDebugger_006, TestSi TAG_LOGI(AAFwkTag::TEST, "StartNativeProcessForDebugger_006 end"); } -/** - * @tc.name: GetCurrentAccountId_001 - * @tc.desc: test GetCurrentAccountId_001 - * @tc.type: FUNC - */ -HWTEST_F(AppMgrServiceInnerEighthTest, GetCurrentAccountId_001, TestSize.Level1) -{ - TAG_LOGI(AAFwkTag::TEST, "GetCurrentAccountId_001 start"); - auto appMgrServiceInner = std::make_shared(); - AAFwk::MyStatus::GetInstance().queryActiveOsAccountIds_ = ERR_NO_INIT; - - auto ret = appMgrServiceInner->GetCurrentAccountId(); - EXPECT_EQ(ret, DEFAULT_USER_ID); - TAG_LOGI(AAFwkTag::TEST, "GetCurrentAccountId_001 end"); -} - -/** - * @tc.name: GetCurrentAccountId_002 - * @tc.desc: test GetCurrentAccountId_002 - * @tc.type: FUNC - */ -HWTEST_F(AppMgrServiceInnerEighthTest, GetCurrentAccountId_002, TestSize.Level1) -{ - TAG_LOGI(AAFwkTag::TEST, "GetCurrentAccountId_002 start"); - auto appMgrServiceInner = std::make_shared(); - AAFwk::MyStatus::GetInstance().queryActiveOsAccountIds_ = ERR_OK; - - auto ret = appMgrServiceInner->GetCurrentAccountId(); - EXPECT_EQ(ret, DEFAULT_USER_ID); - TAG_LOGI(AAFwkTag::TEST, "GetCurrentAccountId_002 end"); -} - /** * @tc.name: SetCurrentUserId_001 * @tc.desc: test SetCurrentUserId_001 diff --git a/test/unittest/app_mgr_service_inner_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 037621bbfbd7da3f4e02305893ee6ae8eb701ed6..865ff47ffa095edd79863e0b6e43f8c9d7aa7b40 100644 --- a/test/unittest/app_mgr_service_inner_second_test/app_mgr_service_inner_second_test.cpp +++ b/test/unittest/app_mgr_service_inner_second_test/app_mgr_service_inner_second_test.cpp @@ -474,7 +474,8 @@ HWTEST_F(AppMgrServiceInnerSecondTest, GetAllRunningInstanceKeysByBundleName_010 EXPECT_NE(appMgrServiceInner, nullptr); std::string bundleName = "testBundleName"; std::vector instanceKeys; - auto ret = appMgrServiceInner->GetAllRunningInstanceKeysByBundleName(bundleName, instanceKeys); + int32_t userId = 100; + auto ret = appMgrServiceInner->GetAllRunningInstanceKeysByBundleName(bundleName, instanceKeys, userId); EXPECT_NE(ret, ERR_OK); TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleName_0100 end"); } @@ -1229,14 +1230,15 @@ HWTEST_F(AppMgrServiceInnerSecondTest, GetAllRunningInstanceKeysByBundleName_100 std::string bundleName = ""; std::vector instanceKeys; auto appMgrServiceInner = std::make_shared(); - auto res = appMgrServiceInner->GetAllRunningInstanceKeysByBundleName(bundleName, instanceKeys); + int32_t userId = 100; + auto res = appMgrServiceInner->GetAllRunningInstanceKeysByBundleName(bundleName, instanceKeys, userId); EXPECT_EQ(res, AAFwk::INVALID_PARAMETERS_ERR); bundleName = TEST_BUNDLE_NAME; appMgrServiceInner->remoteClientManager_ = nullptr; - res = appMgrServiceInner->GetAllRunningInstanceKeysByBundleName(bundleName, instanceKeys); + res = appMgrServiceInner->GetAllRunningInstanceKeysByBundleName(bundleName, instanceKeys, userId); EXPECT_EQ(res, ERR_INVALID_VALUE); appMgrServiceInner->remoteClientManager_ = std::make_shared(); - res = appMgrServiceInner->GetAllRunningInstanceKeysByBundleName(bundleName, instanceKeys); + res = appMgrServiceInner->GetAllRunningInstanceKeysByBundleName(bundleName, instanceKeys, userId); TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceInnerSecondTest_GetAllRunningInstanceKeysByBundleName_1000 end"); } diff --git a/test/unittest/app_mgr_service_inner_seventh_test/BUILD.gn b/test/unittest/app_mgr_service_inner_seventh_test/BUILD.gn index 444e58b6285a1480a2dc3010b0eb36c2225769ce..affddff7755418e2e333abbd118cc27538730439 100644 --- a/test/unittest/app_mgr_service_inner_seventh_test/BUILD.gn +++ b/test/unittest/app_mgr_service_inner_seventh_test/BUILD.gn @@ -103,6 +103,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 = [ @@ -149,6 +150,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 fd194f183b66f5f4f8bdb70bc8d6cc2b8cd9c243..ff27e173c0b90c5a6f183dc3444d288846f9841a 100644 --- a/test/unittest/app_mgr_service_inner_seventh_test/app_mgr_service_inner_seventh_test.cpp +++ b/test/unittest/app_mgr_service_inner_seventh_test/app_mgr_service_inner_seventh_test.cpp @@ -542,43 +542,24 @@ HWTEST_F(AppMgrServiceInnerSeventhTest, GetAllRunningInstanceKeysByBundleName_00 TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleName_001 start"); auto appMgrServiceInner = std::make_shared(); AAFwk::MyStatus::GetInstance().verifyCallingPermission_ = false; - - std::string bundleName = ""; - std::vector instanceKeys; - int32_t userId = 0; - int32_t ret = appMgrServiceInner->GetAllRunningInstanceKeysByBundleName(bundleName, instanceKeys, userId); - EXPECT_EQ(ret, ERR_PERMISSION_DENIED); - TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleName_001 end"); -} - -/** -* @tc.name: GetAllRunningInstanceKeysByBundleNameInner_001 -* @tc.desc: test GetAllRunningInstanceKeysByBundleNameInner_001 -* @tc.type: FUNC -*/ -HWTEST_F(AppMgrServiceInnerSeventhTest, GetAllRunningInstanceKeysByBundleNameInner_001, TestSize.Level1) -{ - TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleNameInner_001 start"); - auto appMgrServiceInner = std::make_shared(); - AAFwk::MyStatus::GetInstance().verifyCallingPermission_ = false; AAFwk::MyStatus::GetInstance().getBundleManagerHelper_ = nullptr; std::string bundleName = "111"; std::vector instanceKeys; int32_t userId = 0; - int32_t ret = appMgrServiceInner->GetAllRunningInstanceKeysByBundleNameInner(bundleName, instanceKeys, userId); + int32_t ret = appMgrServiceInner->GetAllRunningInstanceKeysByBundleName(bundleName, instanceKeys, userId); EXPECT_EQ(ret, ERR_INVALID_VALUE); - TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleNameInner_001 end"); + TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleName_001 end"); } /** -* @tc.name: GetAllRunningInstanceKeysByBundleNameInner_002 -* @tc.desc: test GetAllRunningInstanceKeysByBundleNameInner_002 +* @tc.name: GetAllRunningInstanceKeysByBundleName_002 +* @tc.desc: test GetAllRunningInstanceKeysByBundleName_002 * @tc.type: FUNC */ -HWTEST_F(AppMgrServiceInnerSeventhTest, GetAllRunningInstanceKeysByBundleNameInner_002, TestSize.Level1) +HWTEST_F(AppMgrServiceInnerSeventhTest, GetAllRunningInstanceKeysByBundleName_002, TestSize.Level1) { - TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleNameInner_002 start"); + TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleName_002 start"); auto appMgrServiceInner = std::make_shared(); appMgrServiceInner->appRunningManager_ = nullptr; AAFwk::MyStatus::GetInstance().getBundleManagerHelper_ = std::make_shared(); @@ -591,19 +572,19 @@ HWTEST_F(AppMgrServiceInnerSeventhTest, GetAllRunningInstanceKeysByBundleNameInn std::string bundleName = "111"; std::vector instanceKeys; int32_t userId = 0; - int32_t ret = appMgrServiceInner->GetAllRunningInstanceKeysByBundleNameInner(bundleName, instanceKeys, userId); + int32_t ret = appMgrServiceInner->GetAllRunningInstanceKeysByBundleName(bundleName, instanceKeys, userId); EXPECT_EQ(ret, ERR_INVALID_VALUE); - TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleNameInner_002 end"); + TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleName_002 end"); } /** -* @tc.name: GetAllRunningInstanceKeysByBundleNameInner_003 -* @tc.desc: test GetAllRunningInstanceKeysByBundleNameInner_003 +* @tc.name: GetAllRunningInstanceKeysByBundleName_003 +* @tc.desc: test GetAllRunningInstanceKeysByBundleName_003 * @tc.type: FUNC */ -HWTEST_F(AppMgrServiceInnerSeventhTest, GetAllRunningInstanceKeysByBundleNameInner_003, TestSize.Level1) +HWTEST_F(AppMgrServiceInnerSeventhTest, GetAllRunningInstanceKeysByBundleName_003, TestSize.Level1) { - TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleNameInner_003 start"); + TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleName_003 start"); auto appMgrServiceInner = std::make_shared(); AAFwk::MyStatus::GetInstance().verifyCallingPermission_ = false; AAFwk::MyStatus::GetInstance().getBundleManagerHelper_ = std::make_shared(); @@ -614,19 +595,19 @@ HWTEST_F(AppMgrServiceInnerSeventhTest, GetAllRunningInstanceKeysByBundleNameInn std::string bundleName = "111"; std::vector instanceKeys; int32_t userId = 0; - int32_t ret = appMgrServiceInner->GetAllRunningInstanceKeysByBundleNameInner(bundleName, instanceKeys, userId); + int32_t ret = appMgrServiceInner->GetAllRunningInstanceKeysByBundleName(bundleName, instanceKeys, userId); EXPECT_EQ(ret, ERR_MULTI_INSTANCE_NOT_SUPPORTED); - TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleNameInner_003 end"); + TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleName_003 end"); } /** -* @tc.name: GetAllRunningInstanceKeysByBundleNameInner_004 -* @tc.desc: test GetAllRunningInstanceKeysByBundleNameInner_004 +* @tc.name: GetAllRunningInstanceKeysByBundleName_004 +* @tc.desc: test GetAllRunningInstanceKeysByBundleName_004 * @tc.type: FUNC */ -HWTEST_F(AppMgrServiceInnerSeventhTest, GetAllRunningInstanceKeysByBundleNameInner_004, TestSize.Level1) +HWTEST_F(AppMgrServiceInnerSeventhTest, GetAllRunningInstanceKeysByBundleName_004, TestSize.Level1) { - TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleNameInner_004 start"); + TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleName_004 start"); auto appMgrServiceInner = std::make_shared(); AAFwk::MyStatus::GetInstance().verifyCallingPermission_ = false; AAFwk::MyStatus::GetInstance().getBundleManagerHelper_ = std::make_shared(); @@ -640,19 +621,19 @@ HWTEST_F(AppMgrServiceInnerSeventhTest, GetAllRunningInstanceKeysByBundleNameInn std::string bundleName = "111"; std::vector instanceKeys; int32_t userId = 0; - int32_t ret = appMgrServiceInner->GetAllRunningInstanceKeysByBundleNameInner(bundleName, instanceKeys, userId); + int32_t ret = appMgrServiceInner->GetAllRunningInstanceKeysByBundleName(bundleName, instanceKeys, userId); EXPECT_EQ(ret, ERR_OK); - TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleNameInner_004 end"); + TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleName_004 end"); } /** -* @tc.name: GetAllRunningInstanceKeysByBundleNameInner_005 -* @tc.desc: test GetAllRunningInstanceKeysByBundleNameInner_005 +* @tc.name: GetAllRunningInstanceKeysByBundleName_005 +* @tc.desc: test GetAllRunningInstanceKeysByBundleName_005 * @tc.type: FUNC */ -HWTEST_F(AppMgrServiceInnerSeventhTest, GetAllRunningInstanceKeysByBundleNameInner_005, TestSize.Level1) +HWTEST_F(AppMgrServiceInnerSeventhTest, GetAllRunningInstanceKeysByBundleName_005, TestSize.Level1) { - TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleNameInner_005 start"); + TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleName_005 start"); auto appMgrServiceInner = std::make_shared(); AAFwk::MyStatus::GetInstance().verifyCallingPermission_ = false; AAFwk::MyStatus::GetInstance().getBundleManagerHelper_ = std::make_shared(); @@ -670,19 +651,19 @@ HWTEST_F(AppMgrServiceInnerSeventhTest, GetAllRunningInstanceKeysByBundleNameInn std::string bundleName = "111"; std::vector instanceKeys; int32_t userId = 0; - int32_t ret = appMgrServiceInner->GetAllRunningInstanceKeysByBundleNameInner(bundleName, instanceKeys, userId); + int32_t ret = appMgrServiceInner->GetAllRunningInstanceKeysByBundleName(bundleName, instanceKeys, userId); EXPECT_EQ(ret, ERR_OK); - TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleNameInner_005 end"); + TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleName_005 end"); } /** -* @tc.name: GetAllRunningInstanceKeysByBundleNameInner_006 -* @tc.desc: test GetAllRunningInstanceKeysByBundleNameInner_006 +* @tc.name: GetAllRunningInstanceKeysByBundleName_006 +* @tc.desc: test GetAllRunningInstanceKeysByBundleName_006 * @tc.type: FUNC */ -HWTEST_F(AppMgrServiceInnerSeventhTest, GetAllRunningInstanceKeysByBundleNameInner_006, TestSize.Level1) +HWTEST_F(AppMgrServiceInnerSeventhTest, GetAllRunningInstanceKeysByBundleName_006, TestSize.Level1) { - TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleNameInner_006 start"); + TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleName_006 start"); auto appMgrServiceInner = std::make_shared(); AAFwk::MyStatus::GetInstance().verifyCallingPermission_ = false; AAFwk::MyStatus::GetInstance().getBundleManagerHelper_ = std::make_shared(); @@ -699,10 +680,10 @@ HWTEST_F(AppMgrServiceInnerSeventhTest, GetAllRunningInstanceKeysByBundleNameInn std::string bundleName = "111"; std::vector instanceKeys; - int32_t userId = 1; - int32_t ret = appMgrServiceInner->GetAllRunningInstanceKeysByBundleNameInner(bundleName, instanceKeys, userId); + int32_t userId = 100; + int32_t ret = appMgrServiceInner->GetAllRunningInstanceKeysByBundleName(bundleName, instanceKeys, userId); EXPECT_EQ(ret, ERR_OK); - TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleNameInner_006 end"); + TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleName_006 end"); } /** diff --git a/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp b/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp index 5b0fefdb459be7034e095e144e1c1b66d9551cd5..67661e94fdb0e70cabfc8ba6726e8e9556aea91c 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 @@ -5630,7 +5630,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 4902d04b18245b2c3d984cebe53dd40c24bc9d6f..94cd7b99ea5da128a93db94f43796e412f3e3ace 100644 --- a/test/unittest/app_mgr_stub_test/app_mgr_stub_test.cpp +++ b/test/unittest/app_mgr_stub_test/app_mgr_stub_test.cpp @@ -793,7 +793,7 @@ HWTEST_F(AppMgrStubTest, GetAllRunningInstanceKeysByBundleName_001, TestSize.Lev int32_t userId = -1; data.WriteInt32(userId); - EXPECT_CALL(*mockAppMgrService_, GetAllRunningInstanceKeysByBundleName(_, _, _)).Times(1); + EXPECT_CALL(*mockAppMgrService_, GetAllRunningInstanceKeysByBundleName(_, _)).Times(1); auto result = mockAppMgrService_->OnRemoteRequest( static_cast(AppMgrInterfaceCode::GET_All_RUNNING_INSTANCE_KEYS_BY_BUNDLENAME), data, reply, option); diff --git a/test/unittest/app_service_extension_context_test/ability_manager_stub_mock.h b/test/unittest/app_service_extension_context_test/ability_manager_stub_mock.h index cf600291074be499713ec85972cbbde0fe1fca4e..db46f920b16cc8dd91a2e6ec6ab18187ab1026cc 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 864735a568b0196d297574424149116bf1557d5a..db0cc8c6e3414eaf2c7398f65e845f7891cd89e0 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 = [ @@ -182,6 +183,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 468a327aad5418e72154f81703e19f842ba73904..e23b7376fab892f17f9824578a5a0a1a43848d15 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 4fe12fc613fa16f687f83120742603f05edc6f24..acfcb6ed89c74a1c5884acc5e51ab4d165935511 100644 --- a/test/unittest/keep_alive_process_manager_test/mock/include/ability_manager_service.h +++ b/test/unittest/keep_alive_process_manager_test/mock/include/ability_manager_service.h @@ -50,12 +50,6 @@ public: bool IsSceneBoardReady(int32_t userId); - /** - * get the user id. - * - */ - int32_t GetUserId() const; - /** * Starts a new ability with specific start options. * @@ -88,6 +82,8 @@ public: int32_t userId = DEFAULT_INVAL_VALUE, AppExecFwk::ExtensionAbilityType extensionType = AppExecFwk::ExtensionAbilityType::UNSPECIFIED); + int32_t GetCallerUserId() const; + public: static bool isInStatusBarResult; static bool isSupportStatusBarResult; diff --git a/test/unittest/keep_alive_process_manager_test/mock/src/ability_manager_service.cpp b/test/unittest/keep_alive_process_manager_test/mock/src/ability_manager_service.cpp index dffa2d0e0cda6546d98e18ba557f39585e41ba07..7be7e287e199f6757a2f0dff391059b05ea01123 100644 --- a/test/unittest/keep_alive_process_manager_test/mock/src/ability_manager_service.cpp +++ b/test/unittest/keep_alive_process_manager_test/mock/src/ability_manager_service.cpp @@ -56,11 +56,6 @@ bool AbilityManagerService::IsSceneBoardReady(int32_t userId) return isSceneBoardReadyResult; } -int32_t AbilityManagerService::GetUserId() const -{ - return userId_; -} - int32_t AbilityManagerService::StartAbility(const Want &want, const StartOptions &startOptions, const sptr &callerToken, int32_t userId, int requestCode) { @@ -77,5 +72,11 @@ int32_t AbilityManagerService::StartExtensionAbility(const Want &want, const spt usedStartExtensionAbilityTimes++; return startExtensionAbilityResult; } + +int32_t AbilityManagerService::GetCallerUserId() const +{ + int32_t userId = 100; + return userId; +} } // namespace AAFwk } // namespace OHOS diff --git a/test/unittest/multi_app_utils_test/include/mock_app_mgr_service.h b/test/unittest/multi_app_utils_test/include/mock_app_mgr_service.h index c11b4ec495427f42c5b56eb760d9947159ffd276..b4c11a5ffe501932bd6d372908c1362d9ab4b259 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/multi_instance_utils_second_test/mock_iapp_mgr.h b/test/unittest/multi_instance_utils_second_test/mock_iapp_mgr.h index 127d92c641b880b1472a215f20ec8e67fab897b5..1c96ac677e83786464eef820916b059708c56f49 100644 --- a/test/unittest/multi_instance_utils_second_test/mock_iapp_mgr.h +++ b/test/unittest/multi_instance_utils_second_test/mock_iapp_mgr.h @@ -92,7 +92,7 @@ public: } virtual int32_t GetAllRunningInstanceKeysByBundleName( - const std::string& bundleName, std::vector& instanceKeys, int32_t userId = -1) + const std::string& bundleName, std::vector& instanceKeys) { if (bundleName != "") { userId = 0; 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 cf600291074be499713ec85972cbbde0fe1fca4e..db46f920b16cc8dd91a2e6ec6ab18187ab1026cc 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 346bccbf3c95f8d7b6ac98bc542f4cdce9ac813a..bb711c54e9b885e26c30f01049961a4498a42029 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 46dd5858ccbaf90e4cdab8c600df78b465a548b4..b5ae419a83fe5f536831d53fb3c02e0f1e6f9d7b 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 @@ -3207,7 +3207,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 b2b0181584a478e2c6f17b8667cb265a05efca4b..0d43077c7fe2a260812b8601c200c94badd591c1 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; }