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 60e6e80a8145c07cdc6d07e8519968e74412c9ca..6c386d483d3df7458df24f066995635b6c07bc54 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_client.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_client.h @@ -1012,11 +1012,12 @@ public: /** * @brief start user. * @param accountId accountId. + * @param displayId logical screen id. * @param accountId is appRecovery or not. * * @return Returns ERR_OK on success, others on failure. */ - ErrCode StartUser(int accountId, sptr callback, bool isAppRecovery = false); + ErrCode StartUser(int accountId, uint64_t displayId, sptr callback, bool isAppRecovery = false); /** * @brief stop user. diff --git a/interfaces/inner_api/ability_manager/include/ability_manager_interface.h b/interfaces/inner_api/ability_manager/include/ability_manager_interface.h index c04c88ea43ab51e130c205d27b365d65a3ec4de9..5ca5958705932c6827ae2cbefbe13575b9a2b594 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/ams_mgr_interface.h b/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_interface.h index d2d3c1e1ce35cf3fe5ab659ff09092916e9e51c5..6014c9b2b9586686f198045b4012a91b04efb73e 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_interface.h +++ b/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_interface.h @@ -301,23 +301,6 @@ public: */ virtual int32_t NotifyAppMgrRecordExitReason(int32_t pid, int32_t reason, const std::string &exitMsg) = 0; - /** - * Set the current userId of appMgr. - * - * @param userId the user id. - * - * @return - */ - virtual void SetCurrentUserId(const int32_t userId) = 0; - - /** - * Set enable start process flag by userId - * @param userId the user id. - * @param enableStartProcess enable start process. - * @return - */ - virtual void SetEnableStartProcessFlagByUserId(int32_t userId, bool enableStartProcess) {} - /** * Get bundleName by pid. * @@ -546,8 +529,7 @@ public: GET_APPLICATION_INFO_BY_PROCESS_ID, KILL_APPLICATION_SELF, UPDATE_APPLICATION_INFO_INSTALLED, - SET_CURRENT_USER_ID, - Get_BUNDLE_NAME_BY_PID, + Get_BUNDLE_NAME_BY_PID = 21, SET_ABILITY_FOREGROUNDING_FLAG, REGISTER_APP_DEBUG_LISTENER, UNREGISTER_APP_DEBUG_LISTENER, @@ -577,8 +559,7 @@ public: FORCE_KILL_APPLICATION_BY_ACCESS_TOKEN_ID = 49, IS_PROCESS_ATTACHED, IS_CALLER_KILLING, - ENABLE_START_PROCESS_FLAG_BY_USER_ID, - SET_KEEP_ALIVE_DKV, + SET_KEEP_ALIVE_DKV = 53, SET_KEEP_ALIVE_APP_SERVICE, KILL_PROCESSES_IN_BATCH, PREPARE_TERMINATE_APP, diff --git a/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_proxy.h b/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_proxy.h index 5f01a91819c59d890fedd5f26f489996620c0fe1..c1812147090c6b81c0ae28ee61d51a2cdb4d53d9 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_proxy.h +++ b/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_proxy.h @@ -280,10 +280,6 @@ public: virtual void StartSpecifiedProcess(const AAFwk::Want &want, const AppExecFwk::AbilityInfo &abilityInfo, int32_t requestId = 0, const std::string &customProcess = "") override; - virtual void SetCurrentUserId(const int32_t userId) override; - - virtual void SetEnableStartProcessFlagByUserId(int32_t userId, bool enableStartProcess) override; - virtual int32_t GetBundleNameByPid(const int pid, std::string &bundleName, int32_t &uid) override; /** diff --git a/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_stub.h b/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_stub.h index 9ddbb2efcef6ddad2076262734689dedcf482564..8eb95d202617fafdb3fc5dde1409d1776238e0b9 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_stub.h +++ b/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_stub.h @@ -70,8 +70,6 @@ private: int32_t HandleGetApplicationInfoByProcessID(MessageParcel &data, MessageParcel &reply); int32_t HandleNotifyAppMgrRecordExitReason(MessageParcel &data, MessageParcel &reply); int32_t HandleUpdateApplicationInfoInstalled(MessageParcel &data, MessageParcel &reply); - int32_t HandleSetCurrentUserId(MessageParcel &data, MessageParcel &reply); - int32_t HandleSetEnableStartProcessFlagByUserId(MessageParcel &data, MessageParcel &reply); int32_t HandleGetBundleNameByPid(MessageParcel &data, MessageParcel &reply); int32_t HandleRegisterAppDebugListener(MessageParcel &data, MessageParcel &reply); int32_t HandleUnregisterAppDebugListener(MessageParcel &data, MessageParcel &reply); 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 6f48120bd711503931aadbd138803030e6b01984..8763e256bd75ea7ca4ae1ad8c5eab5933a64fd81 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 @@ -572,23 +572,6 @@ public: */ int32_t StartNativeProcessForDebugger(const AAFwk::Want &want); - /** - * Set the current userId of appMgr. - * - * @param userId the user id. - * - * @return - */ - void SetCurrentUserId(const int32_t userId); - - /** - * Set enable start process flag by userId - * @param userId the user id. - * @param enableStartProcess enable start process. - * @return - */ - void SetEnableStartProcessFlagByUserId(int32_t userId, bool enableStartProcess); - /** * Get bundleName by pid. * diff --git a/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_proxy.cpp b/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_proxy.cpp index a0f1af9ec0a849934fbf2c11a6c0432fd5cd8f2e..69d4b46837f53c343b2d632fa0d84a916cb5c744 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_proxy.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_proxy.cpp @@ -930,53 +930,6 @@ int32_t AmsMgrProxy::NotifyAppMgrRecordExitReason(int32_t pid, int32_t reason, c return reply.ReadInt32(); } -void AmsMgrProxy::SetCurrentUserId(const int32_t userId) -{ - TAG_LOGD(AAFwkTag::APPMGR, "start"); - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - if (!WriteInterfaceToken(data)) { - return; - } - if (!data.WriteInt32(userId)) { - TAG_LOGE(AAFwkTag::APPMGR, "Failed to write userId"); - return; - } - int32_t ret = - SendTransactCmd(static_cast(IAmsMgr::Message::SET_CURRENT_USER_ID), - data, reply, option); - if (ret != NO_ERROR) { - TAG_LOGW(AAFwkTag::APPMGR, "SendRequest err: %{public}d", ret); - } - TAG_LOGD(AAFwkTag::APPMGR, "end"); -} - -void AmsMgrProxy::SetEnableStartProcessFlagByUserId(int32_t userId, bool enableStartProcess) -{ - TAG_LOGD(AAFwkTag::APPMGR, "called"); - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - if (!WriteInterfaceToken(data)) { - return; - } - if (!data.WriteInt32(userId)) { - TAG_LOGE(AAFwkTag::APPMGR, "Failed to write userId"); - return; - } - if (!data.WriteBool(enableStartProcess)) { - TAG_LOGE(AAFwkTag::APPMGR, "Failed to write enableStartProcess"); - return; - } - int32_t ret = - SendTransactCmd(static_cast(IAmsMgr::Message::ENABLE_START_PROCESS_FLAG_BY_USER_ID), - data, reply, option); - if (ret != NO_ERROR) { - TAG_LOGW(AAFwkTag::APPMGR, "SendRequest err: %{public}d", ret); - } -} - int32_t AmsMgrProxy::GetBundleNameByPid(const int pid, std::string &bundleName, int32_t &uid) { MessageParcel data; diff --git a/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_stub.cpp b/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_stub.cpp index fa0925a3e5c1f5691b2c831561ba3907769fbf3c..cf4ce8570ce9e125095505da4298f2b17a00f44c 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_stub.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_stub.cpp @@ -139,10 +139,6 @@ int32_t AmsMgrStub::OnRemoteRequestInnerSecond(uint32_t code, MessageParcel &dat return HandleNotifyAppMgrRecordExitReason(data, reply); case static_cast(IAmsMgr::Message::UPDATE_APPLICATION_INFO_INSTALLED): return HandleUpdateApplicationInfoInstalled(data, reply); - case static_cast(IAmsMgr::Message::SET_CURRENT_USER_ID): - return HandleSetCurrentUserId(data, reply); - case static_cast(IAmsMgr::Message::ENABLE_START_PROCESS_FLAG_BY_USER_ID): - return HandleSetEnableStartProcessFlagByUserId(data, reply); case static_cast(IAmsMgr::Message::Get_BUNDLE_NAME_BY_PID): return HandleGetBundleNameByPid(data, reply); case static_cast(IAmsMgr::Message::REGISTER_APP_DEBUG_LISTENER): @@ -625,21 +621,6 @@ int32_t AmsMgrStub::HandleUpdateApplicationInfoInstalled(MessageParcel &data, Me return NO_ERROR; } -int32_t AmsMgrStub::HandleSetCurrentUserId(MessageParcel &data, MessageParcel &reply) -{ - int32_t userId = data.ReadInt32(); - SetCurrentUserId(userId); - return NO_ERROR; -} - -int32_t AmsMgrStub::HandleSetEnableStartProcessFlagByUserId(MessageParcel &data, MessageParcel &reply) -{ - int32_t userId = data.ReadInt32(); - bool enableStartProcess = data.ReadBool(); - SetEnableStartProcessFlagByUserId(userId, enableStartProcess); - return NO_ERROR; -} - int32_t AmsMgrStub::HandleGetBundleNameByPid(MessageParcel &data, MessageParcel &reply) { int32_t pid = data.ReadInt32(); 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 bd2899945ef36454e9429247625260b59617db2d..20ba29b334b52fab5e1d0f199c5929cdf2d58793 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 @@ -1024,32 +1024,6 @@ sptr AppMgrClient::GetRemoteObject() return mgrHolder_->GetRemoteObject(); } -void AppMgrClient::SetCurrentUserId(const int32_t userId) -{ - sptr service = iface_cast(mgrHolder_->GetRemoteObject()); - if (service == nullptr) { - return; - } - sptr amsService = service->GetAmsMgr(); - if (amsService == nullptr) { - return; - } - amsService->SetCurrentUserId(userId); -} - -void AppMgrClient::SetEnableStartProcessFlagByUserId(int32_t userId, bool enableStartProcess) -{ - sptr service = iface_cast(mgrHolder_->GetRemoteObject()); - if (service == nullptr) { - return; - } - sptr amsService = service->GetAmsMgr(); - if (amsService == nullptr) { - return; - } - amsService->SetEnableStartProcessFlagByUserId(userId, enableStartProcess); -} - int32_t AppMgrClient::GetBundleNameByPid(const int pid, std::string &bundleName, int32_t &uid) { sptr service = iface_cast(mgrHolder_->GetRemoteObject()); diff --git a/services/abilitymgr/BUILD.gn b/services/abilitymgr/BUILD.gn index 822dce7b58e8c0985e8b2b01b96b60b23604a3a6..69362ad783b7a7fb4252db399517a69afca932da 100644 --- a/services/abilitymgr/BUILD.gn +++ b/services/abilitymgr/BUILD.gn @@ -157,6 +157,7 @@ ohos_shared_library("abilityms") { "${ability_runtime_services_path}/common:record_cost_time_util", "${ability_runtime_services_path}/common:res_sched_util", "${ability_runtime_services_path}/common:task_handler_wrap", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ diff --git a/services/abilitymgr/abilitymgr.gni b/services/abilitymgr/abilitymgr.gni index ea0b7039abb851c2a1628a15a052149b478cd13f..a5440e0e678fe3306f8928987148b9a488150270 100644 --- a/services/abilitymgr/abilitymgr.gni +++ b/services/abilitymgr/abilitymgr.gni @@ -100,10 +100,6 @@ abilityms_files = [ "src/connection_state_manager.cpp", "src/dlp_state_item.cpp", - #multi user - "src/user_controller.cpp", - "src/user_event_handler.cpp", - #free_install "src/atomic_service_status_callback_proxy.cpp", "src/atomic_service_status_callback_stub.cpp", diff --git a/services/abilitymgr/include/ability_auto_startup_service.h b/services/abilitymgr/include/ability_auto_startup_service.h index a9ea45b1101d498598bfee89aaae1e565778a4b6..4c2859afc8d486a48c966b2047668286995f2dee 100644 --- a/services/abilitymgr/include/ability_auto_startup_service.h +++ b/services/abilitymgr/include/ability_auto_startup_service.h @@ -144,7 +144,6 @@ private: void CleanResource(const wptr &remote); std::string GetSelfApplicationBundleName(); bool CheckSelfApplication(const std::string &bundleName); - int32_t GetValidUserId(int32_t userId); bool GetBundleInfo(const std::string &bundleName, int32_t userId, int32_t appIndex, AppExecFwk::BundleInfo &bundleInfo); bool GetAbilityData(const AutoStartupInfo &info, AutoStartupAbilityData &abilityData); diff --git a/services/abilitymgr/include/ability_manager_proxy.h b/services/abilitymgr/include/ability_manager_proxy.h index 90aa5002ea4b2fc397d3db6430d780e1c1cdde08..3e8e2addde11f6d6ec962e1df7a678a59542443c 100644 --- a/services/abilitymgr/include/ability_manager_proxy.h +++ b/services/abilitymgr/include/ability_manager_proxy.h @@ -855,10 +855,12 @@ public: /** * @brief start user. * @param accountId accountId. + * @param displayId logical screen id. * @param isAppRecovery is appRecovery or not. * @return Returns ERR_OK on success, others on failure. */ - virtual int StartUser(int userId, sptr callback, bool isAppRecovery = false) override; + virtual int StartUser(int userId, uint64_t displayId, sptr callback, + bool isAppRecovery = false) override; /** * @brief stop user. diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h index 2a291424e2d6d2fb30893c35ae3f6aa9b1e0bae9..9df09762c6ce3b4605ae7513fa51fe0a0c4939c2 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -65,7 +65,6 @@ #include "system_ability.h" #include "task_handler_wrap.h" #include "uri.h" -#include "user_controller.h" #include "intent_exemption_info.h" #ifdef SUPPORT_GRAPHICS #include "implicit_start_processor.h" @@ -1220,7 +1219,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; @@ -1589,12 +1589,6 @@ public: */ sptr GetCollaborator(int32_t type); - /** - * get the user id. - * - */ - int32_t GetUserId() const; - virtual int32_t RegisterStatusBarDelegate(sptr delegate) override; virtual int32_t KillProcessWithPrepareTerminate(const std::vector& pids) override; @@ -2153,8 +2147,6 @@ public: TERMINATE_ABILITY_CODE }; - friend class UserController; - protected: void OnAbilityRequestDone(const sptr &token, const int32_t state) override; int GetUidByBundleName(std::string bundleName); @@ -2218,7 +2210,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. @@ -2290,7 +2282,7 @@ private: void DumpMissionListInner(const std::string &args, std::vector &info); void DumpMissionInfosInner(const std::string &args, std::vector &info); - bool JudgeMultiUserConcurrency(const int32_t userId); + bool JudgeMultiUserConcurrency(int32_t userId); bool CheckCrossUser(const int32_t userId, AppExecFwk::ExtensionAbilityType extensionType); void SendExtensionReport(EventInfo &eventInfo, int32_t errCode, bool isService = false); void SendIntentReport(EventInfo &eventInfo, int32_t errCode, const std::string &intentName); @@ -2327,7 +2319,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(); @@ -2359,7 +2351,7 @@ private: bool JudgeSelfCalled(const std::shared_ptr &abilityRecord); bool IsAppSelfCalled(const std::shared_ptr &abilityRecord); - int32_t GetValidUserId(const int32_t userId); + int32_t GetValidUserId(int32_t userId); int DelegatorMoveMissionToFront(int32_t missionId); @@ -2740,7 +2732,6 @@ private: std::shared_ptr freeInstallManager_; std::shared_ptr subManagersHelper_; - std::shared_ptr userController_; sptr abilityController_ = nullptr; std::multimap timeoutMap_; @@ -2808,6 +2799,7 @@ private: int32_t OpenLinkInner(const Want &want, sptr callerToken, int32_t userId, int requestCode, bool removeInsightIntentFlag); int32_t KillProcessWithReasonInner(int32_t pid, const ExitReason &reason, bool isKillPrecedeStart); + int32_t UpdateApplicationKeepAlive(int32_t userId) const; #ifdef BGTASKMGR_CONTINUOUS_TASK_ENABLE std::shared_ptr bgtaskObserver_; #endif diff --git a/services/abilitymgr/include/app_scheduler.h b/services/abilitymgr/include/app_scheduler.h index 976b318b63c0b84e640c5549844314c41d017526..eee86af4c0c4b135eedb23e06a3fdb0151e30c16 100644 --- a/services/abilitymgr/include/app_scheduler.h +++ b/services/abilitymgr/include/app_scheduler.h @@ -476,23 +476,6 @@ public: */ virtual int32_t NotifyAppMgrRecordExitReason(int32_t pid, int32_t reason, const std::string &exitMsg); - /** - * Set the current userId of appMgr, only used by abilityMgr. - * - * @param userId the user id. - * - * @return - */ - void SetCurrentUserId(int32_t userId); - - /** - * Set enable start process flag by userId - * @param userId the user id. - * @param enableStartProcess enable start process. - * @return - */ - void SetEnableStartProcessFlagByUserId(int32_t userId, bool enableStartProcess); - /** * Get bundleName by pid. * diff --git a/services/abilitymgr/include/user_controller.h b/services/abilitymgr/include/user_controller.h deleted file mode 100644 index c516fb9206ae69ed6f61eade304529cd81c74bf6..0000000000000000000000000000000000000000 --- a/services/abilitymgr/include/user_controller.h +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Copyright (c) 2021-2023 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_CONTROLLER_H -#define OHOS_ABILITY_RUNTIME_USER_CONTROLLER_H - -#include -#include -#include "cpp/mutex.h" - -#include "user_event_handler.h" -#include "refbase.h" - -namespace OHOS { -namespace AAFwk { -class IUserCallback; - -const int32_t USER_ID_NO_HEAD = 0; -const int32_t USER_ID_DEFAULT = 100; - -enum UserState { - STATE_BOOTING = 0, - STATE_STARTED, - STATE_STOPPING, - STATE_SHUTDOWN -}; - -class UserItem { -public: - explicit UserItem(int32_t id); - virtual ~UserItem(); - - int32_t GetUserId(); - void SetState(const UserState &state); - UserState GetState(); - -private: - int32_t userId_; - UserState curState_ = STATE_BOOTING; - UserState lastState_ = STATE_BOOTING; -}; - -class UserEvent : public EventDataBase { -public: - virtual ~UserEvent() = default; - int32_t oldUserId; - int32_t newUserId; - std::shared_ptr userItem; -}; - -class UserController : public std::enable_shared_from_this { -public: - UserController(); - virtual ~UserController(); - - void Init(); - - /** - * Start user, if it is not running.. - * - * @param userId id of started user. - * @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); - - /** - * Stop user, if it is running.. - * - * @param userId id of started user. - * @return 0 if the user has been successfully started. - */ - int32_t StopUser(int32_t userId); - - /** - * Logout user, if it is running.. - * - * @param userId id of Logout user. - * @return 0 if the user has been successfully Logout. - */ - int32_t LogoutUser(int32_t userId, sptr callback = nullptr); - - int32_t GetCurrentUserId(); - - std::shared_ptr GetUserItem(int32_t userId); - - void ProcessEvent(const EventWrap &event); - - int32_t GetFreezingNewUserId() const; - - void SetFreezingNewUserId(int32_t userId); - - void ClearAbilityUserItems(int32_t userId); - -private: - bool IsCurrentUser(int32_t userId); - 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, - bool isAppRecovery = false); - void UserBootDone(std::shared_ptr &item); - void BroadcastUserBackground(int32_t userId); - void BroadcastUserForeground(int32_t userId); - void BroadcastUserStopping(int32_t userId); - void BroadcastUserStopped(int32_t userId); - - void SendSystemUserStart(int32_t userId); - void SendSystemUserCurrent(int32_t oldUserId, int32_t newUserId); - void SendReportUserSwitch(int32_t oldUserId, int32_t newUserId, - std::shared_ptr &usrItem); - void SendUserSwitchTimeout(int32_t oldUserId, int32_t newUserId, - std::shared_ptr &usrItem); - void SendContinueUserSwitch(int32_t oldUserId, int32_t newUserId, - std::shared_ptr &usrItem); - void SendUserSwitchDone(int32_t userId); - - void HandleSystemUserStart(int32_t userId); - void HandleSystemUserCurrent(int32_t oldUserId, int32_t newUserId); - void HandleReportUserSwitch(int32_t oldUserId, int32_t newUserId, - std::shared_ptr &usrItem); - void HandleUserSwitchTimeout(int32_t oldUserId, int32_t newUserId, - std::shared_ptr &usrItem); - void HandleContinueUserSwitch(int32_t oldUserId, int32_t newUserId, - std::shared_ptr &usrItem); - 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_; - ffrt::mutex userLock_; -}; -} // namespace AAFwk -} // namespace OHOS -#endif // OHOS_ABILITY_RUNTIME_USER_CONTROLLER_H diff --git a/services/abilitymgr/include/user_event_handler.h b/services/abilitymgr/include/user_event_handler.h deleted file mode 100644 index 49b53eb9244f0149c8a6525618f4da132a7d2ca7..0000000000000000000000000000000000000000 --- a/services/abilitymgr/include/user_event_handler.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2021 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_EVENT_HANDLER_H -#define OHOS_ABILITY_RUNTIME_USER_EVENT_HANDLER_H - -#include - -#include "event_handler_wrap.h" - -namespace OHOS { -namespace AAFwk { -class UserController; -class UserEventHandler : public EventHandlerWrap { -public: - UserEventHandler( - const std::shared_ptr &taskHandler, const std::weak_ptr &owner); - virtual ~UserEventHandler() = default; - - static constexpr uint32_t EVENT_SYSTEM_USER_START = 10; - static constexpr uint32_t EVENT_SYSTEM_USER_CURRENT = 20; - static constexpr uint32_t EVENT_REPORT_USER_SWITCH = 30; - static constexpr uint32_t EVENT_CONTINUE_USER_SWITCH = 40; - static constexpr uint32_t EVENT_USER_SWITCH_TIMEOUT = 50; - static constexpr uint32_t EVENT_REPORT_USER_SWITCH_DONE = 60; - - /** - * ProcessEvent with request. - * - * @param event, inner event loop. - */ - void ProcessEvent(const EventWrap &event) override; - -private: - std::weak_ptr controller_; -}; -} // namespace AAFwk -} // namespace OHOS -#endif // OHOS_ABILITY_RUNTIME_USER_EVENT_HANDLER_H diff --git a/services/abilitymgr/libabilityms.map b/services/abilitymgr/libabilityms.map index 65832ba509c48e23ca58f51e98f1379b4acff835..21026ec494a59be2853787bd24366be0d61fe514 100644 --- a/services/abilitymgr/libabilityms.map +++ b/services/abilitymgr/libabilityms.map @@ -98,7 +98,6 @@ *SenderInfo*; *ExtensionRunningInfo*; *UserCallbackStub*; - *UserItem*; *WantReceiverStub*; *WantReceiverProxy*; *WantSenderProxy*; diff --git a/services/abilitymgr/src/ability_auto_startup_service.cpp b/services/abilitymgr/src/ability_auto_startup_service.cpp index 6c6d2a2218c6000b75a1a8257ac07a30a6390b3c..5cda8502a454236e887603f3aeddcb2d8d525f78 100644 --- a/services/abilitymgr/src/ability_auto_startup_service.cpp +++ b/services/abilitymgr/src/ability_auto_startup_service.cpp @@ -23,6 +23,7 @@ #include "hilog_tag_wrapper.h" #include "in_process_call_wrapper.h" #include "permission_constants.h" +#include "user_controller/user_controller.h" namespace OHOS { namespace AbilityRuntime { @@ -252,8 +253,7 @@ int32_t AbilityAutoStartupService::CheckAutoStartupData(const std::string &bundl int32_t appIndex = 0; AppExecFwk::BundleInfo bundleInfo; int32_t userId = uid / AppExecFwk::Constants::BASE_USER_RANGE; - int32_t validUserId = GetValidUserId(userId); - if (!GetBundleInfo(bundleName, validUserId, appIndex, bundleInfo)) { + if (!GetBundleInfo(bundleName, userId, appIndex, bundleInfo)) { return INNER_ERR; } auto tokenId = bundleInfo.applicationInfo.accessTokenId; @@ -300,8 +300,7 @@ void AbilityAutoStartupService::ExecuteCallbacks(bool isCallOn, const AutoStartu " accessTokenId: %{public}s, setterUserId: %{public}d, userId: %{public}d", info.bundleName.c_str(), info.moduleName.c_str(), info.abilityName.c_str(), info.accessTokenId.c_str(), info.setterUserId, info.userId); - int32_t currentUserId = DelayedSingleton::GetInstance()->GetUserId(); - bool isUserIdMatch = (info.userId == currentUserId); + bool isUserIdMatch = UserController::GetInstance().IsCurrentUser(info.userId); bool isUserIdU0OrU1 = (U0_USER_ID == info.userId) || (U1_USER_ID == info.userId); if (!isUserIdMatch && !isUserIdU0OrU1) { TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Condition not satisfied"); @@ -408,20 +407,6 @@ bool AbilityAutoStartupService::CheckSelfApplication(const std::string &bundleNa return GetSelfApplicationBundleName() == bundleName ? true : false; } -int32_t AbilityAutoStartupService::GetValidUserId(int32_t userId) -{ - TAG_LOGD(AAFwkTag::AUTO_STARTUP, "userId = %{public}d.", userId); - int32_t validUserId = userId; - - if (userId == -1) { - validUserId = IPCSkeleton::GetCallingUid() / AppExecFwk::Constants::BASE_USER_RANGE; - } - if (validUserId == U0_USER_ID || validUserId == U1_USER_ID) { - validUserId = DelayedSingleton::GetInstance()->GetUserId(); - } - return validUserId; -} - bool AbilityAutoStartupService::GetBundleInfo(const std::string &bundleName, int32_t userId, int32_t appIndex, AppExecFwk::BundleInfo &bundleInfo) { @@ -468,8 +453,8 @@ bool AbilityAutoStartupService::GetAbilityData(const AutoStartupInfo &info, Auto info.bundleName.c_str(), info.moduleName.c_str(), info.abilityName.c_str(), info.accessTokenId.c_str(), info.setterUserId); AppExecFwk::BundleInfo bundleInfo; - int32_t validUserId = GetValidUserId(info.userId); - if (!GetBundleInfo(info.bundleName, validUserId, info.appCloneIndex, bundleInfo)) { + int32_t callerUserId = UserController::GetInstance().GetCallerUserId(); + if (!GetBundleInfo(info.bundleName, callerUserId, info.appCloneIndex, bundleInfo)) { TAG_LOGE(AAFwkTag::AUTO_STARTUP, "GetBundleInfo fail"); return false; } diff --git a/services/abilitymgr/src/ability_connect_manager.cpp b/services/abilitymgr/src/ability_connect_manager.cpp index 6085e0b6c202a650739dc928103feb2eb7a45e9b..3b8bba5aa2d996df224f8109d98a203aa64796f7 100644 --- a/services/abilitymgr/src/ability_connect_manager.cpp +++ b/services/abilitymgr/src/ability_connect_manager.cpp @@ -42,6 +42,7 @@ #include "datetime_ex.h" #include "init_reboot.h" #include "string_wrapper.h" +#include "user_controller/user_controller.h" namespace OHOS { namespace AAFwk { @@ -652,7 +653,7 @@ int AbilityConnectManager::ConnectAbilityLocked(const AbilityRequest &abilityReq #ifdef SUPPORT_UPMS // grant uri to service extension by connect, must call out of serialMutex_ if (userId_ == U0_USER_ID || - userId_ == DelayedSingleton::GetInstance()->GetUserId()) { + userId_ == AbilityRuntime::UserController::GetInstance().GetCallerUserId()) { UriUtils::GetInstance().GrantUriPermissionForServiceExtension(abilityRequest); } else { TAG_LOGD(AAFwkTag::ABILITYMGR, "cross user, without grantUriPermission"); @@ -1895,7 +1896,7 @@ void AbilityConnectManager::HandleStartTimeoutTask(const std::shared_ptr::GetInstance()->AttachTimeOut(abilityRecord->GetToken()); if (abilityRecord->IsSceneBoard()) { - if (DelayedSingleton::GetInstance()->GetUserId() == userId_) { + if (AbilityRuntime::UserController::GetInstance().IsCurrentUser(userId_)) { RestartAbility(abilityRecord, userId_); } return; @@ -2483,8 +2484,7 @@ void AbilityConnectManager::CleanActivatingTimeoutAbility(std::shared_ptrIsSceneBoard() || - DelayedSingleton::GetInstance()->GetUserId() == userId_) { + if (!abilityRecord->IsSceneBoard() || AbilityRuntime::UserController::GetInstance().IsCurrentUser(userId_)) { RestartAbility(abilityRecord, userId_); } } @@ -2536,7 +2536,7 @@ void AbilityConnectManager::KeepAbilityAlive(const std::shared_ptr } if (abilityRecord->IsSceneBoard()) { requestInfo.want.SetParam("ohos.app.recovery", true); + uint64_t displayId = 0; + if (AbilityRuntime::UserController::GetInstance().GetDisplayIdByUserId(userId_, displayId)) { + requestInfo.want.SetParam(Want::PARAM_RESV_DISPLAY_ID, static_cast(displayId)); + } DelayedSingleton::GetInstance()->EnableListForSCBRecovery(userId_); } requestInfo.restartCount = abilityRecord->GetRestartCount(); @@ -3029,7 +3033,7 @@ void AbilityConnectManager::PauseExtensions() auto targetExtension = it->second; if (targetExtension != nullptr && targetExtension->GetAbilityInfo().type == AbilityType::EXTENSION && (IsLauncher(targetExtension) || targetExtension->IsSceneBoard() || - (targetExtension->GetKeepAlive() && userId_ != USER_ID_NO_HEAD))) { + (targetExtension->GetKeepAlive() && userId_ != U0_USER_ID))) { terminatingExtensionList_.push_back(it->second); it = serviceMap_.erase(it); TAG_LOGI(AAFwkTag::EXT, "terminate ability:%{public}s, serviceMap size:%{public}zu", diff --git a/services/abilitymgr/src/ability_manager_client.cpp b/services/abilitymgr/src/ability_manager_client.cpp index bc5b52dd421fe83cdada35147a74a6580842c171..49b8eea077a9da23b6e7746a07a25ca9e36e6af8 100644 --- a/services/abilitymgr/src/ability_manager_client.cpp +++ b/services/abilitymgr/src/ability_manager_client.cpp @@ -1236,13 +1236,14 @@ ErrCode AbilityManagerClient::StopSyncRemoteMissions(const std::string &devId) return abms->StopSyncRemoteMissions(devId); } -ErrCode AbilityManagerClient::StartUser(int accountId, sptr callback, bool isAppRecovery) +ErrCode AbilityManagerClient::StartUser(int accountId, uint64_t displayId, sptr callback, + bool isAppRecovery) { TAG_LOGI(AAFwkTag::ABILITYMGR, "accountId:%{public}d, isAppRecovery:%{public}d", accountId, isAppRecovery); auto abms = GetAbilityManager(); CHECK_POINTER_RETURN_NOT_CONNECTED(abms); - return abms->StartUser(accountId, callback, isAppRecovery); + return abms->StartUser(accountId, displayId, callback, isAppRecovery); } ErrCode AbilityManagerClient::StopUser(int accountId, sptr callback) diff --git a/services/abilitymgr/src/ability_manager_proxy.cpp b/services/abilitymgr/src/ability_manager_proxy.cpp index 8ab7a0ec36fb0271e9bc7d2162079b9b9957befd..4494e0daa6f24aa427150dec50241dd8df456c6a 100644 --- a/services/abilitymgr/src/ability_manager_proxy.cpp +++ b/services/abilitymgr/src/ability_manager_proxy.cpp @@ -3242,7 +3242,7 @@ int AbilityManagerProxy::MoveMissionsToBackground(const std::vector& mi return reply.ReadInt32(); } -int AbilityManagerProxy::StartUser(int userId, sptr callback, bool isAppRecovery) +int AbilityManagerProxy::StartUser(int userId, uint64_t displayId, sptr callback, bool isAppRecovery) { Ability_MANAGER_HITRACE_CHAIN_NAME("StartUser", HITRACE_FLAG_INCLUDE_ASYNC); MessageParcel data; @@ -3253,6 +3253,10 @@ int AbilityManagerProxy::StartUser(int userId, sptr callback, boo TAG_LOGE(AAFwkTag::ABILITYMGR, "fail"); return ERR_INVALID_VALUE; } + if (!data.WriteUint64(displayId)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "write displayId failed"); + return IPC_PROXY_ERR; + } if (!callback) { data.WriteBool(false); } else { diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index da29f8b836b117a1a7d275125e438efa832b421e..5fa2886eb236f8b82b36eae03af964006002bb45 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -135,6 +135,7 @@ #include "hidden_start_observer_manager.h" #include "insight_intent_db_cache.h" #include "sa_interceptor_manager.h" +#include "user_controller/user_controller.h" using OHOS::AppExecFwk::ElementName; using OHOS::Security::AccessToken::AccessTokenKit; @@ -333,6 +334,7 @@ constexpr const char* LIFE_CYCLE_MINIMIZE = "minimize"; constexpr const char* LIFE_CYCLE_TERMINATE = "terminate"; constexpr const char* LIFE_CYCLE_PRELOAD = "preload"; constexpr uint32_t TARGET_TYPE_INIT = 100; +constexpr int64_t USER_SWITCH_TIMEOUT = 3 * 1000; // 3s const bool REGISTER_RESULT = SystemAbility::MakeAndRegisterAbility(DelayedSingleton::GetInstance().get()); @@ -408,9 +410,6 @@ bool AbilityManagerService::Init() freeInstallManager_ = std::make_shared(weak_from_this()); CHECK_POINTER_RETURN_BOOL(freeInstallManager_); - // init user controller. - userController_ = std::make_shared(); - userController_->Init(); AmsConfigurationParameter::GetInstance().Parse(); TAG_LOGI(AAFwkTag::ABILITYMGR, "config parse"); subManagersHelper_ = std::make_shared(taskHandler_, eventHandler_); @@ -934,7 +933,8 @@ 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()); + auto callerUserId = AbilityRuntime::UserController::GetInstance().GetCallerUserId(); + AbilityUtil::AddAbilityJumpRuleToBms(callerPkg, targetPkg, callerUserId); } int32_t ret = StartAbilityWrap(newWant, callerToken, requestCode, false, userId, true, 0, false, isImplicit, false); @@ -971,8 +971,9 @@ int AbilityManagerService::StartAbilityPrechainInterceptor(StartAbilityParams &p { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); auto shouldBlockFunc = [aams = shared_from_this()]() { return aams->ShouldBlockAllAppStart(); }; + auto callerUserId = AbilityRuntime::UserController::GetInstance().GetCallerUserId(); AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(params.want, params.requestCode, - GetUserId(), true, nullptr, shouldBlockFunc); + callerUserId, true, nullptr, shouldBlockFunc); auto interceptorResult = interceptorExecuter_ == nullptr ? ERR_INVALID_VALUE : interceptorExecuter_->DoProcess(interceptorParam); if (interceptorResult != ERR_OK) { @@ -1251,7 +1252,8 @@ int AbilityManagerService::StartAbilityInner(const Want &want, const sptrShouldBlockAllAppStart(); }; - AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(want, requestCode, GetUserId(), + auto callerUserId = AbilityRuntime::UserController::GetInstance().GetCallerUserId(); + AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(want, requestCode, callerUserId, true, nullptr, shouldBlockFunc); result = interceptorExecuter_ == nullptr ? ERR_NULL_INTERCEPTOR_EXECUTER : interceptorExecuter_->DoProcess(interceptorParam); @@ -1424,7 +1426,7 @@ int AbilityManagerService::StartAbilityInner(const Want &want, const sptr(abilityInfo), isStartAsCaller, appIndex); result = afterCheckExecuter_ == nullptr ? ERR_NULL_AFTER_CHECK_EXECUTER : afterCheckExecuter_->DoProcess(afterCheckParam); @@ -1437,14 +1439,14 @@ int AbilityManagerService::StartAbilityInner(const Want &want, const sptrShouldBlockAllAppStart(); }; - AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(want, requestCode, GetUserId(), + auto callerUserId = AbilityRuntime::UserController::GetInstance().GetCallerUserId(); + AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(want, requestCode, callerUserId, true, nullptr, shouldBlockFunc); result = interceptorExecuter_ == nullptr ? ERR_NULL_INTERCEPTOR_EXECUTER : interceptorExecuter_->DoProcess(interceptorParam); @@ -1782,7 +1785,7 @@ int AbilityManagerService::StartAbilityDetails(const Want &want, const AbilitySt } AbilityInterceptorParam afterCheckParam = AbilityInterceptorParam(abilityRequest.want, requestCode, - GetUserId(), true, callerToken, std::make_shared(abilityInfo), false, appIndex); + callerUserId, true, callerToken, std::make_shared(abilityInfo), false, appIndex); result = afterCheckExecuter_ == nullptr ? ERR_NULL_AFTER_CHECK_EXECUTER : afterCheckExecuter_->DoProcess(afterCheckParam); if (result != ERR_OK) { @@ -2027,7 +2030,8 @@ 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(), + auto callerUserId = AbilityRuntime::UserController::GetInstance().GetCallerUserId(); + AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(want, requestCode, callerUserId, true, nullptr, shouldBlockFunc); auto result = interceptorExecuter_ == nullptr ? ERR_NULL_INTERCEPTOR_EXECUTER : interceptorExecuter_->DoProcess(interceptorParam); @@ -2222,7 +2226,7 @@ int AbilityManagerService::StartAbilityForOptionInner(const Want &want, const St } Want newWant = abilityRequest.want; - AbilityInterceptorParam afterCheckParam = AbilityInterceptorParam(newWant, requestCode, GetUserId(), + AbilityInterceptorParam afterCheckParam = AbilityInterceptorParam(newWant, requestCode, callerUserId, true, callerToken, std::make_shared(abilityInfo), isStartAsCaller, appIndex); result = afterCheckExecuter_ == nullptr ? ERR_NULL_AFTER_CHECK_EXECUTER : afterCheckExecuter_->DoProcess(afterCheckParam); @@ -2235,14 +2239,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, callerUserId, newWant); eventHelper_.SendStartAbilityErrorEvent(eventInfo, result, "HandleErmsResult failed"); return result; } if (result == ERR_OK && - DialogSessionManager::GetInstance().IsCreateCloneSelectorDialog(abilityInfo.bundleName, GetUserId())) { + DialogSessionManager::GetInstance().IsCreateCloneSelectorDialog(abilityInfo.bundleName, callerUserId)) { TAG_LOGI(AAFwkTag::ABILITYMGR, "create clone selector dialog"); - result = CreateCloneSelectorDialog(abilityRequest, GetUserId()); + result = CreateCloneSelectorDialog(abilityRequest, callerUserId); eventHelper_.SendStartAbilityErrorEvent(eventInfo, result, "CreateCloneSelectorDialog failed"); return result; } @@ -2490,7 +2494,8 @@ int32_t AbilityManagerService::StartUIAbilitiesInterceptorCheck(const Want &want Want newWant = abilityRequest.want; auto abilityInfo = abilityRequest.abilityInfo; auto shouldBlockFunc = [aams = shared_from_this()]() { return aams->ShouldBlockAllAppStart(); }; - AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(want, requestCode, GetUserId(), + auto callerUserId = AbilityRuntime::UserController::GetInstance().GetCallerUserId(); + AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(want, requestCode, callerUserId, true, nullptr, shouldBlockFunc); int32_t result = interceptorExecuter_ == nullptr ? ERR_NULL_INTERCEPTOR_EXECUTER : interceptorExecuter_->DoProcess(interceptorParam); @@ -2503,7 +2508,7 @@ int32_t AbilityManagerService::StartUIAbilitiesInterceptorCheck(const Want &want return START_UI_ABILITIES_INTERCEPTOR_CHECK_FAILED; } - AbilityInterceptorParam afterCheckParam = AbilityInterceptorParam(newWant, requestCode, GetUserId(), + AbilityInterceptorParam afterCheckParam = AbilityInterceptorParam(newWant, requestCode, callerUserId, true, callerToken, std::make_shared(abilityInfo), false, appIndex); result = afterCheckExecuter_ == nullptr ? ERR_NULL_AFTER_CHECK_EXECUTER : afterCheckExecuter_->DoProcess(afterCheckParam); @@ -2585,7 +2590,8 @@ 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(), + auto callerUserId = AbilityRuntime::UserController::GetInstance().GetCallerUserId(); + AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(want, requestCode, callerUserId, true, nullptr, shouldBlockFunc); auto result = interceptorExecuter_ == nullptr ? ERR_INVALID_VALUE : interceptorExecuter_->DoProcess(interceptorParam); @@ -2633,7 +2639,7 @@ int32_t AbilityManagerService::RequestDialogServiceInner(const Want &want, const } AbilityInterceptorParam afterCheckParam = AbilityInterceptorParam(abilityRequest.want, requestCode, - GetUserId(), true, callerToken, std::make_shared(abilityInfo)); + callerUserId, true, callerToken, std::make_shared(abilityInfo)); result = afterCheckExecuter_ == nullptr ? ERR_INVALID_VALUE : afterCheckExecuter_->DoProcess(afterCheckParam); if (result != ERR_OK) { @@ -2861,7 +2867,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, + auto callerUserId = AbilityRuntime::UserController::GetInstance().GetCallerUserId(); + AbilityInterceptorParam afterCheckParam = AbilityInterceptorParam(newWant, requestCode, callerUserId, true, sessionInfo->callerToken, std::make_shared(abilityInfo), false, appIndex); result = afterCheckExecuter_ == nullptr ? ERR_INVALID_VALUE : afterCheckExecuter_->DoProcess(afterCheckParam); @@ -2965,7 +2972,8 @@ 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()) { + auto callerUserId = AbilityRuntime::UserController::GetInstance().GetCallerUserId(); + if (userId != U0_USER_ID && userId != U1_USER_ID && userId != callerUserId) { TAG_LOGI(AAFwkTag::ABILITYMGR, "not current user"); return; } @@ -3617,7 +3625,8 @@ 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, + auto callerUserId = AbilityRuntime::UserController::GetInstance().GetCallerUserId(); + AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(want, 0, callerUserId, false, nullptr, shouldBlockFunc); result = interceptorExecuter_ == nullptr ? ERR_INVALID_VALUE : interceptorExecuter_->DoProcess(interceptorParam); @@ -3706,7 +3715,7 @@ int32_t AbilityManagerService::StartExtensionAbilityInner(const Want &want, cons return result; } - AbilityInterceptorParam afterCheckParam = AbilityInterceptorParam(abilityRequest.want, 0, GetUserId(), + AbilityInterceptorParam afterCheckParam = AbilityInterceptorParam(abilityRequest.want, 0, callerUserId, false, callerToken, std::make_shared(abilityInfo), false, appIndex); result = afterCheckExecuter_ == nullptr ? ERR_INVALID_VALUE : afterCheckExecuter_->DoProcess(afterCheckParam); @@ -3971,7 +3980,8 @@ int AbilityManagerService::StartUIExtensionAbility(const sptr &exte StartAbilityInfoWrap threadLocalInfo; auto shouldBlockFunc = [aams = shared_from_this()]() { return aams->ShouldBlockAllAppStart(); }; - AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(extensionSessionInfo->want, 0, GetUserId(), + auto callerUserId = AbilityRuntime::UserController::GetInstance().GetCallerUserId(); + AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(extensionSessionInfo->want, 0, callerUserId, true, nullptr, shouldBlockFunc); auto result = interceptorExecuter_ == nullptr ? ERR_INVALID_VALUE : interceptorExecuter_->DoProcess(interceptorParam); @@ -4042,7 +4052,7 @@ int AbilityManagerService::StartUIExtensionAbility(const sptr &exte return result; } - AbilityInterceptorParam afterCheckParam = AbilityInterceptorParam(abilityRequest.want, 0, GetUserId(), + AbilityInterceptorParam afterCheckParam = AbilityInterceptorParam(abilityRequest.want, 0, callerUserId, true, callerToken, std::make_shared(abilityInfo)); result = afterCheckExecuter_ == nullptr ? ERR_INVALID_VALUE : afterCheckExecuter_->DoProcess(afterCheckParam); @@ -4168,7 +4178,7 @@ void AbilityManagerService::StopSwitchUserDialog() return; } - if (userController_ == nullptr || userController_->GetFreezingNewUserId() == DEFAULT_INVAL_VALUE) { + if (AbilityRuntime::UserController::GetInstance().GetFreezingNewUserId() == DEFAULT_INVAL_VALUE) { TAG_LOGE(AAFwkTag::ABILITYMGR, "get last userId error"); return; } @@ -4179,9 +4189,9 @@ void AbilityManagerService::StopSwitchUserDialog() return; } Want stopWant = sysDialog->GetSwitchUserDialogWant(); - StopSwitchUserDialogInner(stopWant, userController_->GetFreezingNewUserId()); + StopSwitchUserDialogInner(stopWant, AbilityRuntime::UserController::GetInstance().GetFreezingNewUserId()); #endif // SUPPORT_GRAPHICS - userController_->SetFreezingNewUserId(DEFAULT_INVAL_VALUE); + AbilityRuntime::UserController::GetInstance().SetFreezingNewUserId(DEFAULT_INVAL_VALUE); return; } @@ -4894,7 +4904,8 @@ int32_t AbilityManagerService::ConnectAbilityCommon( #endif // WITH_DLP auto shouldBlockFunc = [aams = shared_from_this()]() { return aams->ShouldBlockAllAppStart(); }; - AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(want, 0, GetUserId(), false, nullptr, + auto callerUserId = AbilityRuntime::UserController::GetInstance().GetCallerUserId(); + AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(want, 0, callerUserId, false, nullptr, shouldBlockFunc); result = interceptorExecuter_ == nullptr ? ERR_INVALID_VALUE : interceptorExecuter_->DoProcess(interceptorParam); @@ -5049,7 +5060,8 @@ 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, + auto callerUserId = AbilityRuntime::UserController::GetInstance().GetCallerUserId(); + AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(want, 0, callerUserId, false, nullptr, shouldBlockFunc); result = interceptorExecuter_ == nullptr ? ERR_INVALID_VALUE : interceptorExecuter_->DoProcess(interceptorParam); @@ -5262,7 +5274,8 @@ int32_t AbilityManagerService::ConnectLocalAbility(const Want &want, const int32 return result; } - AbilityInterceptorParam afterCheckParam = AbilityInterceptorParam(abilityRequest.want, 0, GetUserId(), + auto callerUserId = AbilityRuntime::UserController::GetInstance().GetCallerUserId(); + AbilityInterceptorParam afterCheckParam = AbilityInterceptorParam(abilityRequest.want, 0, callerUserId, false, callerToken, std::make_shared(abilityInfo)); result = afterCheckExecuter_ == nullptr ? ERR_INVALID_VALUE : afterCheckExecuter_->DoProcess(afterCheckParam); @@ -5354,7 +5367,7 @@ int AbilityManagerService::DisconnectLocalAbility(const sptr } // EnterpriseAdminExtensionAbility Scene - connectManager = GetConnectManagerByUserId(USER_ID_DEFAULT); + connectManager = GetConnectManagerByUserId(MAIN_USER_ID); CHECK_POINTER_AND_RETURN(connectManager, ERR_NO_INIT); return connectManager->DisconnectAbilityLocked(connect); } @@ -6426,7 +6439,7 @@ void AbilityManagerService::DumpSysMissionListInnerBySCB( const std::string &args, std::vector &info, bool isClient, bool isUserID, int userId) { if (!isUserID) { - userId = GetUserId(); + userId = AbilityRuntime::UserController::GetInstance().GetCallerUserId(); } std::vector argList; @@ -6491,7 +6504,7 @@ void AbilityManagerService::DumpSysAbilityInnerBySCB( const std::string &args, std::vector &info, bool isClient, bool isUserID, int userId) { if (!isUserID) { - userId = GetUserId(); + userId = AbilityRuntime::UserController::GetInstance().GetCallerUserId(); } std::vector argList; @@ -7222,18 +7235,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(); @@ -7290,6 +7294,7 @@ int AbilityManagerService::StartHighestPriorityAbility(int32_t userId, bool isBo #ifdef SUPPORT_GRAPHICS abilityWant.SetParam(NEED_STARTINGWINDOW, false); + abilityWant.SetParam(Want::PARAM_RESV_DISPLAY_ID, static_cast(displayId)); // wait BOOT_ANIMATION_STARTED to start LAUNCHER WaitBootAnimationStart(); #endif @@ -7554,14 +7559,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"); @@ -7626,7 +7631,7 @@ int AbilityManagerService::KillProcess(const std::string &bundleName, bool clear auto bms = AbilityUtil::GetBundleManagerHelper(); CHECK_POINTER_AND_RETURN(bms, KILL_PROCESS_FAILED); - int32_t userId = GetUserId(); + int32_t userId = AbilityRuntime::UserController::GetInstance().GetCallerUserId(); AppExecFwk::BundleInfo bundleInfo; if (IN_PROCESS_CALL(bms->GetCloneBundleInfoExt(bundleName, static_cast(AppExecFwk::GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_APPLICATION), @@ -8176,8 +8181,9 @@ void AbilityManagerService::StartAutoStartupApps() return; } std::vector infoList; + auto callerUserId = AbilityRuntime::UserController::GetInstance().GetCallerUserId(); int32_t result = abilityAutoStartupService_->QueryAllAutoStartupApplicationsWithoutPermission(infoList, - GetUserId()); + callerUserId); if (result != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITYMGR, "failed query data"); return; @@ -8562,8 +8568,9 @@ int AbilityManagerService::StartAbilityByCallWithErrMsg(const Want &want, const errMsg = "app index is error"; return ERR_APP_CLONE_INDEX_INVALID; } + auto callerUserId = AbilityRuntime::UserController::GetInstance().GetCallerUserId(); auto checkRet = AbilityPermissionUtil::GetInstance().CheckMultiInstanceAndAppClone(const_cast(want), - GetUserId(), appIndex, callerToken, false); + callerUserId, appIndex, callerToken, false); if (checkRet != ERR_OK) { return checkRet; } @@ -8572,10 +8579,10 @@ int AbilityManagerService::StartAbilityByCallWithErrMsg(const Want &want, const DmsUtil::GetInstance().UpdateFlagForCollaboration(want); #endif - StartAbilityInfoWrap threadLocalInfo(want, GetUserId(), appIndex, callerToken); + StartAbilityInfoWrap threadLocalInfo(want, callerUserId, appIndex, callerToken); auto shouldBlockFunc = [aams = shared_from_this()]() { return aams->ShouldBlockAllAppStart(); }; isSilent = want.GetBoolParam(Want::PARAM_RESV_CALL_TO_FOREGROUND, false) ? true : !isSilent; - AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(want, 0, GetUserId(), isSilent, nullptr, + AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(want, 0, callerUserId, isSilent, nullptr, shouldBlockFunc); auto result = interceptorExecuter_ == nullptr ? ERR_INVALID_VALUE : interceptorExecuter_->DoProcess(interceptorParam); @@ -8604,7 +8611,7 @@ int AbilityManagerService::StartAbilityByCallWithErrMsg(const Want &want, const abilityRequest.callerToken = callerToken; abilityRequest.want = want; abilityRequest.connect = connect; - result = GenerateAbilityRequest(want, -1, abilityRequest, callerToken, GetUserId()); + result = GenerateAbilityRequest(want, -1, abilityRequest, callerToken, callerUserId); if (result != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITYMGR, "generate ability request error"); return result; @@ -8628,7 +8635,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, callerUserId, false, callerToken, std::make_shared(abilityRequest.abilityInfo), false, appIndex); result = afterCheckExecuter_ == nullptr ? ERR_INVALID_VALUE : afterCheckExecuter_->DoProcess(afterCheckParam); @@ -8729,17 +8736,29 @@ 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); + HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); if (callback == nullptr) { TAG_LOGE(AAFwkTag::ABILITYMGR, "startUser callback is nullptr"); return INVALID_PARAMETERS_ERR; } - if (IPCSkeleton::GetCallingUid() != ACCOUNT_MGR_SERVICE_UID) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "startUser permission verification failed, not account process"); - callback->OnStartUserDone(userId, CHECK_PERMISSION_FAILED); - return CHECK_PERMISSION_FAILED; + auto checkRet = AbilityRuntime::UserController::GetInstance().CheckUserParam(userId); + if (checkRet != ERR_OK) { + callback->OnStartUserDone(userId, checkRet); + return checkRet; + } + + if (userId == U1_USER_ID) { + UserStarted(userId); + callback->OnStartUserDone(userId, ERR_OK); + return ERR_OK; + } + if (AbilityRuntime::UserController::GetInstance().IsCurrentUser(userId, displayId)) { + TAG_LOGW(AAFwkTag::ABILITYMGR, "StartUser current:%{public}d", userId); + callback->OnStartUserDone(userId, ERR_OK); + return ERR_OK; } if (ShouldBlockAllAppStart() && callback != nullptr) { @@ -8748,32 +8767,67 @@ int AbilityManagerService::StartUser(int userId, sptr callback, b return ERR_ALL_APP_START_BLOCKED; } - if (userController_) { - return userController_->StartUser(userId, callback, isAppRecovery); + AbilityRuntime::UserController::GetInstance().SetEnableStartProcessFlagByUserId(userId, true); + auto oldUserId = AbilityRuntime::UserController::GetInstance().GetCurrentUserId(displayId); + if (oldUserId != U0_USER_ID && !Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { + // start freezing screen + AbilityRuntime::UserController::GetInstance().SetFreezingNewUserId(userId); + StartFreezingScreen(); + auto stopFreezingScreenTask = [weak = weak_from_this()]() { + auto abilityMgr = weak.lock(); + if (abilityMgr == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "ability manager instance null"); + return; + } + abilityMgr->StopFreezingScreen(); + }; + if (taskHandler_) { + taskHandler_->SubmitTask(stopFreezingScreenTask, "StopFreezingScreen", USER_SWITCH_TIMEOUT); + } } - return 0; + + AbilityRuntime::UserController::GetInstance().SetCurrentUserId(userId, displayId); + return SwitchToUser(oldUserId, userId, displayId, callback, isAppRecovery); } int AbilityManagerService::StopUser(int userId, const sptr &callback) { XCOLLIE_TIMER_LESS(__PRETTY_FUNCTION__); TAG_LOGI(AAFwkTag::ABILITYMGR, "stopUser in service:%{public}d", userId); - if (IPCSkeleton::GetCallingUid() != ACCOUNT_MGR_SERVICE_UID) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "stopUser permission verification failed, not account process"); - if (callback != nullptr) { - callback->OnStopUserDone(userId, CHECK_PERMISSION_FAILED); - } - return CHECK_PERMISSION_FAILED; + HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); + if (callback == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "stopUser callback is nullptr"); + return INVALID_PARAMETERS_ERR; } - - auto ret = -1; - if (userController_) { - ret = userController_->StopUser(userId); - TAG_LOGD(AAFwkTag::ABILITYMGR, "ret = %{public}d", ret); + auto checkRet = AbilityRuntime::UserController::GetInstance().CheckStopUserParam(userId); + if (checkRet != ERR_OK) { + callback->OnStopUserDone(userId, checkRet); + return checkRet; } - if (callback) { - callback->OnStopUserDone(userId, ret); + if (AbilityRuntime::UserController::GetInstance().IsCurrentUser(userId)) { + TAG_LOGW(AAFwkTag::ABILITYMGR, "user current:%{public}d", userId); + callback->OnStopUserDone(userId, ERR_OK); + return ERR_OK; + } + DelayedSingleton::GetInstance()->KillProcessesByUserId(userId); + + if (!Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { + auto missionListWrap = GetMissionListWrap(); + if (!missionListWrap) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "missionListWrap null"); + callback->OnStopUserDone(userId, -1); + return -1; + } + missionListWrap->RemoveUserDir(userId); } + ClearUserData(userId); + callback->OnStopUserDone(userId, ERR_OK); + UpdateApplicationKeepAlive(userId); + return ERR_OK; +} + +int32_t AbilityManagerService::UpdateApplicationKeepAlive(int32_t userId) const +{ if (!system::GetBoolParameter(PRODUCT_ENTERPRISE_FEATURE_SETTING_ENABLED, false)) { return 0; } @@ -8791,19 +8845,22 @@ int AbilityManagerService::StopUser(int userId, const sptr &callb bundleInfo.name, false, true, false)); } } - return 0; + return ERR_OK; } int AbilityManagerService::LogoutUser(int32_t userId, sptr callback) { XCOLLIE_TIMER_LESS(__PRETTY_FUNCTION__); TAG_LOGI(AAFwkTag::ABILITYMGR, "LogoutUser in service:%{public}d", userId); - if (IPCSkeleton::GetCallingUid() != ACCOUNT_MGR_SERVICE_UID) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "permission verification failed, not account process"); - if (callback != nullptr) { - callback->OnLogoutUserDone(userId, CHECK_PERMISSION_FAILED); - } - return CHECK_PERMISSION_FAILED; + HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); + if (callback == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "logoutUser callback is nullptr"); + return INVALID_PARAMETERS_ERR; + } + auto checkRet = AbilityRuntime::UserController::GetInstance().CheckUserParam(userId); + if (checkRet != ERR_OK) { + callback->OnLogoutUserDone(userId, checkRet); + return checkRet; } // Lister screen unlock for auto startup apps. @@ -8812,11 +8869,11 @@ 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; - } + RemoveLauncherDeathRecipient(userId); + ClearUserData(userId); + AbilityRuntime::UserController::GetInstance().SetEnableStartProcessFlagByUserId(userId, false); + DelayedSingleton::GetInstance()->KillProcessesByUserId(userId, + system::GetBoolParameter(DEVELOPER_MODE_STATE, false), callback); return ERR_OK; } @@ -8960,7 +9017,8 @@ 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); + auto callerUserId = AbilityRuntime::UserController::GetInstance().GetCallerUserId(); + connectManager->GetExtensionRunningInfos(upperLimit, info, callerUserId, isPerm); return ERR_OK; } @@ -9278,7 +9336,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 = AbilityRuntime::UserController::GetInstance().GetCallerUserId(); bool ret = IN_PROCESS_CALL( bms->GetBundleInfo(bundleName, AppExecFwk::BundleFlag::GET_BUNDLE_WITH_ABILITIES, bundleInfo, userId)); @@ -9336,10 +9394,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) { @@ -9348,7 +9402,7 @@ void AbilityManagerService::StartSwitchUserDialog() } Want dialogWant = sysDialog->GetSwitchUserDialogWant(); - StartSwitchUserDialogInner(dialogWant, userController_->GetFreezingNewUserId()); + StartSwitchUserDialogInner(dialogWant, AbilityRuntime::UserController::GetInstance().GetFreezingNewUserId()); #endif // SUPPORT_GRAPHICS } @@ -9424,8 +9478,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__, @@ -9438,7 +9492,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); } @@ -9466,9 +9520,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"); @@ -9544,20 +9595,10 @@ void AbilityManagerService::StartUserApps() } } -int32_t AbilityManagerService::GetValidUserId(const int32_t userId) +int32_t AbilityManagerService::GetValidUserId(int32_t userId) { TAG_LOGD(AAFwkTag::ABILITYMGR, "userId = %{public}d.", userId); - int32_t validUserId = userId; - - if (DEFAULT_INVAL_VALUE == userId) { - validUserId = IPCSkeleton::GetCallingUid() / BASE_USER_RANGE; - TAG_LOGD(AAFwkTag::ABILITYMGR, "validUserId = %{public}d, CallingUid = %{public}d.", validUserId, - IPCSkeleton::GetCallingUid()); - if (validUserId == U0_USER_ID || validUserId == U1_USER_ID) { - validUserId = GetUserId(); - } - } - return validUserId; + return DEFAULT_INVAL_VALUE == userId ? AbilityRuntime::UserController::GetInstance().GetCallerUserId() : userId; } int AbilityManagerService::SetAbilityController(const sptr &abilityController, @@ -9651,10 +9692,10 @@ 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(); 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))) { @@ -9669,7 +9710,7 @@ int AbilityManagerService::StartUserTest(const Want &want, const sptr::GetInstance()->StartUserTest(want, observer, bundleInfo, GetUserId()); + return DelayedSingleton::GetInstance()->StartUserTest(want, observer, bundleInfo, userId); } int AbilityManagerService::FinishUserTest( @@ -9827,7 +9868,7 @@ int AbilityManagerService::DelegatorMoveMissionToFront(int32_t missionId) return missionListManager->MoveMissionToFront(missionId); } -bool AbilityManagerService::JudgeMultiUserConcurrency(const int32_t userId) +bool AbilityManagerService::JudgeMultiUserConcurrency(int32_t userId) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); if (userId == U0_USER_ID || userId == U1_USER_ID) { @@ -9835,15 +9876,12 @@ 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()); + int32_t callerUserId = AbilityRuntime::UserController::GetInstance().GetCallerUserId(); + TAG_LOGD(AAFwkTag::ABILITYMGR, "userId : %{public}d, current userId : %{public}d", userId, callerUserId); + if (userId == callerUserId) { + return true; } - - return true; + return AAFwk::PermissionVerification::GetInstance()->VerifyAccountPermission() == ERR_OK; } void AbilityManagerService::SendExtensionReport(EventInfo &eventInfo, int32_t errCode, bool isService) @@ -10122,7 +10160,8 @@ void AbilityManagerService::GetAbilityRunningInfo(std::vectorGetCurrentUserId() == userId))) { + int32_t callerUserId = AbilityRuntime::UserController::GetInstance().GetCallerUserId(); + if (userId < 0 || callerUserId == userId) { return ERR_OK; } return AAFwk::PermissionVerification::GetInstance()->VerifyAccountPermission(); @@ -11596,7 +11635,7 @@ int AbilityManagerService::VerifyPermission(const std::string &permission, int p return CHECK_PERMISSION_FAILED; } - int32_t userId = GetUserId(); + int32_t userId = AbilityRuntime::UserController::GetInstance().GetCallerUserId(); AppExecFwk::BundleInfo bundleInfo; bool queryBundleInfoRet = IN_PROCESS_CALL( bms->GetBundleInfo(callerBundleName, AppExecFwk::BundleFlag::GET_BUNDLE_WITH_ABILITIES, bundleInfo, userId)); @@ -11762,14 +11801,15 @@ int32_t AbilityManagerService::StartSpecifiedAbilityBySCB(const Want &want) TAG_LOGE(AAFwkTag::ABILITYMGR, "invalid app clone index"); return ERR_APP_CLONE_INDEX_INVALID; } + int32_t callerUserId = AbilityRuntime::UserController::GetInstance().GetCallerUserId(); auto result = AbilityPermissionUtil::GetInstance().CheckMultiInstanceAndAppClone(const_cast(want), - GetUserId(), appIndex, nullptr, true); + callerUserId, appIndex, nullptr, true); if (result != ERR_OK) { return result; } AbilityRequest abilityRequest; - result = GenerateAbilityRequest(want, -1, abilityRequest, want.GetRemoteObject(TOKEN_KEY), GetUserId()); + result = GenerateAbilityRequest(want, -1, abilityRequest, want.GetRemoteObject(TOKEN_KEY), callerUserId); if (result != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITYMGR, "generate ability request error"); return result; @@ -12038,7 +12078,8 @@ int32_t AbilityManagerService::QueryAllAutoStartupApplications(std::vectorQueryAllAutoStartupApplications(infoList, GetUserId()); + int32_t callerUserId = AbilityRuntime::UserController::GetInstance().GetCallerUserId(); + return abilityAutoStartupService_->QueryAllAutoStartupApplications(infoList, callerUserId); } int AbilityManagerService::PrepareTerminateAbilityBySCB(const sptr &sessionInfo, bool &isTerminate) @@ -12221,7 +12262,8 @@ 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)) { + int32_t callerUserId = AbilityRuntime::UserController::GetInstance().GetCallerUserId(); + if (!StartAbilityUtils::GetApplicationInfo(abilityData.bundleName, callerUserId, appInfo)) { TAG_LOGE(AAFwkTag::ABILITYMGR, "can't get applicationInfo through bundleName"); } else if (appInfo.bundleType == AppExecFwk::BundleType::ATOMIC_SERVICE) { abilityData.isAtomicService = true; @@ -12493,19 +12537,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 = AbilityRuntime::UserController::GetInstance().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); } } @@ -12519,9 +12559,9 @@ void AbilityManagerService::NotifyStartResidentProcess(std::vectorStartResidentProcessWithMainElement( - bundleInfosForCurrentUser, currentUser); - if (!bundleInfosForCurrentUser.empty()) { - residentProcessMgr->StartResidentProcess(bundleInfosForCurrentUser); + bundleInfosForcallerUser, callerUser); + if (!bundleInfosForcallerUser.empty()) { + residentProcessMgr->StartResidentProcess(bundleInfosForcallerUser); } } @@ -12531,7 +12571,7 @@ void AbilityManagerService::NotifyStartKeepAliveProcess(std::vector bundleInfosForCurrentUser; std::vector bundleInfosForU1; for (const auto &item: bundleInfos) { @@ -12736,7 +12776,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 = AbilityRuntime::UserController::GetInstance().GetCallerUserId(); std::string callerAppIdentifier = abilityRequest.want.GetStringParam(Want::PARAM_RESV_CALLER_APP_IDENTIFIER); if (callerAppIdentifier.empty()) { AppExecFwk::SignatureInfo signatureInfo; @@ -12774,7 +12814,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 = AbilityRuntime::UserController::GetInstance().GetCallerUserId(); auto connectManager = GetConnectManagerByUserId(validUserId); if (connectManager == nullptr) { TAG_LOGE(AAFwkTag::ABILITYMGR, "manager null, userId: %{public}d", validUserId); @@ -13179,14 +13219,15 @@ 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 callerUserId = AbilityRuntime::UserController::GetInstance().GetCallerUserId(); + int32_t ret = freeInstallManager_->StartFreeInstall(want, callerUserId, 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, callerUserId); } int32_t AbilityManagerService::AddQueryERMSObserver(sptr callerToken, @@ -13222,7 +13263,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 = AbilityRuntime::UserController::GetInstance().GetCallerUserId(); int32_t ret = freeInstallManager_->StartFreeInstall(want, userId, 0, callerToken); if (ret != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITYMGR, "free install failed:%{public}d", ret); @@ -13234,7 +13275,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, userId, rule, replaceWant); if (ret == ERR_OK) { TAG_LOGI(AAFwkTag::ABILITYMGR, "QueryAtomicServiceStartupRule succeeded"); return ERR_OK; @@ -13819,7 +13860,8 @@ 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(), + auto callerUserId = AbilityRuntime::UserController::GetInstance().GetCallerUserId(); + AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(want, requestCode, callerUserId, true, nullptr, shouldBlockFunc); auto result = interceptorExecuter_ == nullptr ? ERR_INVALID_VALUE : interceptorExecuter_->DoProcess(interceptorParam); @@ -13875,7 +13917,7 @@ int AbilityManagerService::StartUIAbilityByPreInstallInner(sptr ses } Want newWant = abilityRequest.want; - AbilityInterceptorParam afterCheckParam = AbilityInterceptorParam(newWant, requestCode, GetUserId(), + AbilityInterceptorParam afterCheckParam = AbilityInterceptorParam(newWant, requestCode, callerUserId, true, callerToken, std::make_shared(abilityInfo), isStartAsCaller, appIndex); result = afterCheckExecuter_ == nullptr ? ERR_INVALID_VALUE : afterCheckExecuter_->DoProcess(afterCheckParam); @@ -13887,12 +13929,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, callerUserId, newWant); } if (result == ERR_OK && - DialogSessionManager::GetInstance().IsCreateCloneSelectorDialog(abilityInfo.bundleName, GetUserId())) { + DialogSessionManager::GetInstance().IsCreateCloneSelectorDialog(abilityInfo.bundleName, callerUserId)) { TAG_LOGI(AAFwkTag::ABILITYMGR, "create clone selector dialog"); - return CreateCloneSelectorDialog(abilityRequest, GetUserId()); + return CreateCloneSelectorDialog(abilityRequest, callerUserId); } #endif // SUPPORT_SCREEN @@ -14441,8 +14483,9 @@ int AbilityManagerService::StartSelfUIAbilityInner(StartSelfUIAbilityParam param CHECK_POINTER_AND_RETURN(bundleMgrHelper, INNER_ERR); AppExecFwk::AbilityInfo abilityInfo; + auto callerUserId = AbilityRuntime::UserController::GetInstance().GetCallerUserId(); 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, callerUserId, abilityInfo)), TARGET_BUNDLE_NOT_EXIST, "bundle or ability not exist"); CHECK_TRUE_RETURN_RET(abilityInfo.type != AppExecFwk::AbilityType::PAGE, @@ -14836,7 +14879,8 @@ 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(); + auto callerUserId = AbilityRuntime::UserController::GetInstance().GetCallerUserId(); + return userId != INVALID_USER_ID && userId != U0_USER_ID && userId != U1_USER_ID && userId != callerUserId; } int32_t AbilityManagerService::RestartSelfAtomicService(sptr callerToken) @@ -14965,7 +15009,8 @@ bool AbilityManagerService::HandleExecuteSAInterceptor(const Want &want, sptr callback = nullptr; if (data.ReadBool()) { callback = iface_cast(data.ReadRemoteObject()); @@ -2551,7 +2552,7 @@ int AbilityManagerStub::StartUserInner(MessageParcel &data, MessageParcel &reply return ERR_INVALID_VALUE; } bool isAppRecovery = data.ReadBool(); - int result = StartUser(userId, callback, isAppRecovery); + int result = StartUser(userId, displayId, callback, isAppRecovery); if (!reply.WriteInt32(result)) { TAG_LOGE(AAFwkTag::ABILITYMGR, "startUser fail"); return ERR_INVALID_VALUE; diff --git a/services/abilitymgr/src/app_scheduler.cpp b/services/abilitymgr/src/app_scheduler.cpp index ac38cf0ac84b429fb3593de814035bf6cd69a182..80bd976712ff7e87ea30607d2ddd0d0ef604e269 100644 --- a/services/abilitymgr/src/app_scheduler.cpp +++ b/services/abilitymgr/src/app_scheduler.cpp @@ -564,18 +564,6 @@ int32_t AppScheduler::GetBundleNameByPid(const int pid, std::string &bundleName, return ERR_OK; } -void AppScheduler::SetCurrentUserId(const int32_t userId) -{ - CHECK_POINTER(appMgrClient_); - IN_PROCESS_CALL_WITHOUT_RET(appMgrClient_->SetCurrentUserId(userId)); -} - -void AppScheduler::SetEnableStartProcessFlagByUserId(int32_t userId, bool enableStartProcess) -{ - CHECK_POINTER(appMgrClient_); - IN_PROCESS_CALL_WITHOUT_RET(appMgrClient_->SetEnableStartProcessFlagByUserId(userId, enableStartProcess)); -} - int32_t AppScheduler::NotifyFault(const AppExecFwk::FaultData &faultData) { CHECK_POINTER_AND_RETURN(appMgrClient_, INNER_ERR); diff --git a/services/abilitymgr/src/data_ability/data_ability_manager.cpp b/services/abilitymgr/src/data_ability/data_ability_manager.cpp index fe0a4abfa9895f4ea8dddd188eb3599b62d997c3..101470fdcfab9d575bc1ea8aaaa26f71af590a7d 100644 --- a/services/abilitymgr/src/data_ability/data_ability_manager.cpp +++ b/services/abilitymgr/src/data_ability/data_ability_manager.cpp @@ -28,6 +28,7 @@ using namespace std::placeholders; namespace { constexpr bool DEBUG_ENABLED = false; constexpr system_clock::duration DATA_ABILITY_LOAD_TIMEOUT = 11000ms; +constexpr int32_t USER_ID_NO_HEAD = 0; } // namespace DataAbilityManager::DataAbilityManager() 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..84aa8ea2f0ef63b1255b6038d7d633395f220687 100644 --- a/services/abilitymgr/src/keep_alive/ability_keep_alive_service.cpp +++ b/services/abilitymgr/src/keep_alive/ability_keep_alive_service.cpp @@ -18,6 +18,7 @@ #include "ability_keep_alive_data_manager.h" #include "ability_manager_service.h" #include "hilog_tag_wrapper.h" +#include "user_controller/user_controller.h" namespace OHOS { namespace AbilityRuntime { @@ -104,14 +105,9 @@ void AbilityKeepAliveService::GetValidUserId(int32_t &userId) if (userId >= 0) { return; } - auto abilityMgr = DelayedSingleton::GetInstance(); - if (abilityMgr == nullptr) { - TAG_LOGE(AAFwkTag::KEEP_ALIVE, "null abilityMgr"); - return; - } if (userId < 0) { - userId = abilityMgr->GetUserId(); + userId = AbilityRuntime::UserController::GetInstance().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 f2bdcf339804b9aea777a9abe4e981ce3dda80e6..a45744b7556d83042b4faec567cae0f7d4ea8782 100644 --- a/services/abilitymgr/src/keep_alive/keep_alive_process_manager.cpp +++ b/services/abilitymgr/src/keep_alive/keep_alive_process_manager.cpp @@ -25,6 +25,7 @@ #include "parameters.h" #include "permission_constants.h" #include "process_options.h" +#include "user_controller/user_controller.h" namespace OHOS { namespace AAFwk { @@ -219,7 +220,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 ? AbilityRuntime::UserController::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..313923124b6716e9d33d37ed6218c22e3b190220 100644 --- a/services/abilitymgr/src/resident_process/resident_process_manager.cpp +++ b/services/abilitymgr/src/resident_process/resident_process_manager.cpp @@ -22,6 +22,7 @@ #include "ffrt.h" #include "keep_alive_utils.h" #include "main_element_utils.h" +#include "user_controller/user_controller.h" namespace OHOS { namespace AAFwk { @@ -211,8 +212,8 @@ void ResidentProcessManager::UpdateResidentProcessesStatus( } AppExecFwk::BundleInfo bundleInfo; - auto currentUser = DelayedSingleton::GetInstance()->GetUserId(); - std::set users{0, currentUser}; + auto callerUser = AbilityRuntime::UserController::GetInstance().GetCallerUserId(); + std::set users{0, callerUser}; for (const auto &userId: users) { if (!IN_PROCESS_CALL(bms->GetBundleInfo( diff --git a/services/abilitymgr/src/user_controller.cpp b/services/abilitymgr/src/user_controller.cpp deleted file mode 100644 index c1b8408e95a15321ee61d48523980a640566a780..0000000000000000000000000000000000000000 --- a/services/abilitymgr/src/user_controller.cpp +++ /dev/null @@ -1,570 +0,0 @@ -/* - * Copyright (c) 2021-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_controller.h" - -#include "ability_manager_service.h" -#include "hilog_tag_wrapper.h" -#include "mock_session_manager_service.h" -#include "os_account_manager_wrapper.h" -#include "scene_board_judgement.h" - -namespace OHOS { -namespace AAFwk { -using namespace OHOS::AppExecFwk; -namespace { -const int64_t USER_SWITCH_TIMEOUT = 3 * 1000; // 3s -constexpr const char* DEVELOPER_MODE_STATE = "const.security.developermode.state"; -} - -UserItem::UserItem(int32_t id) : userId_(id) -{} - -UserItem::~UserItem() {} - -int32_t UserItem::GetUserId() -{ - return userId_; -} - -void UserItem::SetState(const UserState &state) -{ - if (curState_ == state) { - return; - } - lastState_ = curState_; - curState_ = state; -} - -UserState UserItem::GetState() -{ - return curState_; -} - -UserController::UserController() -{ -} - -UserController::~UserController() -{ -} - -void UserController::Init() -{ - auto handler = DelayedSingleton::GetInstance()->GetTaskHandler(); - if (!handler) { - return; - } - - if (eventHandler_) { - return; - } - eventHandler_ = std::make_shared(handler, shared_from_this()); -} - -void UserController::ClearAbilityUserItems(int32_t userId) -{ - std::lock_guard guard(userLock_); - if (userItems_.count(userId)) { - userItems_.erase(userId); - } -} - -int UserController::StartUser(int32_t userId, sptr callback, bool isAppRecovery) -{ - if (userId == U1_USER_ID) { - return StartNoHeadUser(userId, callback); - } - - if (userId < 0 || userId == USER_ID_NO_HEAD) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "StartUserId invalid:%{public}d", userId); - if (callback != nullptr) { - callback->OnStartUserDone(userId, INVALID_USERID_VALUE); - } - return INVALID_USERID_VALUE; - } - - if (IsCurrentUser(userId)) { - TAG_LOGW(AAFwkTag::ABILITYMGR, "StartUser current:%{public}d", userId); - if (callback != nullptr) { - callback->OnStartUserDone(userId, ERR_OK); - } - return ERR_OK; - } - - auto appScheduler = DelayedSingleton::GetInstance(); - if (!appScheduler) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "null appScheduler"); - return ABILITY_SERVICE_NOT_CONNECTED; - } - appScheduler->SetEnableStartProcessFlagByUserId(userId, true); - - if (!IsExistOsAccount(userId)) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "null StartUser account:%{public}d", userId); - if (callback != nullptr) { - callback->OnStartUserDone(userId, INVALID_USERID_VALUE); - } - return INVALID_USERID_VALUE; - } - - if (GetCurrentUserId() != 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) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "StartUser user stop, userId:%{public}d", userId); - if (callback != nullptr) { - callback->OnStartUserDone(userId, ERR_DEAD_OBJECT); - } - return ERR_DEAD_OBJECT; - } - - SetCurrentUserId(userId); - if (state == STATE_BOOTING) { - // send user start msg. - SendSystemUserStart(userId); - } - - SendSystemUserCurrent(oldUserId, userId); - SendReportUserSwitch(oldUserId, userId, userItem); - SendUserSwitchTimeout(oldUserId, userId, userItem); - return MoveUserToForeground(oldUserId, userId, callback, isAppRecovery); -} - -int32_t UserController::StartNoHeadUser(int32_t userId, sptr callback) const -{ - if (!IsExistOsAccount(userId)) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "U1 not exist"); - callback->OnStartUserDone(userId, INVALID_USERID_VALUE); - return INVALID_USERID_VALUE; - } - - auto abilityManagerService = DelayedSingleton::GetInstance(); - if (!abilityManagerService) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "abilityManagerService is nullptr"); - callback->OnLogoutUserDone(userId, GET_ABILITY_SERVICE_FAILED); - return GET_ABILITY_SERVICE_FAILED; - } - abilityManagerService->UserStarted(userId); - callback->OnStartUserDone(userId, ERR_OK); - return ERR_OK; -} - -int32_t UserController::StopUser(int32_t userId) -{ - if (userId < 0 || userId == USER_ID_NO_HEAD || userId == USER_ID_DEFAULT) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "userId invalid:%{public}d", userId); - return -1; - } - - if (IsCurrentUser(userId)) { - TAG_LOGW(AAFwkTag::ABILITYMGR, "user current:%{public}d", userId); - return 0; - } - - if (!IsExistOsAccount(userId)) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "null account:%{public}d", userId); - return -1; - } - - BroadcastUserStopping(userId); - - auto appScheduler = DelayedSingleton::GetInstance(); - if (!appScheduler) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "null appScheduler"); - return -1; - } - appScheduler->KillProcessesByUserId(userId); - - auto abilityManagerService = DelayedSingleton::GetInstance(); - if (!abilityManagerService) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "abilityManagerService null"); - return -1; - } - - if (!Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { - auto missionListWrap = abilityManagerService->GetMissionListWrap(); - if (!missionListWrap) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "missionListWrap null"); - return -1; - } - missionListWrap->RemoveUserDir(userId); - } - - abilityManagerService->ClearUserData(userId); - - BroadcastUserStopped(userId); - return 0; -} - -int32_t UserController::LogoutUser(int32_t userId, sptr callback) -{ - if (userId < 0 || userId == USER_ID_NO_HEAD) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "userId invalid:%{public}d", userId); - if (callback) { - callback->OnLogoutUserDone(userId, INVALID_USERID_VALUE); - } - return INVALID_USERID_VALUE; - } - if (!IsExistOsAccount(userId)) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "null account:%{public}d", userId); - if (callback) { - callback->OnLogoutUserDone(userId, INVALID_USERID_VALUE); - } - return INVALID_USERID_VALUE; - } - auto abilityManagerService = DelayedSingleton::GetInstance(); - if (!abilityManagerService) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "null abilityManagerService"); - if (callback) { - callback->OnLogoutUserDone(userId, -1); - } - return -1; - } - abilityManagerService->RemoveLauncherDeathRecipient(userId); - if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { - TAG_LOGI(AAFwkTag::ABILITYMGR, "SceneBoard exit normally."); - Rosen::MockSessionManagerService::GetInstance().NotifyNotKillService(); - } - auto appScheduler = DelayedSingleton::GetInstance(); - if (!appScheduler) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "null appScheduler"); - if (callback) { - callback->OnLogoutUserDone(userId, INVALID_USERID_VALUE); - } - return INVALID_USERID_VALUE; - } - 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() -{ - std::lock_guard guard(userLock_); - return currentUserId_; -} - -std::shared_ptr UserController::GetUserItem(int32_t userId) -{ - std::lock_guard guard(userLock_); - auto it = userItems_.find(userId); - if (it != userItems_.end()) { - return it->second; - } - - return nullptr; -} - -bool UserController::IsCurrentUser(int32_t userId) -{ - int32_t oldUserId = GetCurrentUserId(); - if (oldUserId == userId) { - auto userItem = GetUserItem(userId); - if (userItem) { - TAG_LOGW(AAFwkTag::ABILITYMGR, "IsCurrentUserId current:%{public}d", userId); - return true; - } - } - return false; -} - -bool UserController::IsExistOsAccount(int32_t userId) const -{ - bool isExist = false; - auto errCode = DelayedSingleton::GetInstance()->IsOsAccountExists(userId, isExist); - return (errCode == 0) && isExist; -} - -std::shared_ptr UserController::GetOrCreateUserItem(int32_t userId) -{ - std::lock_guard guard(userLock_); - auto it = userItems_.find(userId); - if (it != userItems_.end()) { - return it->second; - } - - auto userItem = std::make_shared(userId); - userItems_.emplace(userId, userItem); - return userItem; -} - -void UserController::SetCurrentUserId(int32_t userId) -{ - std::lock_guard guard(userLock_); - currentUserId_ = userId; - TAG_LOGD(AAFwkTag::ABILITYMGR, "set current userId: %{public}d", userId); - DelayedSingleton::GetInstance()->SetCurrentUserId(userId); -} - -int UserController::MoveUserToForeground(int32_t oldUserId, int32_t newUserId, sptr callback, - bool isAppRecovery) -{ - auto manager = DelayedSingleton::GetInstance(); - if (!manager) { - return ABILITY_SERVICE_NOT_CONNECTED; - } - auto ret = manager->SwitchToUser(oldUserId, newUserId, callback, isAppRecovery); - if (ret != ERR_OK) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "SwitchToUser failed: %{public}d", ret); - } - BroadcastUserBackground(oldUserId); - BroadcastUserForeground(newUserId); - return ret; -} - -void UserController::UserBootDone(std::shared_ptr &item) -{ - if (!item) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "null item"); - return; - } - int32_t userId = item->GetUserId(); - - std::lock_guard guard(userLock_); - auto it = userItems_.find(userId); - if (it == userItems_.end()) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "invalid userId"); - return; - } - - if (item != it->second) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "invalid item"); - return; - } - item->SetState(UserState::STATE_STARTED); - auto manager = DelayedSingleton::GetInstance(); - if (!manager) { - return; - } - manager->UserStarted(userId); -} - -void UserController::BroadcastUserBackground(int32_t userId) -{ - TAG_LOGD(AAFwkTag::ABILITYMGR, "user background"); -} - -void UserController::BroadcastUserForeground(int32_t userId) -{ - TAG_LOGD(AAFwkTag::ABILITYMGR, "user foreground"); -} - -void UserController::BroadcastUserStopping(int32_t userId) -{ - TAG_LOGD(AAFwkTag::ABILITYMGR, "user stopping"); -} - -void UserController::BroadcastUserStopped(int32_t userId) -{ - TAG_LOGD(AAFwkTag::ABILITYMGR, "user stopped"); -} - -void UserController::SendSystemUserStart(int32_t userId) -{ - auto handler = eventHandler_; - if (!handler) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "null handler"); - return; - } - - auto eventData = std::make_shared(); - eventData->newUserId = userId; - handler->SendEvent(EventWrap(UserEventHandler::EVENT_SYSTEM_USER_START, eventData)); - TAG_LOGD(AAFwkTag::ABILITYMGR, "SendEvent(EVENT_SYSTEM_USER_START)"); -} - -void UserController::ProcessEvent(const EventWrap &event) -{ - auto eventId = event.GetEventId(); - auto eventData = static_cast(event.GetEventData().get()); - if (!eventData) { - TAG_LOGD(AAFwkTag::ABILITYMGR, "no event data, event id: %{public}u.", eventId); - return; - } - - TAG_LOGD(AAFwkTag::ABILITYMGR, "Event id obtained: %{public}u.", eventId); - switch (eventId) { - case UserEventHandler::EVENT_SYSTEM_USER_START: { - HandleSystemUserStart(eventData->newUserId); - break; - } - case UserEventHandler::EVENT_SYSTEM_USER_CURRENT: { - HandleSystemUserCurrent(eventData->oldUserId, eventData->newUserId); - break; - } - case UserEventHandler::EVENT_REPORT_USER_SWITCH: { - HandleReportUserSwitch(eventData->oldUserId, eventData->newUserId, eventData->userItem); - break; - } - case UserEventHandler::EVENT_CONTINUE_USER_SWITCH: { - HandleContinueUserSwitch(eventData->oldUserId, eventData->newUserId, eventData->userItem); - break; - } - case UserEventHandler::EVENT_USER_SWITCH_TIMEOUT: { - HandleUserSwitchTimeout(eventData->oldUserId, eventData->newUserId, eventData->userItem); - break; - } - case UserEventHandler::EVENT_REPORT_USER_SWITCH_DONE: { - HandleUserSwitchDone(eventData->newUserId); - break; - } - default: { - TAG_LOGW(AAFwkTag::ABILITYMGR, "Unsupported event."); - break; - } - } -} - -void UserController::SendSystemUserCurrent(int32_t oldUserId, int32_t newUserId) -{ - auto handler = eventHandler_; - if (!handler) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "null handler"); - return; - } - - auto eventData = std::make_shared(); - eventData->oldUserId = oldUserId; - eventData->newUserId = newUserId; - handler->SendEvent(EventWrap(UserEventHandler::EVENT_SYSTEM_USER_CURRENT, eventData)); - TAG_LOGD(AAFwkTag::ABILITYMGR, "SendEvent(EVENT_SYSTEM_USER_CURRENT)"); -} - -void UserController::SendReportUserSwitch(int32_t oldUserId, int32_t newUserId, - std::shared_ptr &usrItem) -{ - auto handler = eventHandler_; - if (!handler) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "null handler"); - return; - } - - auto eventData = std::make_shared(); - eventData->oldUserId = oldUserId; - eventData->newUserId = newUserId; - eventData->userItem = usrItem; - handler->SendEvent(EventWrap(UserEventHandler::EVENT_REPORT_USER_SWITCH, eventData)); - TAG_LOGD(AAFwkTag::ABILITYMGR, "SendEvent(EVENT_REPORT_USER_SWITCH)"); -} - -void UserController::SendUserSwitchTimeout(int32_t oldUserId, int32_t newUserId, - std::shared_ptr &usrItem) -{ - auto handler = eventHandler_; - if (!handler) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "null handler"); - return; - } - - auto eventData = std::make_shared(); - eventData->oldUserId = oldUserId; - eventData->newUserId = newUserId; - eventData->userItem = usrItem; - handler->SendEvent(EventWrap(UserEventHandler::EVENT_USER_SWITCH_TIMEOUT, - eventData), USER_SWITCH_TIMEOUT); - TAG_LOGD(AAFwkTag::ABILITYMGR, "SendEvent(EVENT_USER_SWITCH_TIMEOUT)"); -} - -void UserController::SendContinueUserSwitch(int32_t oldUserId, int32_t newUserId, - std::shared_ptr &usrItem) -{ - auto handler = eventHandler_; - if (!handler) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "null handler"); - return; - } - - auto eventData = std::make_shared(); - eventData->oldUserId = oldUserId; - eventData->newUserId = newUserId; - eventData->userItem = usrItem; - handler->SendEvent(EventWrap(UserEventHandler::EVENT_CONTINUE_USER_SWITCH, eventData)); - TAG_LOGD(AAFwkTag::ABILITYMGR, "SendEvent(EVENT_CONTINUE_USER_SWITCH)"); -} - -void UserController::SendUserSwitchDone(int32_t userId) -{ - auto handler = eventHandler_; - if (!handler) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "null handler"); - return; - } - - auto eventData = std::make_shared(); - eventData->newUserId = userId; - handler->SendEvent(EventWrap(UserEventHandler::EVENT_REPORT_USER_SWITCH_DONE, - eventData)); - TAG_LOGD(AAFwkTag::ABILITYMGR, "SendEvent(EVENT_REPORT_USER_SWITCH_DONE)"); -} - -void UserController::HandleSystemUserStart(int32_t userId) -{ - TAG_LOGD(AAFwkTag::ABILITYMGR, "notify system user start."); -} - -void UserController::HandleSystemUserCurrent(int32_t oldUserId, int32_t newUserId) -{ - TAG_LOGD(AAFwkTag::ABILITYMGR, "notify system user current."); -} - -void UserController::HandleReportUserSwitch(int32_t oldUserId, int32_t newUserId, - std::shared_ptr &usrItem) -{ - TAG_LOGD(AAFwkTag::ABILITYMGR, "notify report user switch."); -} - -void UserController::HandleUserSwitchTimeout(int32_t oldUserId, int32_t newUserId, - std::shared_ptr &usrItem) -{ - SendContinueUserSwitch(oldUserId, newUserId, usrItem); -} - -void UserController::HandleContinueUserSwitch(int32_t oldUserId, int32_t newUserId, - std::shared_ptr &usrItem) -{ - auto manager = DelayedSingleton::GetInstance(); - if (manager && !Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { - manager->StopFreezingScreen(); - } - SendUserSwitchDone(newUserId); -} - -void UserController::HandleUserSwitchDone(int32_t userId) -{ - TAG_LOGD(AAFwkTag::ABILITYMGR, "handle user switch done."); -} - -int32_t UserController::GetFreezingNewUserId() const -{ - return freezingNewUserId_; -} - -void UserController::SetFreezingNewUserId(int32_t userId) -{ - freezingNewUserId_ = userId; -} -} -} diff --git a/services/appmgr/BUILD.gn b/services/appmgr/BUILD.gn index b9d6640df6bd381647646dd476c29e9e337b77c4..f909ca2f9a75d836ad737732f43e8be6eb79ddec 100644 --- a/services/appmgr/BUILD.gn +++ b/services/appmgr/BUILD.gn @@ -72,7 +72,6 @@ ohos_shared_library("libappms") { "src/remote_client_manager.cpp", "src/render_record.cpp", "src/render_state_observer_manager.cpp", - "src/user_record_manager.cpp", "src/window_focus_changed_listener.cpp", "src/window_pid_visibility_changed_listener.cpp", "src/window_visibility_changed_listener.cpp", @@ -117,6 +116,7 @@ ohos_shared_library("libappms") { "${ability_runtime_services_path}/common:record_cost_time_util", "${ability_runtime_services_path}/common:res_sched_util", "${ability_runtime_services_path}/common:task_handler_wrap", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ @@ -177,6 +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/ams_mgr_scheduler.h b/services/appmgr/include/ams_mgr_scheduler.h index 5daa110dacf8b90e4138fc6e1b812bb97a02f93e..7a025cf9e17ac2e894cdb1eeccde16895148fcd7 100644 --- a/services/appmgr/include/ams_mgr_scheduler.h +++ b/services/appmgr/include/ams_mgr_scheduler.h @@ -293,15 +293,6 @@ public: virtual void StartSpecifiedProcess(const AAFwk::Want &want, const AppExecFwk::AbilityInfo &abilityInfo, int32_t requestId = 0, const std::string &customProcess = "") override; - /** - * SetCurrentUserId, set the userid to app mgr by ability mgr when switching to another user. - * - * @param userId the new user. - */ - virtual void SetCurrentUserId(const int32_t userId) override; - - virtual void SetEnableStartProcessFlagByUserId(int32_t userId, bool enableStartProcess) override; - /** * GetBundleNameByPid, get bundleName and uid of a process. * diff --git a/services/appmgr/include/app_mgr_service_inner.h b/services/appmgr/include/app_mgr_service_inner.h index 7a5692b5ee738171fd5029572f0caf3bbfe99726..fcfea5e5cb3f6de9fcd93c0a0a701df1be240768 100644 --- a/services/appmgr/include/app_mgr_service_inner.h +++ b/services/appmgr/include/app_mgr_service_inner.h @@ -1025,22 +1025,6 @@ public: */ void HandleWindowPidVisibilityChanged(const sptr& windowPidVisibilityInfo); #endif //SUPPORT_SCREEN - /** - * Set the current userId, only used by abilityMgr. - * - * @param userId the user id. - * - * @return - */ - void SetCurrentUserId(const int32_t userId); - - /** - * Set enable start process flag by userId - * @param userId the user id. - * @param enableStartProcess enable start process. - * @return - */ - void SetEnableStartProcessFlagByUserId(int32_t userId, bool enableStartProcess); #ifdef BGTASKMGR_CONTINUOUS_TASK_ENABLE int32_t SetContinuousTaskProcess(int32_t pid, bool isContinuousTask); @@ -2035,7 +2019,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(); @@ -2117,7 +2100,6 @@ private: bool isInitAppWaitingDebugListExecuted_ = false; std::atomic sceneBoardAttachFlag_ = true; std::atomic willKillPidsNum_ = 0; - int32_t currentUserId_ = 0; int32_t lastRenderUid_ = Constants::START_UID_FOR_RENDER_PROCESS; const std::string TASK_ON_CALLBACK_DIED = "OnCallbackDiedTask"; std::vector appStateCallbacks_; diff --git a/services/appmgr/src/ams_mgr_scheduler.cpp b/services/appmgr/src/ams_mgr_scheduler.cpp index 92cc246bf7928b28454650d6b25de2fec16b9b06..b94ed942f896cfe6702bdaafacf863e773771110 100644 --- a/services/appmgr/src/ams_mgr_scheduler.cpp +++ b/services/appmgr/src/ams_mgr_scheduler.cpp @@ -536,26 +536,6 @@ int32_t AmsMgrScheduler::NotifyAppMgrRecordExitReason(int32_t pid, int32_t reaso return amsMgrServiceInner_->NotifyAppMgrRecordExitReason(pid, reason, exitMsg); } -void AmsMgrScheduler::SetCurrentUserId(const int32_t userId) -{ - if (!IsReady()) { - return; - } - amsMgrServiceInner_->SetCurrentUserId(userId); -} - -void AmsMgrScheduler::SetEnableStartProcessFlagByUserId(int32_t userId, bool enableStartProcess) -{ - if (!IsReady()) { - return; - } - if (amsMgrServiceInner_->VerifyRequestPermission() != ERR_OK) { - TAG_LOGE(AAFwkTag::APPMGR, "verification failed"); - return; - } - amsMgrServiceInner_->SetEnableStartProcessFlagByUserId(userId, enableStartProcess); -} - int32_t AmsMgrScheduler::GetBundleNameByPid(const int pid, std::string &bundleName, int32_t &uid) { if (!IsReady()) { diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index 749fc44327f404e3e0c30a94cda22be561058620..75c62cdfe38cb0c40592601a63e075cfa38879b3 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -46,6 +46,7 @@ #include "common_event_manager.h" #include "common_event_support.h" #include "datetime_ex.h" +#include "display_util.h" #include "distributed_data_mgr.h" #include "extension_ability_info.h" #include "ffrt.h" @@ -91,7 +92,6 @@ #ifdef SUPPORT_UPMS #include "uri_permission_manager_client.h" #endif // SUPPORT_UPMS -#include "user_record_manager.h" #ifdef APP_MGR_SERVICE_APPMS #include "net_conn_client.h" #endif @@ -106,6 +106,7 @@ #include "cache_process_manager.h" #include "res_sched_util.h" #include "session_manager_lite.h" +#include "user_controller/user_controller.h" #ifdef APP_NO_RESPONSE_DIALOG #include "fault_data.h" #include "modal_system_app_freeze_uiextension.h" @@ -120,6 +121,7 @@ namespace AppExecFwk { #ifdef SUPPORT_SCREEN using namespace OHOS::Rosen; #endif //SUPPORT_SCREEN +using namespace OHOS::AbilityRuntime; using namespace OHOS::Security; using namespace OHOS::Rosen; @@ -284,7 +286,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; @@ -468,7 +469,7 @@ void AppMgrServiceInner::StartSpecifiedProcess(const AAFwk::Want &want, const Ap if (!GetBundleAndHapInfo(abilityInfo, appInfo, bundleInfo, hapModuleInfo, appIndex)) { return; } - if (UserRecordManager::GetInstance().IsLogoutUser(GetUserIdByUid(appInfo->uid))) { + if (UserController::GetInstance().IsLogoutUser(GetUserIdByUid(appInfo->uid))) { TAG_LOGE(AAFwkTag::APPMGR, "disable start process in logout user"); return; } @@ -577,10 +578,13 @@ 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 = UserController::GetInstance().GetCurrentUserId(AAFwk::DisplayUtil::ObtainDefaultDisplayId()); + } } - if (UserRecordManager::GetInstance().IsLogoutUser(userId)) { + if (UserController::GetInstance().IsLogoutUser(userId)) { TAG_LOGE(AAFwkTag::APPMGR, "disable start process in logout user"); return ERR_INVALID_OPERATION; } @@ -891,7 +895,7 @@ void AppMgrServiceInner::LoadAbility(std::shared_ptr abilityInfo, s return; } - if (UserRecordManager::GetInstance().IsLogoutUser(GetUserIdByUid(appInfo->uid))) { + if (UserController::GetInstance().IsLogoutUser(GetUserIdByUid(appInfo->uid))) { TAG_LOGE(AAFwkTag::APPMGR, "disable start process in logout user"); return; } @@ -2303,16 +2307,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 = UserController::GetInstance().GetCurrentUserId(AAFwk::DisplayUtil::ObtainDefaultDisplayId()); } } TAG_LOGI(AAFwkTag::APPMGR, "bundleName: %{public}s, uId: %{public}d, appIndex: %{public}d", bundleName.c_str(), - newUserId, appCloneIndex); - return ClearUpApplicationDataByUserId(bundleName, callerUid, callerPid, appCloneIndex, newUserId, + userId, appCloneIndex); + return ClearUpApplicationDataByUserId(bundleName, callerUid, callerPid, appCloneIndex, userId, false, "ClearUpApplicationData"); } @@ -2328,9 +2331,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, @@ -2433,12 +2433,13 @@ int32_t AppMgrServiceInner::GetRunningProcessesByBundleType(BundleType bundleTyp TAG_LOGE(AAFwkTag::APPMGR, "permission deny"); return ERR_PERMISSION_DENIED; } + int32_t userId = GetUserIdByUid(IPCSkeleton::GetCallingUid()); for (const auto &item : appRunningManager_->GetAppRunningRecordMap()) { const auto &appRecord = item.second; if (!appRecord || !appRecord->GetSpawned()) { continue; } - if (GetUserIdByUid(appRecord->GetUid()) != currentUserId_) { + if (GetUserIdByUid(appRecord->GetUid()) != userId) { continue; } auto appInfo = appRecord->GetApplicationInfo(); @@ -2466,9 +2467,10 @@ int32_t AppMgrServiceInner::GetRunningMultiAppInfoByBundleName(const std::string return ERR_INVALID_VALUE; } ApplicationInfo appInfo; - TAG_LOGD(AAFwkTag::APPMGR, "userId: %{public}d, bundleName: %{public}s", currentUserId_, bundleName.c_str()); + int32_t userId = GetUserIdByUid(IPCSkeleton::GetCallingUid()); + TAG_LOGD(AAFwkTag::APPMGR, "userId: %{public}d, bundleName: %{public}s", userId, bundleName.c_str()); auto queryRet = IN_PROCESS_CALL(bundleMgrHelper->GetApplicationInfo(bundleName, - ApplicationFlag::GET_BASIC_APPLICATION_INFO, currentUserId_, appInfo)); + ApplicationFlag::GET_BASIC_APPLICATION_INFO, userId, appInfo)); if (!queryRet) { TAG_LOGE(AAFwkTag::APPMGR, "bundle unexist"); return AAFwk::ERR_BUNDLE_NOT_EXIST; @@ -2489,7 +2491,7 @@ int32_t AppMgrServiceInner::GetRunningMultiAppInfoByBundleName(const std::string if (appRecord == nullptr || appRecord->GetBundleName() != bundleName) { continue; } - if (GetUserIdByUid(appRecord->GetUid()) != currentUserId_) { + if (GetUserIdByUid(appRecord->GetUid()) != userId) { continue; } #ifdef SUPPORT_CHILD_PROCESS @@ -2517,14 +2519,15 @@ int32_t AppMgrServiceInner::GetAllRunningInstanceKeysBySelf(std::vector &instanceKeys, int32_t userId) { if (userId == -1) { - userId = currentUserId_; + userId = AbilityRuntime::UserController::GetInstance().GetCallerUserId(); } if (VerifyAccountPermission(AAFwk::PermissionConstants::PERMISSION_GET_RUNNING_INFO, userId) == ERR_PERMISSION_DENIED) { @@ -5139,7 +5142,7 @@ void AppMgrServiceInner::StartEmptyResidentProcess( if (!appMultiUserExistFlag) { NotifyAppRunningStatusEvent(info.name, appInfo->uid, AbilityRuntime::RunningStatus::APP_RUNNING_START); } - if (UserRecordManager::GetInstance().IsLogoutUser(GetUserIdByUid(appInfo->uid))) { + if (UserController::GetInstance().IsLogoutUser(GetUserIdByUid(appInfo->uid))) { TAG_LOGE(AAFwkTag::APPMGR, "disable start process in logout user"); return; } @@ -5499,7 +5502,7 @@ int AppMgrServiceInner::StartEmptyProcess(const AAFwk::Want &want, const sptruid, AbilityRuntime::RunningStatus::APP_RUNNING_START); } - if (UserRecordManager::GetInstance().IsLogoutUser(GetUserIdByUid(appInfo->uid))) { + if (UserController::GetInstance().IsLogoutUser(GetUserIdByUid(appInfo->uid))) { TAG_LOGE(AAFwkTag::APPMGR, "disable start process in logout user"); return ERR_INVALID_OPERATION; } @@ -5637,7 +5640,7 @@ void AppMgrServiceInner::StartSpecifiedAbility(const AAFwk::Want &want, const Ap if (!GetBundleAndHapInfo(abilityInfo, appInfo, bundleInfo, hapModuleInfo, appIndex)) { return; } - if (UserRecordManager::GetInstance().IsLogoutUser(GetUserIdByUid(appInfo->uid))) { + if (UserController::GetInstance().IsLogoutUser(GetUserIdByUid(appInfo->uid))) { TAG_LOGE(AAFwkTag::APPMGR, "disable start process in logout user"); return; } @@ -5991,7 +5994,8 @@ void AppMgrServiceInner::HandleConfigurationChange(const Configuration& config, for (const auto &item : appStateCallbacks_) { if (item.callback != nullptr && (userId == -1 || item.userId == 0 || item.userId == userId)) { - item.callback->NotifyConfigurationChange(config, currentUserId_); + item.callback->NotifyConfigurationChange(config, + UserController::GetInstance().GetCurrentUserId(AAFwk::DisplayUtil::ObtainDefaultDisplayId())); } } } @@ -6349,7 +6353,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 = UserController::GetInstance().GetCurrentUserId(AAFwk::DisplayUtil::ObtainDefaultDisplayId()); + } + if (userId != callerUserId) { auto isCallingPermAccount = AAFwk::PermissionVerification::GetInstance()->VerifyCallingPermission( AAFwk::PermissionConstants::PERMISSION_INTERACT_ACROSS_LOCAL_ACCOUNTS); if (!isCallingPermAccount) { @@ -6390,7 +6398,7 @@ int AppMgrServiceInner::PreStartNWebSpawnProcess(const pid_t hostPid) TAG_LOGE(AAFwkTag::APPMGR, "nwebSpawnClient null"); return ERR_INVALID_VALUE; } - if (UserRecordManager::GetInstance().IsLogoutUser(GetUserIdByUid(IPCSkeleton::GetCallingUid()))) { + if (UserController::GetInstance().IsLogoutUser(GetUserIdByUid(IPCSkeleton::GetCallingUid()))) { TAG_LOGE(AAFwkTag::APPMGR, "disable start process in logout user"); return ERR_INVALID_OPERATION; } @@ -6421,7 +6429,7 @@ int AppMgrServiceInner::StartRenderProcess(const pid_t hostPid, const std::strin return ERR_INVALID_VALUE; } CHECK_POINTER_AND_RETURN_VALUE(appRunningManager_, ERR_INVALID_VALUE); - if (UserRecordManager::GetInstance().IsLogoutUser(GetUserIdByUid(IPCSkeleton::GetCallingUid()))) { + if (UserController::GetInstance().IsLogoutUser(GetUserIdByUid(IPCSkeleton::GetCallingUid()))) { TAG_LOGE(AAFwkTag::APPMGR, "disable start process in logout user"); return ERR_INVALID_OPERATION; } @@ -7577,8 +7585,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 = UserController::GetInstance().GetCurrentUserId(AAFwk::DisplayUtil::ObtainDefaultDisplayId()); + } BundleInfo bundleInfo; - auto userId = GetCurrentAccountId(); int32_t bundleMgrResult; if (appCloneIndex == 0) { bundleMgrResult = IN_PROCESS_CALL(bundleMgrHelper->GetBundleInfoV9(bundleName, @@ -7613,11 +7624,6 @@ int32_t AppMgrServiceInner::IsAppRunningByBundleNameAndUserId(const std::string TAG_LOGE(AAFwkTag::APPMGR, "appRunningManager_ null"); return ERR_NO_INIT; } - - if (userId < 0) { - userId = GetCurrentAccountId(); - } - return appRunningManager_->IsAppRunningByBundleNameAndUserId(bundleName, userId, isRunning); } @@ -7628,7 +7634,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 = UserController::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"); @@ -7680,7 +7689,7 @@ int32_t AppMgrServiceInner::StartNativeProcessForDebugger(const AAFwk::Want &wan std::string processName; auto abilityInfoPtr = std::make_shared(abilityInfo); MakeProcessName(abilityInfoPtr, appInfo, hapModuleInfo, 0, "", processName, false); - if (UserRecordManager::GetInstance().IsLogoutUser(GetUserIdByUid(appInfo->uid))) { + if (UserController::GetInstance().IsLogoutUser(GetUserIdByUid(appInfo->uid))) { TAG_LOGE(AAFwkTag::APPMGR, "disable start process in logout user"); return ERR_INVALID_OPERATION; } @@ -7708,23 +7717,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) { @@ -7742,20 +7734,6 @@ void AppMgrServiceInner::RemoveRunningSharedBundleList(const std::string &bundle runningSharedBundleList_.erase(iterator); } -void AppMgrServiceInner::SetCurrentUserId(const int32_t userId) -{ - if (IPCSkeleton::GetCallingUid() != FOUNDATION_UID) { - return; - } - TAG_LOGD(AAFwkTag::APPMGR, "set current userId: %{public}d", userId); - currentUserId_ = userId; -} - -void AppMgrServiceInner::SetEnableStartProcessFlagByUserId(int32_t userId, bool enableStartProcess) -{ - UserRecordManager::GetInstance().SetEnableStartProcessFlagByUserId(userId, enableStartProcess); -} - int32_t AppMgrServiceInner::GetBundleNameByPid(const int32_t pid, std::string &bundleName, int32_t &uid) { TAG_LOGD(AAFwkTag::APPMGR, "called"); @@ -8077,8 +8055,9 @@ bool AppMgrServiceInner::CheckIsDebugApp(const std::string &bundleName) CHECK_POINTER_AND_RETURN_VALUE(bundleMgrHelper, false); BundleInfo bundleInfo; + auto userId = UserController::GetInstance().GetCurrentUserId(AAFwk::DisplayUtil::ObtainDefaultDisplayId()); auto ret = IN_PROCESS_CALL(bundleMgrHelper->GetBundleInfoV9(bundleName, - static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_APPLICATION), bundleInfo, currentUserId_)); + static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_APPLICATION), bundleInfo, userId)); if (ret != ERR_OK) { TAG_LOGE(AAFwkTag::APPMGR, "getBundleInfo fail"); return false; @@ -8328,7 +8307,8 @@ void AppMgrServiceInner::ClearResidentProcessAppRunningData(const std::shared_pt return; } auto userId = GetUserIdByUid(appRecord->GetUid()); - if (appRecord->IsKeepAliveApp() && (userId == 0 || userId == currentUserId_) && + bool isCurentUserId = UserController::GetInstance().IsCurrentUser(userId); + if (appRecord->IsKeepAliveApp() && (userId == 0 || isCurentUserId) && appRecord->GetBundleName() != SCENE_BOARD_BUNDLE_NAME) { if (!IsNeedRestartKeepAliveProcess(appRecord->GetBundleName(), appRecord->GetUid())) { return; @@ -8373,10 +8353,10 @@ void AppMgrServiceInner::ClearNonResidentKeepAliveAppRunningData(const std::shar } auto userId = GetUserIdByUid(appRecord->GetUid()); + bool isCurentUserId = UserController::GetInstance().IsCurrentUser(userId); bool isDefaultInstance = appRecord->GetInstanceKey().empty() || appRecord->GetInstanceKey() == APP_INSTANCE_KEY_0; - if (!appRecord->GetRestartAppFlag() && (appRecord->IsKeepAliveDkv() || appRecord->IsKeepAliveAppService()) && - isDefaultInstance && (userId == 0 || userId == 1 ||userId == currentUserId_) && - appRecord->GetBundleName() != SCENE_BOARD_BUNDLE_NAME) { + if (!appRecord->GetRestartAppFlag() && appRecord->IsKeepAliveDkv() && isDefaultInstance && + (userId == 0 || isCurentUserId) && appRecord->GetBundleName() != SCENE_BOARD_BUNDLE_NAME) { if (ExitResidentProcessManager::GetInstance().IsKilledForUpgradeWeb(appRecord->GetBundleName())) { TAG_LOGI(AAFwkTag::APPMGR, "is killed for upgrade web"); return; @@ -8485,7 +8465,7 @@ int32_t AppMgrServiceInner::StartChildProcess(const pid_t callingPid, pid_t &chi TAG_LOGE(AAFwkTag::APPMGR, "invalid callingPid:%{public}d srcEntry:%{private}s", callingPid, srcEntry.c_str()); return ERR_INVALID_VALUE; } - if (UserRecordManager::GetInstance().IsLogoutUser(GetUserIdByUid(IPCSkeleton::GetCallingUid()))) { + if (UserController::GetInstance().IsLogoutUser(GetUserIdByUid(IPCSkeleton::GetCallingUid()))) { TAG_LOGE(AAFwkTag::APPMGR, "disable start process in logout user"); return ERR_INVALID_OPERATION; } @@ -9650,7 +9630,7 @@ int32_t AppMgrServiceInner::CreateNativeChildProcess(const pid_t hostPid, const return errCode; } - if (UserRecordManager::GetInstance().IsLogoutUser(GetUserIdByUid(IPCSkeleton::GetCallingUid()))) { + if (UserController::GetInstance().IsLogoutUser(GetUserIdByUid(IPCSkeleton::GetCallingUid()))) { TAG_LOGE(AAFwkTag::APPMGR, "disable start process in logout user"); return ERR_INVALID_OPERATION; } diff --git a/services/appmgr/src/user_record_manager.cpp b/services/appmgr/src/user_record_manager.cpp deleted file mode 100644 index 2c56e1a0290794eb744ee640a0c169a412bce683..0000000000000000000000000000000000000000 --- a/services/appmgr/src/user_record_manager.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2024 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_record_manager.h" - -#include -#include "hilog_tag_wrapper.h" - -namespace OHOS { -namespace AppExecFwk { -namespace { -constexpr int32_t U0_USER_ID = 0; -} -UserRecordManager::~UserRecordManager() {} - -UserRecordManager::UserRecordManager() {} - -UserRecordManager &UserRecordManager::GetInstance() -{ - static UserRecordManager instance; - return instance; -} - -bool UserRecordManager::IsLogoutUser(int32_t userId) -{ - if (userId == U0_USER_ID) { - return false; - } - std::lock_guard lock(logoutUserIdLock_); - return logoutUserIdSet_.find(userId) != logoutUserIdSet_.end(); -} - -void UserRecordManager::SetEnableStartProcessFlagByUserId(int32_t userId, bool enableStartProcess) -{ - TAG_LOGI(AAFwkTag::APPMGR, "userId:%{public}d, enableStartProcess:%{public}d", userId, enableStartProcess); - if (enableStartProcess) { - std::lock_guard lock(logoutUserIdLock_); - logoutUserIdSet_.erase(userId); - } else { - std::lock_guard lock(logoutUserIdLock_); - logoutUserIdSet_.insert(userId); - } -} -} // namespace AppExecFwk -} // namespace OHOS diff --git a/services/common/BUILD.gn b/services/common/BUILD.gn index 42fc60e83007eb7a2fcc96842ae771635857bb6b..ea50b34e4dcda17acefa46314c1f7ab027411e08 100644 --- a/services/common/BUILD.gn +++ b/services/common/BUILD.gn @@ -284,6 +284,54 @@ ohos_shared_library("hitrace_chain_util") { "hitrace:libhitracechain", ] + innerapi_tags = [ "platformsdk_indirect" ] + subsystem_name = "ability" + part_name = "ability_runtime" +} + +ohos_shared_library("user_controller") { + sanitize = { + integer_overflow = true + ubsan = true + boundary_sanitize = true + cfi = true + cfi_cross_dso = true + debug = false + } + branch_protector_ret = "pac_ret" + + include_dirs = [ + "include/user_controller", + "${ability_runtime_innerkits_path}/ability_manager/include", + "${ability_runtime_services_path}/common/include", + ] + + defines = [] + + sources = [ "src/user_controller/user_controller.cpp" ] + + deps = [ "${ability_runtime_innerkits_path}/deps_wrapper:ability_deps_wrapper", ] + + external_deps = [ + "c_utils:utils", + "ffrt:libffrt", + "hilog:libhilog", + "ipc:ipc_single", + ] + + if (ability_runtime_graphics) { + defines += [ + "SUPPORT_GRAPHICS", + "SUPPORT_SCREEN", + ] + + deps += [] + external_deps += [ + "window_manager:libdm", + "window_manager:libwsutils", + ] + } + innerapi_tags = [ "platformsdk_indirect" ] subsystem_name = "ability" part_name = "ability_runtime" diff --git a/services/common/include/display_util.h b/services/common/include/display_util.h index eb22fda5f3d69897e2021d4c83be8020b54a2ebe..962c2d056ac46b8c811799bd638b123272b9dd61 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_LOGI(AAFwkTag::DEFAULT, "displayId: %{public}" PRIu64"", display->GetId()); + return display->GetId(); + } + } + return Rosen::DisplayManager::GetInstance().GetDefaultDisplayId(); +} #endif }; } // namespace AAFwk diff --git a/services/common/include/hilog_tag_wrapper.h b/services/common/include/hilog_tag_wrapper.h index 5aaa6001aa88f0a99a8976ec25e42c5ec37a186a..49a20aa69deb5b714575665f7f04d52ea54e3972 100644 --- a/services/common/include/hilog_tag_wrapper.h +++ b/services/common/include/hilog_tag_wrapper.h @@ -98,6 +98,7 @@ enum class AAFwkLogTag : uint32_t { LOCAL_CALL = DEFAULT + 0x60, // 0xD001360 SA_INTERCEPTOR, + USER_CONTROLLER, APP_SERVICE_EXT = DEFAULT + 0x70, // 0xD001370 diff --git a/services/appmgr/include/user_record_manager.h b/services/common/include/user_controller/user_controller.h similarity index 40% rename from services/appmgr/include/user_record_manager.h rename to services/common/include/user_controller/user_controller.h index f7362628f66bece9c62b3859827193d1350f09f0..6de0cb28eff45087778b9ce362e3437af13c2bbf 100644 --- a/services/appmgr/include/user_record_manager.h +++ b/services/common/include/user_controller/user_controller.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * 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 @@ -13,32 +13,58 @@ * limitations under the License. */ -#ifndef OHOS_ABILITY_RUNTIME_USER_RECORD_MANAGER_H -#define OHOS_ABILITY_RUNTIME_USER_RECORD_MANAGER_H +#ifndef OHOS_ABILITY_RUNTIME_USER_CONTROLLER_H +#define OHOS_ABILITY_RUNTIME_USER_CONTROLLER_H -#include +#include #include #include "cpp/mutex.h" -#include "nocopyable.h" - namespace OHOS { -namespace AppExecFwk { - -class UserRecordManager { +namespace AAFwk { +class IUserCallback; +} +namespace AbilityRuntime { +class UserController final { public: - static UserRecordManager &GetInstance(); - ~UserRecordManager(); + UserController& operator=(const UserController&) = delete; + UserController(const UserController&) = delete; + virtual ~UserController() = default; + static UserController& GetInstance(); + + int32_t GetCurrentUserId(uint64_t displayId); + void SetCurrentUserId(int32_t userId, uint64_t displayId); + + bool GetDisplayIdByUserId(int32_t userId, uint64_t &displayId); + + bool IsCurrentUser(int32_t userId); + bool IsCurrentUser(int32_t userId, uint64_t displayId); + + void ClearUserId(int32_t userId); + + int32_t GetCallerUserId(); + bool IsLogoutUser(int32_t userId); void SetEnableStartProcessFlagByUserId(int32_t userId, bool enableStartProcess); + int32_t GetFreezingNewUserId() const; + void SetFreezingNewUserId(int32_t userId); + + bool IsExistOsAccount(int32_t userId) const; + + int32_t CheckStopUserParam(int32_t userId) const; + int32_t CheckUserParam(int32_t userId) const; + private: - UserRecordManager(); - std::unordered_set logoutUserIdSet_; + UserController() = default; + + ffrt::mutex userLock_; + std::unordered_map displayIdMap_; ffrt::mutex logoutUserIdLock_; - DISALLOW_COPY_AND_MOVE(UserRecordManager); + std::unordered_set logoutUserIdSet_; + int32_t freezingNewUserId_ = -1; }; -} // namespace AppExecFwk +} // namespace AbilityRuntime } // namespace OHOS -#endif // OHOS_ABILITY_RUNTIME_USER_RECORD_MANAGER_H +#endif // OHOS_ABILITY_RUNTIME_USER_CONTROLLER_H \ No newline at end of file diff --git a/services/common/src/user_controller/user_controller.cpp b/services/common/src/user_controller/user_controller.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b976edf36631751f3df162009b39cd275a564523 --- /dev/null +++ b/services/common/src/user_controller/user_controller.cpp @@ -0,0 +1,180 @@ +/* + * 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_controller.h" + +#include + +#include "ability_manager_errors.h" +#include "display_util.h" +#include "hilog_tag_wrapper.h" +#include "ipc_skeleton.h" +#include "os_account_manager_wrapper.h" + +namespace OHOS { +namespace AbilityRuntime { +namespace { +constexpr int32_t BASE_USER_RANGE = 200000; +constexpr int32_t U0_USER_ID = 0; +constexpr int32_t U1_USER_ID = 1; +constexpr int32_t USER_ID_DEFAULT = 100; +constexpr int32_t ACCOUNT_MGR_SERVICE_UID = 3058; +} +UserController& UserController::GetInstance() +{ + static UserController instance; + return instance; +} + +void UserController::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 UserController::GetCurrentUserId(uint64_t displayId) +{ + std::lock_guard guard(userLock_); + auto iter = displayIdMap_.find(displayId); + if (iter != displayIdMap_.end()) { + return iter->second; + } + return 0; +} + +bool UserController::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 UserController::IsCurrentUser(int32_t userId) +{ + std::lock_guard guard(userLock_); + for (auto &item : displayIdMap_) { + if (item.second == userId) { + return true; + } + } + return false; +} + +bool UserController::IsCurrentUser(int32_t userId, uint64_t displayId) +{ + int32_t currentUserId = GetCurrentUserId(displayId); + if (currentUserId == userId) { + return true; + } + TAG_LOGI(AAFwkTag::USER_CONTROLLER, "current:%{public}d", currentUserId); + return false; +} + +void UserController::SetCurrentUserId(int32_t userId, uint64_t displayId) +{ + std::lock_guard guard(userLock_); + displayIdMap_[displayId] = userId; +} + +int32_t UserController::GetCallerUserId() +{ + int32_t callerUid = IPCSkeleton::GetCallingUid(); + int32_t callerUser = callerUid / BASE_USER_RANGE; + TAG_LOGD(AAFwkTag::USER_CONTROLLER, "callerUser = %{public}d, CallingUid = %{public}d.", callerUser, callerUid); + if (callerUser == U0_USER_ID || callerUser == U1_USER_ID) { + callerUser = GetCurrentUserId(AAFwk::DisplayUtil::ObtainDefaultDisplayId()); + } + return callerUser; +} + +bool UserController::IsLogoutUser(int32_t userId) +{ + if (userId == U0_USER_ID) { + return false; + } + std::lock_guard lock(logoutUserIdLock_); + return logoutUserIdSet_.find(userId) != logoutUserIdSet_.end(); +} + +void UserController::SetEnableStartProcessFlagByUserId(int32_t userId, bool enableStartProcess) +{ + TAG_LOGI(AAFwkTag::USER_CONTROLLER, "userId:%{public}d, enableStartProcess:%{public}d", userId, enableStartProcess); + if (enableStartProcess) { + std::lock_guard lock(logoutUserIdLock_); + logoutUserIdSet_.erase(userId); + } else { + std::lock_guard lock(logoutUserIdLock_); + logoutUserIdSet_.insert(userId); + } +} + +int32_t UserController::GetFreezingNewUserId() const +{ + return freezingNewUserId_; +} + +void UserController::SetFreezingNewUserId(int32_t userId) +{ + freezingNewUserId_ = userId; + +} + +bool UserController::IsExistOsAccount(int32_t userId) const +{ + bool isExist = false; + auto errCode = DelayedSingleton::GetInstance()->IsOsAccountExists(userId, + isExist); + return (errCode == 0) && isExist; +} + +int32_t UserController::CheckStopUserParam(int32_t userId) const +{ + if (userId == USER_ID_DEFAULT) { + TAG_LOGE(AAFwkTag::USER_CONTROLLER, "stopUser invalid:%{public}d", userId); + return AAFwk::INVALID_USERID_VALUE; + } + return CheckUserParam(userId); +} + +int32_t UserController::CheckUserParam(int32_t userId) const +{ + if (userId <= U0_USER_ID) { + TAG_LOGE(AAFwkTag::USER_CONTROLLER, "userId invalid:%{public}d", userId); + return AAFwk::INVALID_USERID_VALUE; + } + + if (IPCSkeleton::GetCallingUid() != ACCOUNT_MGR_SERVICE_UID) { + TAG_LOGE(AAFwkTag::USER_CONTROLLER, "permission verification failed, not account process"); + return AAFwk::CHECK_PERMISSION_FAILED; + } + + if (!IsExistOsAccount(userId)) { + TAG_LOGE(AAFwkTag::USER_CONTROLLER, "userId not exist"); + return AAFwk::INVALID_USERID_VALUE; + } + return ERR_OK; +} +} +} \ No newline at end of file diff --git a/test/fuzztest/abilityautostartupservicea_fuzzer/BUILD.gn b/test/fuzztest/abilityautostartupservicea_fuzzer/BUILD.gn index 312685efe456ed9b77399573626fc965820a8826..3bb82929a80fbe4175068faa40b2ab00e3aaa3c8 100755 --- a/test/fuzztest/abilityautostartupservicea_fuzzer/BUILD.gn +++ b/test/fuzztest/abilityautostartupservicea_fuzzer/BUILD.gn @@ -56,6 +56,7 @@ ohos_fuzztest("AbilityAutoStartupServiceaFuzzTest") { "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:app_util", "${ability_runtime_services_path}/common:perm_verification", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ diff --git a/test/fuzztest/abilityautostartupserviceb_fuzzer/BUILD.gn b/test/fuzztest/abilityautostartupserviceb_fuzzer/BUILD.gn index c1d52c33e18baac6aa81bb34bae53b33827b2cee..0d947e370e789cdfb587e96eb332adea1f74e8b2 100755 --- a/test/fuzztest/abilityautostartupserviceb_fuzzer/BUILD.gn +++ b/test/fuzztest/abilityautostartupserviceb_fuzzer/BUILD.gn @@ -56,6 +56,7 @@ ohos_fuzztest("AbilityAutoStartupServicebFuzzTest") { "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:app_util", "${ability_runtime_services_path}/common:perm_verification", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ diff --git a/test/fuzztest/abilityautostartupserviceb_fuzzer/abilityautostartupserviceb_fuzzer.cpp b/test/fuzztest/abilityautostartupserviceb_fuzzer/abilityautostartupserviceb_fuzzer.cpp index 820752e27f54a68e671c33c571108a447b9470dc..a67243b73393c581cb7000391638ba1f0707b564 100755 --- a/test/fuzztest/abilityautostartupserviceb_fuzzer/abilityautostartupserviceb_fuzzer.cpp +++ b/test/fuzztest/abilityautostartupserviceb_fuzzer/abilityautostartupserviceb_fuzzer.cpp @@ -85,7 +85,6 @@ void AbilityStartupServiceFuzztest1(bool boolParam, std::string &stringParam, in service->GetSelfApplicationBundleName(); service->CheckSelfApplication(stringParam); - service->GetValidUserId(int32Param); AppExecFwk::BundleInfo bundleInfo; service->GetBundleInfo(stringParam, int32Param, int32Param, bundleInfo); // branch AutoStartupInfo info; diff --git a/test/fuzztest/abilityautostartupservicefirst_fuzzer/BUILD.gn b/test/fuzztest/abilityautostartupservicefirst_fuzzer/BUILD.gn index ab0d1d7be62005e014ec4fc684903222ebd80b59..dda7ec7bc4bd2f05b244a9d8d08c6fb2275e69e9 100644 --- a/test/fuzztest/abilityautostartupservicefirst_fuzzer/BUILD.gn +++ b/test/fuzztest/abilityautostartupservicefirst_fuzzer/BUILD.gn @@ -57,6 +57,7 @@ ohos_fuzztest("AbilityAutoStartupServiceFirstFuzzTest") { "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:app_util", "${ability_runtime_services_path}/common:perm_verification", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ diff --git a/test/fuzztest/abilitykeepalivedatamanager_fuzzer/BUILD.gn b/test/fuzztest/abilitykeepalivedatamanager_fuzzer/BUILD.gn index f9948ac813b609088f19bc23932b361555c5a294..dfec4853e77a83e91b9d8095147ff803be0edf50 100644 --- a/test/fuzztest/abilitykeepalivedatamanager_fuzzer/BUILD.gn +++ b/test/fuzztest/abilitykeepalivedatamanager_fuzzer/BUILD.gn @@ -67,6 +67,7 @@ ohos_fuzztest("AbilityKeepAliveDataManagerFuzzTest") { "${ability_runtime_path}/utils/server/startup:startup_util", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:record_cost_time_util", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ diff --git a/test/fuzztest/abilitykeepaliveservice_fuzzer/BUILD.gn b/test/fuzztest/abilitykeepaliveservice_fuzzer/BUILD.gn index 6255d2f21636262bd9c781c3e1ada2239c2b5097..cdc561d273d00db6f72c4304f5a89ca8e70d0df5 100644 --- a/test/fuzztest/abilitykeepaliveservice_fuzzer/BUILD.gn +++ b/test/fuzztest/abilitykeepaliveservice_fuzzer/BUILD.gn @@ -49,6 +49,7 @@ ohos_fuzztest("AbilityKeepAliveServiceFuzzTest") { "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_path}/utils/server/startup:startup_util", "${ability_runtime_services_path}/abilitymgr:abilityms", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ diff --git a/test/fuzztest/abilitymanagerservicefourth_fuzzer/abilitymanagerservicefourth_fuzzer.cpp b/test/fuzztest/abilitymanagerservicefourth_fuzzer/abilitymanagerservicefourth_fuzzer.cpp index 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/keepaliveprocessmanagereighteenth_fuzzer/BUILD.gn b/test/fuzztest/keepaliveprocessmanagereighteenth_fuzzer/BUILD.gn index b9515b6872dcdc63eec8bd54034e54a96abfb386..21fdc4596c80409b7e8e9c72a535de5b5097a618 100644 --- a/test/fuzztest/keepaliveprocessmanagereighteenth_fuzzer/BUILD.gn +++ b/test/fuzztest/keepaliveprocessmanagereighteenth_fuzzer/BUILD.gn @@ -66,6 +66,7 @@ ohos_fuzztest("KeepAliveProcessManagerEighteenthFuzzTest") { "${ability_runtime_path}/utils/server/startup:startup_util", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:record_cost_time_util", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ diff --git a/test/fuzztest/keepaliveprocessmanagereighth_fuzzer/BUILD.gn b/test/fuzztest/keepaliveprocessmanagereighth_fuzzer/BUILD.gn index cb815bf317c08e6b1856483dc0732699b0c9acf9..c40fb532933554302d7a302e98547d6012d85835 100644 --- a/test/fuzztest/keepaliveprocessmanagereighth_fuzzer/BUILD.gn +++ b/test/fuzztest/keepaliveprocessmanagereighth_fuzzer/BUILD.gn @@ -67,6 +67,7 @@ ohos_fuzztest("KeepAliveProcessManagerEighthFuzzTest") { "${ability_runtime_path}/utils/server/startup:startup_util", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:record_cost_time_util", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ diff --git a/test/fuzztest/keepaliveprocessmanagereleventh_fuzzer/BUILD.gn b/test/fuzztest/keepaliveprocessmanagereleventh_fuzzer/BUILD.gn index 32bf75cdd8142e7aa97b2b34102414583dc7a930..809e6853865e0532f321d0d795b7ac42d4ea3c30 100644 --- a/test/fuzztest/keepaliveprocessmanagereleventh_fuzzer/BUILD.gn +++ b/test/fuzztest/keepaliveprocessmanagereleventh_fuzzer/BUILD.gn @@ -67,6 +67,7 @@ ohos_fuzztest("KeepAliveProcessManagerEleventhFuzzTest") { "${ability_runtime_path}/utils/server/startup:startup_util", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:record_cost_time_util", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ diff --git a/test/fuzztest/keepaliveprocessmanagerfifteenth_fuzzer/BUILD.gn b/test/fuzztest/keepaliveprocessmanagerfifteenth_fuzzer/BUILD.gn index 65582f901a0267bba6fc6a577ab3981385891604..87fb87da196b7194613d4b9c2ccd310b4a289ab3 100644 --- a/test/fuzztest/keepaliveprocessmanagerfifteenth_fuzzer/BUILD.gn +++ b/test/fuzztest/keepaliveprocessmanagerfifteenth_fuzzer/BUILD.gn @@ -67,6 +67,7 @@ ohos_fuzztest("KeepAliveProcessManagerFifteenthFuzzTest") { "${ability_runtime_path}/utils/server/startup:startup_util", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:record_cost_time_util", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ diff --git a/test/fuzztest/keepaliveprocessmanagerfifth_fuzzer/BUILD.gn b/test/fuzztest/keepaliveprocessmanagerfifth_fuzzer/BUILD.gn index e2e99632a7ae0e63eb819fa58ecdab4b03602b3c..bfc9b0082eca425cc9442a8260d299fe11ca5343 100644 --- a/test/fuzztest/keepaliveprocessmanagerfifth_fuzzer/BUILD.gn +++ b/test/fuzztest/keepaliveprocessmanagerfifth_fuzzer/BUILD.gn @@ -66,6 +66,7 @@ ohos_fuzztest("KeepAliveProcessManagerFifthFuzzTest") { "${ability_runtime_path}/utils/server/startup:startup_util", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:record_cost_time_util", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ diff --git a/test/fuzztest/keepaliveprocessmanagerfirst_fuzzer/BUILD.gn b/test/fuzztest/keepaliveprocessmanagerfirst_fuzzer/BUILD.gn index 24974375c8faf08feaee40907b11303df08dad8a..9736f521b871c06c09774fa336a6544393f6db7d 100644 --- a/test/fuzztest/keepaliveprocessmanagerfirst_fuzzer/BUILD.gn +++ b/test/fuzztest/keepaliveprocessmanagerfirst_fuzzer/BUILD.gn @@ -67,6 +67,7 @@ ohos_fuzztest("KeepAliveProcessManagerFirstFuzzTest") { "${ability_runtime_path}/utils/server/startup:startup_util", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:record_cost_time_util", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ diff --git a/test/fuzztest/keepaliveprocessmanagerfourteenth_fuzzer/BUILD.gn b/test/fuzztest/keepaliveprocessmanagerfourteenth_fuzzer/BUILD.gn index 63f9807a935a2de52885760d4ce643ca351c153f..c9271fd63591f974c29ae73ea31a1f3fcf3fa8df 100644 --- a/test/fuzztest/keepaliveprocessmanagerfourteenth_fuzzer/BUILD.gn +++ b/test/fuzztest/keepaliveprocessmanagerfourteenth_fuzzer/BUILD.gn @@ -67,6 +67,7 @@ ohos_fuzztest("KeepAliveProcessManagerFourteenthFuzzTest") { "${ability_runtime_path}/utils/server/startup:startup_util", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:record_cost_time_util", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ diff --git a/test/fuzztest/keepaliveprocessmanagerfourth_fuzzer/BUILD.gn b/test/fuzztest/keepaliveprocessmanagerfourth_fuzzer/BUILD.gn index 52e0e169eaad7ff2fa3e3b135b96fa9b22315a64..5c40daa53cb44dd8d2060d19f792c7effd5c2cd9 100644 --- a/test/fuzztest/keepaliveprocessmanagerfourth_fuzzer/BUILD.gn +++ b/test/fuzztest/keepaliveprocessmanagerfourth_fuzzer/BUILD.gn @@ -66,6 +66,7 @@ ohos_fuzztest("KeepAliveProcessManagerFourthFuzzTest") { "${ability_runtime_path}/utils/server/startup:startup_util", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:record_cost_time_util", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ diff --git a/test/fuzztest/keepaliveprocessmanagerninteenth_fuzzer/BUILD.gn b/test/fuzztest/keepaliveprocessmanagerninteenth_fuzzer/BUILD.gn index 64d20fa7d020a34a9a08955ba8516c21ed590668..82c7bb58bfaf7b7093a322608104429f867e2fd4 100644 --- a/test/fuzztest/keepaliveprocessmanagerninteenth_fuzzer/BUILD.gn +++ b/test/fuzztest/keepaliveprocessmanagerninteenth_fuzzer/BUILD.gn @@ -66,6 +66,7 @@ ohos_fuzztest("KeepAliveProcessManagerNinteenthFuzzTest") { "${ability_runtime_path}/utils/server/startup:startup_util", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:record_cost_time_util", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ diff --git a/test/fuzztest/keepaliveprocessmanagerninth_fuzzer/BUILD.gn b/test/fuzztest/keepaliveprocessmanagerninth_fuzzer/BUILD.gn index 39fdca3deac74fe1a7c5ad0267fbeebe536cc77a..23ea702923d78e4f01be8d594b020526733a723a 100644 --- a/test/fuzztest/keepaliveprocessmanagerninth_fuzzer/BUILD.gn +++ b/test/fuzztest/keepaliveprocessmanagerninth_fuzzer/BUILD.gn @@ -66,6 +66,7 @@ ohos_fuzztest("KeepAliveProcessManagerNinthFuzzTest") { "${ability_runtime_path}/utils/server/startup:startup_util", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:record_cost_time_util", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ diff --git a/test/fuzztest/keepaliveprocessmanagersecond_fuzzer/BUILD.gn b/test/fuzztest/keepaliveprocessmanagersecond_fuzzer/BUILD.gn index 2b2d2d882a1c644cd893c1bda7337113d8a067a6..19c3b88f7751b6ca04a4d9661944774e9b0ac9e8 100644 --- a/test/fuzztest/keepaliveprocessmanagersecond_fuzzer/BUILD.gn +++ b/test/fuzztest/keepaliveprocessmanagersecond_fuzzer/BUILD.gn @@ -67,6 +67,7 @@ ohos_fuzztest("KeepAliveProcessManagerSecondFuzzTest") { "${ability_runtime_path}/utils/server/startup:startup_util", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:record_cost_time_util", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ diff --git a/test/fuzztest/keepaliveprocessmanagerseventeenth_fuzzer/BUILD.gn b/test/fuzztest/keepaliveprocessmanagerseventeenth_fuzzer/BUILD.gn index 59b08590d335e5aa2b136cde8ee9336b6e51e676..cf9a515f3fcf9b4c613aeb07052c43618c6f1dbd 100644 --- a/test/fuzztest/keepaliveprocessmanagerseventeenth_fuzzer/BUILD.gn +++ b/test/fuzztest/keepaliveprocessmanagerseventeenth_fuzzer/BUILD.gn @@ -66,6 +66,7 @@ ohos_fuzztest("KeepAliveProcessManagerSeventeenthFuzzTest") { "${ability_runtime_path}/utils/server/startup:startup_util", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:record_cost_time_util", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ diff --git a/test/fuzztest/keepaliveprocessmanagerseventh_fuzzer/BUILD.gn b/test/fuzztest/keepaliveprocessmanagerseventh_fuzzer/BUILD.gn index a90f941ce083976df89de502aa2dad9c42ad6305..aeac0fc7a15417f0a00c4f6858f47264d12a3bd1 100644 --- a/test/fuzztest/keepaliveprocessmanagerseventh_fuzzer/BUILD.gn +++ b/test/fuzztest/keepaliveprocessmanagerseventh_fuzzer/BUILD.gn @@ -67,6 +67,7 @@ ohos_fuzztest("KeepAliveProcessManagerSeventhFuzzTest") { "${ability_runtime_path}/utils/server/startup:startup_util", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:record_cost_time_util", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ diff --git a/test/fuzztest/keepaliveprocessmanagersixteenth_fuzzer/BUILD.gn b/test/fuzztest/keepaliveprocessmanagersixteenth_fuzzer/BUILD.gn index f4ec5bf813b6dfbe6075bd856a8153a69e7ec01b..71194513391e5a8a7376bd2107a50c9bc83c747b 100644 --- a/test/fuzztest/keepaliveprocessmanagersixteenth_fuzzer/BUILD.gn +++ b/test/fuzztest/keepaliveprocessmanagersixteenth_fuzzer/BUILD.gn @@ -67,6 +67,7 @@ ohos_fuzztest("KeepAliveProcessManagerSixteenthFuzzTest") { "${ability_runtime_path}/utils/server/startup:startup_util", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:record_cost_time_util", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ diff --git a/test/fuzztest/keepaliveprocessmanagersixth_fuzzer/BUILD.gn b/test/fuzztest/keepaliveprocessmanagersixth_fuzzer/BUILD.gn index 48c3944b2778d46992cbb1d5f79374703787f3d2..45e43404cc87fe2218dfa8f36ae0cb616b010b85 100644 --- a/test/fuzztest/keepaliveprocessmanagersixth_fuzzer/BUILD.gn +++ b/test/fuzztest/keepaliveprocessmanagersixth_fuzzer/BUILD.gn @@ -66,6 +66,7 @@ ohos_fuzztest("KeepAliveProcessManagerSixthFuzzTest") { "${ability_runtime_path}/utils/server/startup:startup_util", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:record_cost_time_util", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ diff --git a/test/fuzztest/keepaliveprocessmanagertenth_fuzzer/BUILD.gn b/test/fuzztest/keepaliveprocessmanagertenth_fuzzer/BUILD.gn index 97b82a07142f29e4087a2eeb7792a3320e264392..593d63355787a9e3263633aa36d7466e1bdd4880 100644 --- a/test/fuzztest/keepaliveprocessmanagertenth_fuzzer/BUILD.gn +++ b/test/fuzztest/keepaliveprocessmanagertenth_fuzzer/BUILD.gn @@ -67,6 +67,7 @@ ohos_fuzztest("KeepAliveProcessManagerTenthFuzzTest") { "${ability_runtime_path}/utils/server/startup:startup_util", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:record_cost_time_util", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ diff --git a/test/fuzztest/keepaliveprocessmanagerthird_fuzzer/BUILD.gn b/test/fuzztest/keepaliveprocessmanagerthird_fuzzer/BUILD.gn index 7196e59e83a7ace5b5e95782c1bb2393357b861f..f723d51184d8f499a61056aa9817b5cfd75daaea 100644 --- a/test/fuzztest/keepaliveprocessmanagerthird_fuzzer/BUILD.gn +++ b/test/fuzztest/keepaliveprocessmanagerthird_fuzzer/BUILD.gn @@ -67,6 +67,7 @@ ohos_fuzztest("KeepAliveProcessManagerThirdFuzzTest") { "${ability_runtime_path}/utils/server/startup:startup_util", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:record_cost_time_util", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ diff --git a/test/fuzztest/keepaliveprocessmanagerthirteenth_fuzzer/BUILD.gn b/test/fuzztest/keepaliveprocessmanagerthirteenth_fuzzer/BUILD.gn index 0bccb3b546e3fa09ad7016ae75e62025581196f7..eb07b8bcb78fb37fbe88f63714e2300313654b4a 100644 --- a/test/fuzztest/keepaliveprocessmanagerthirteenth_fuzzer/BUILD.gn +++ b/test/fuzztest/keepaliveprocessmanagerthirteenth_fuzzer/BUILD.gn @@ -67,6 +67,7 @@ ohos_fuzztest("KeepAliveProcessManagerThirteenthFuzzTest") { "${ability_runtime_path}/utils/server/startup:startup_util", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:record_cost_time_util", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ diff --git a/test/fuzztest/keepaliveprocessmanagertwelfth_fuzzer/BUILD.gn b/test/fuzztest/keepaliveprocessmanagertwelfth_fuzzer/BUILD.gn index 759511eb962f3d0cf25e10b0622f1ba166846bc3..4772c87de8b2289a12cfd275a0a6840e0dec7884 100644 --- a/test/fuzztest/keepaliveprocessmanagertwelfth_fuzzer/BUILD.gn +++ b/test/fuzztest/keepaliveprocessmanagertwelfth_fuzzer/BUILD.gn @@ -66,6 +66,7 @@ ohos_fuzztest("KeepAliveProcessManagerTwelfthFuzzTest") { "${ability_runtime_path}/utils/server/startup:startup_util", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:record_cost_time_util", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ 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 9fddcdfc1cc0bb5582305161e308a59e65b10eb0..8eb2af62769321c3c3ad0dabdc9665b189f9f9f4 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 89299aada1bd577ac39976bf5289ea28e376bd74..e731850ebaaf3cc96b1c49fdd07299af60205d1e 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 dd7fe95a1495a3e013f780164891d3afff3030c8..4137df30ef01a361ea5708ac864c9ce263fb4671 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 127ea466c0af146f0c91b014624e1c00966e999a..b9f0168fda6a2d39d3312e2b33eff1f9455fb0a3 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 7d1d71c42446b68dbbf2fc853d6cd3e1fb4e35ab..3cb74a269251e494b74fb897f8716d89df658ea5 100644 --- a/test/mock/frameworks_kits_appkit_native_test/ability_delegator/mock_ability_delegator_stub.h +++ b/test/mock/frameworks_kits_appkit_native_test/ability_delegator/mock_ability_delegator_stub.h @@ -125,7 +125,7 @@ public: MOCK_METHOD4(ShareDataDone, int32_t(const sptr &token, const int32_t &resultCode, const int32_t &uniqueId, WantParams &wantParam)); MOCK_METHOD2(SetMissionContinueState, int(const sptr& token, const AAFwk::ContinueState& state)); - int StartUser(int userId, sptr callback, bool isAppRecovery) override; + int StartUser(int userId, uint64_t displayId, sptr callback, bool isAppRecovery) override; int StopUser(int userId, const sptr& callback) override; int LogoutUser(int32_t userId, sptr callback = nullptr) override; int StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag) override; @@ -306,7 +306,7 @@ public: MOCK_METHOD4(ShareDataDone, int32_t(const sptr &token, const int32_t &resultCode, const int32_t &uniqueId, WantParams &wantParam)); MOCK_METHOD2(SetMissionContinueState, int(const sptr& token, const AAFwk::ContinueState& state)); - int StartUser(int userId, sptr callback, bool isAppRecovery) override; + int StartUser(int userId, uint64_t displayId, sptr callback, bool isAppRecovery) override; int StopUser(int userId, const sptr& callback) override; int LogoutUser(int32_t userId, sptr callback = nullptr) override; int StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag) override; diff --git a/test/mock/frameworks_kits_test/AMS/mock_ability_manager_service.h b/test/mock/frameworks_kits_test/AMS/mock_ability_manager_service.h index 3fb4002e1041dc3728952ad13cb6a64cc3dea46b..44f19bf59acf2ab9891768ae00c682cb9bec61af 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 2f54869dfb90dfd60f8880d7aaf69002fbc98a48..0531d96b543a546046e716fbdd4b4df23c5b27e4 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/moduletest/ability_manager_client_test/mock_iabilitymanager.h b/test/moduletest/ability_manager_client_test/mock_iabilitymanager.h index 4682b9fb078deff882dfdf70785d5104cb832644..468a9e3580dac2bed7db5c6c5f540b46ee2d0669 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 60e8956a96764dcb14f918c93c90bda1fb361297..41aeac608c45f508539d2fe234576689ca7cc105 100644 --- a/test/moduletest/common/ams/ability_running_record_test/BUILD.gn +++ b/test/moduletest/common/ams/ability_running_record_test/BUILD.gn @@ -33,6 +33,7 @@ ohos_moduletest("AmsAbilityRunningRecordModuleTest") { "${ability_runtime_services_path}/common:perm_verification", "${ability_runtime_services_path}/common:record_cost_time_util", "${ability_runtime_services_path}/common:res_sched_util", + "${ability_runtime_services_path}/common:user_controller", "${ability_runtime_test_path}/moduletest/common/ams:appmgr_mst_source", ] @@ -55,6 +56,7 @@ ohos_moduletest("AmsAbilityRunningRecordModuleTest") { if (ability_runtime_graphics) { external_deps += [ + "window_manager:libdm", "window_manager:libwm", "window_manager:libwsutils", ] diff --git a/test/moduletest/common/ams/app_mgr_service_test/BUILD.gn b/test/moduletest/common/ams/app_mgr_service_test/BUILD.gn index 245d98c4f01a3da300b8bb9f24525061e733bd44..2cf0fe1553f031d7e072cea6c8d8ac55b1193a14 100644 --- a/test/moduletest/common/ams/app_mgr_service_test/BUILD.gn +++ b/test/moduletest/common/ams/app_mgr_service_test/BUILD.gn @@ -43,6 +43,7 @@ ohos_moduletest("AmsAppMgrServiceModuleTest") { "${ability_runtime_services_path}/common:perm_verification", "${ability_runtime_services_path}/common:record_cost_time_util", "${ability_runtime_services_path}/common:res_sched_util", + "${ability_runtime_services_path}/common:user_controller", "${ability_runtime_test_path}/moduletest/common/ams:appmgr_mst_source", ] @@ -66,6 +67,7 @@ ohos_moduletest("AmsAppMgrServiceModuleTest") { if (ability_runtime_graphics) { external_deps += [ "i18n:intl_util", + "window_manager:libdm", "window_manager:libwm", ] } diff --git a/test/moduletest/common/ams/app_recent_list_test/BUILD.gn b/test/moduletest/common/ams/app_recent_list_test/BUILD.gn index d1fbca3d6f0673e7959e68b7a23c42e914eac62d..d6b441d83730c3fef4a949d6ad0c601e30f5f3ba 100644 --- a/test/moduletest/common/ams/app_recent_list_test/BUILD.gn +++ b/test/moduletest/common/ams/app_recent_list_test/BUILD.gn @@ -35,6 +35,7 @@ ohos_moduletest("AmsAppRecentListModuleTest") { "${ability_runtime_services_path}/common:record_cost_time_util", "${ability_runtime_services_path}/common:res_sched_util", "${ability_runtime_services_path}/common:task_handler_wrap", + "${ability_runtime_services_path}/common:user_controller", "${ability_runtime_test_path}/moduletest/common/ams:appmgr_mst_source", ] diff --git a/test/moduletest/common/ams/app_service_flow_test/BUILD.gn b/test/moduletest/common/ams/app_service_flow_test/BUILD.gn index 9a41ae9d754efba4dbb591d1947e5989afbfd2ed..e1e11e547cc2a9938554e6de499c2870a48b5e98 100644 --- a/test/moduletest/common/ams/app_service_flow_test/BUILD.gn +++ b/test/moduletest/common/ams/app_service_flow_test/BUILD.gn @@ -38,6 +38,7 @@ ohos_moduletest("AmsAppServiceFlowModuleTest") { "${ability_runtime_services_path}/common:record_cost_time_util", "${ability_runtime_services_path}/common:res_sched_util", "${ability_runtime_services_path}/common:task_handler_wrap", + "${ability_runtime_services_path}/common:user_controller", "${ability_runtime_test_path}/moduletest/common/ams:appmgr_mst_source", ] diff --git a/test/moduletest/common/ams/ipc_ams_mgr_test/BUILD.gn b/test/moduletest/common/ams/ipc_ams_mgr_test/BUILD.gn index effd5e6d6f74f418b0f2c0fb2486a8dae20d365f..effbcf849d9301ef82a866c60404b7c07805241a 100644 --- a/test/moduletest/common/ams/ipc_ams_mgr_test/BUILD.gn +++ b/test/moduletest/common/ams/ipc_ams_mgr_test/BUILD.gn @@ -44,6 +44,7 @@ ohos_moduletest("AmsIpcAmsmgrModuleTest") { "${ability_runtime_services_path}/common:record_cost_time_util", "${ability_runtime_services_path}/common:res_sched_util", "${ability_runtime_services_path}/common:task_handler_wrap", + "${ability_runtime_services_path}/common:user_controller", "${ability_runtime_test_path}/moduletest/common/ams:appmgr_mst_source", "${ability_runtime_test_path}/unittest:appmgr_test_source", ] @@ -67,7 +68,10 @@ ohos_moduletest("AmsIpcAmsmgrModuleTest") { ] if (ability_runtime_graphics) { - external_deps += [ "window_manager:libwm" ] + external_deps += [ + "window_manager:libdm", + "window_manager:libwm", + ] } if (background_task_mgr_continuous_task_enable) { diff --git a/test/moduletest/common/ams/ipc_app_mgr_test/BUILD.gn b/test/moduletest/common/ams/ipc_app_mgr_test/BUILD.gn index 9689d74f1b51e057bcf9901c1a73c784eaa08071..3f08a5282f9f7e85cf1f4694f804c12c38fa71ef 100644 --- a/test/moduletest/common/ams/ipc_app_mgr_test/BUILD.gn +++ b/test/moduletest/common/ams/ipc_app_mgr_test/BUILD.gn @@ -35,6 +35,7 @@ ohos_moduletest("AmsIpcAppmgrModuleTest") { "${ability_runtime_services_path}/common:perm_verification", "${ability_runtime_services_path}/common:record_cost_time_util", "${ability_runtime_services_path}/common:res_sched_util", + "${ability_runtime_services_path}/common:user_controller", "${ability_runtime_test_path}/moduletest/common/ams:appmgr_mst_source", ] @@ -60,6 +61,7 @@ ohos_moduletest("AmsIpcAppmgrModuleTest") { "memory_utils:libmeminfo", "safwk:system_ability_fwk", "samgr:samgr_proxy", + "window_manager:libdm", "window_manager:libwm", "window_manager:libwsutils", ] diff --git a/test/moduletest/common/ams/ipc_app_scheduler_test/BUILD.gn b/test/moduletest/common/ams/ipc_app_scheduler_test/BUILD.gn index 8f3185e86e175ca71316cc958ecd36a4461ccb6a..969354cc20025199119f600b88654196fc93603a 100644 --- a/test/moduletest/common/ams/ipc_app_scheduler_test/BUILD.gn +++ b/test/moduletest/common/ams/ipc_app_scheduler_test/BUILD.gn @@ -35,6 +35,7 @@ ohos_moduletest("AmsIpcAppSchedulerModuleTest") { "${ability_runtime_services_path}/common:perm_verification", "${ability_runtime_services_path}/common:record_cost_time_util", "${ability_runtime_services_path}/common:res_sched_util", + "${ability_runtime_services_path}/common:user_controller", "${ability_runtime_test_path}/moduletest/common/ams:appmgr_mst_source", ] @@ -60,6 +61,7 @@ ohos_moduletest("AmsIpcAppSchedulerModuleTest") { "memory_utils:libmeminfo", "safwk:system_ability_fwk", "samgr:samgr_proxy", + "window_manager:libdm", "window_manager:libwm", "window_manager:libwsutils", ] diff --git a/test/moduletest/common/ams/service_start_process_test/BUILD.gn b/test/moduletest/common/ams/service_start_process_test/BUILD.gn index 92bf5be75cb7dfd5f0b6551e1a865cef4949f0fe..4f4897ba1df8c90faf0b1c7d1f1c7b885cf01630 100644 --- a/test/moduletest/common/ams/service_start_process_test/BUILD.gn +++ b/test/moduletest/common/ams/service_start_process_test/BUILD.gn @@ -35,6 +35,7 @@ ohos_moduletest("AmsServiceStartModuleTest") { "${ability_runtime_services_path}/common:perm_verification", "${ability_runtime_services_path}/common:record_cost_time_util", "${ability_runtime_services_path}/common:res_sched_util", + "${ability_runtime_services_path}/common:user_controller", "${ability_runtime_test_path}/moduletest/common/ams:appmgr_mst_source", ] @@ -54,6 +55,7 @@ ohos_moduletest("AmsServiceStartModuleTest") { if (ability_runtime_graphics) { external_deps += [ "i18n:intl_util", + "window_manager:libdm", "window_manager:libwm", ] } diff --git a/test/moduletest/mock/include/mock_ability_mgr_service.h b/test/moduletest/mock/include/mock_ability_mgr_service.h index 9f9438d17596815f858047a001e41515cdcdbc8c..2aa5fe0bae265e0711726837abcbe09e934850e6 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/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..5fc46d1b7eabe9575dab0f8240dc0532dc5d7163 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 @@ -30,6 +30,7 @@ #include "system_ability_definition.h" #include "ui_service_mgr_client_mock.h" #include "mission_list_manager.h" +#include "user_controller/user_controller.h" using namespace testing; using namespace testing::ext; @@ -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); + AbilityRuntime::UserController::GetInstance().SetCurrentUserId(MOCK_MAIN_USER_ID, 0); return; } diff --git a/test/new_test/mock/ability_manager_service/ability_manager_service.h b/test/new_test/mock/ability_manager_service/ability_manager_service.h index da6132073630a0df214bd2b917ca988129d6e2f8..a7315a46a1e959de0a26e2f7ea5bd58994628f5a 100644 --- a/test/new_test/mock/ability_manager_service/ability_manager_service.h +++ b/test/new_test/mock/ability_manager_service/ability_manager_service.h @@ -45,7 +45,7 @@ public: void StopFreezingScreen() {} void UserStarted(int32_t userId) {} - OH_MOCK_METHOD(int, AbilityManagerService, SwitchToUser, int32_t, int32_t, + OH_MOCK_METHOD(int, AbilityManagerService, SwitchToUser, int32_t, int32_t, uint64_t, sptr, bool isAppRecovery = false); void ClearUserData(int32_t userId) {} }; diff --git a/test/new_test/mock/app_scheduler/app_scheduler.h b/test/new_test/mock/app_scheduler/app_scheduler.h index 156ff64e732ea798475c2e27d3e489d4b03cd472..b4920ec76de3938a01fbe20b3be1551b0b63584d 100644 --- a/test/new_test/mock/app_scheduler/app_scheduler.h +++ b/test/new_test/mock/app_scheduler/app_scheduler.h @@ -125,12 +125,8 @@ public: return false; } - void SetEnableStartProcessFlagByUserId(int32_t userId, bool enableStartProcess) {} - void KillProcessesByUserId(int32_t userId, bool isNeedSendAppSpawnMsg = false, sptr callback = nullptr) {} - - void SetCurrentUserId(int32_t userId) {} }; } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/src/user_event_handler.cpp b/test/new_test/mock/dispaly_util/display_util.h similarity index 58% rename from services/abilitymgr/src/user_event_handler.cpp rename to test/new_test/mock/dispaly_util/display_util.h index 416b02f11ddbe3b7e757b290f566244582167476..cd0d94d2cf390d15dda512880b6eff035bb4b190 100644 --- a/services/abilitymgr/src/user_event_handler.cpp +++ b/test/new_test/mock/dispaly_util/display_util.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * 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 @@ -13,24 +13,24 @@ * limitations under the License. */ -#include "user_event_handler.h" +#ifndef OHOS_ABILITY_RUNTIME_DISPLAY_UTIL_H +#define OHOS_ABILITY_RUNTIME_DISPLAY_UTIL_H -#include "user_controller.h" +#include "refbase.h" namespace OHOS { namespace AAFwk { -UserEventHandler::UserEventHandler( - const std::shared_ptr &taskHandler, const std::weak_ptr &owner) - : EventHandlerWrap(taskHandler), controller_(owner) +namespace DisplayUtil { +static inline int32_t GetDefaultDisplayId() { + return 0; } -void UserEventHandler::ProcessEvent(const EventWrap &event) +static inline uint64_t ObtainDefaultDisplayId() { - auto owner = controller_.lock(); - if (owner) { - owner->ProcessEvent(event); - } + return 0; +} } } // namespace AAFwk } // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_DISPLAY_UTIL_H \ No newline at end of file diff --git a/test/new_test/mock/hilog_tag_wrapper/hilog_tag_wrapper.h b/test/new_test/mock/hilog_tag_wrapper/hilog_tag_wrapper.h index 9d577ef3055423e24f67d4e7317eb15d3a00f9d2..5beead6b33b55c320d54710e7cd43e31fe5357a4 100644 --- a/test/new_test/mock/hilog_tag_wrapper/hilog_tag_wrapper.h +++ b/test/new_test/mock/hilog_tag_wrapper/hilog_tag_wrapper.h @@ -95,6 +95,8 @@ enum class AAFwkLogTag : uint32_t { QUERY_ERMS, LOCAL_CALL = DEFAULT + 0x60, // 0xD001360 + SA_INTERCEPTOR, + USER_CONTROLLER, END = 256, // N.B. never use it }; diff --git a/test/unittest/app_mgr_service_inner_ninth_test/mock/src/mock_user_record_manager.cpp b/test/new_test/mock/ipc_skeleton/ipc_skeleton.h similarity index 48% rename from test/unittest/app_mgr_service_inner_ninth_test/mock/src/mock_user_record_manager.cpp rename to test/new_test/mock/ipc_skeleton/ipc_skeleton.h index 25c797eb34194cdd059e8f50983c043cc01ff8fa..f68fbae3f42ef65128d196b90397b8f531530b11 100644 --- a/test/unittest/app_mgr_service_inner_ninth_test/mock/src/mock_user_record_manager.cpp +++ b/test/new_test/mock/ipc_skeleton/ipc_skeleton.h @@ -12,35 +12,22 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "user_record_manager.h" -#include -#include "hilog_tag_wrapper.h" -#include "mock_my_status.h" + +#ifndef OHOS_ABILITY_RUNTIME_IPC_SKELETON_H +#define OHOS_ABILITY_RUNTIME_IPC_SKELETON_H + +#include "refbase.h" namespace OHOS { -namespace AppExecFwk { -namespace { - constexpr int32_t U0_USER_ID = 0; -} -UserRecordManager::~UserRecordManager() {} - -UserRecordManager::UserRecordManager() {} - -UserRecordManager &UserRecordManager::GetInstance() -{ - static UserRecordManager instance; - return instance; -} - -bool UserRecordManager::IsLogoutUser(int32_t userId) -{ - AAFwk::MyStatus::GetInstance().isLogoutUserCalled_ = true; - return AAFwk::MyStatus::GetInstance().isLogoutUser_; -} +class IPCSkeleton { +public: + IPCSkeleton() = default; + ~IPCSkeleton() = default; + + static int32_t GetCallingUid() { + return 0; + } -void UserRecordManager::SetEnableStartProcessFlagByUserId(int32_t userId, bool enableStartProcess) -{ -} -} // namespace AppExecFwk +}; } // namespace OHOS - \ No newline at end of file +#endif // OHOS_ABILITY_RUNTIME_IPC_SKELETON_H \ No newline at end of file diff --git a/test/new_test/mock/user_event_handler/user_event_handler.h b/test/new_test/mock/user_event_handler/user_event_handler.h deleted file mode 100644 index e41e001bb5ec45c0371957e33ca9b8f0cf7cdb94..0000000000000000000000000000000000000000 --- a/test/new_test/mock/user_event_handler/user_event_handler.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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_EVENT_HANDLER_H -#define OHOS_ABILITY_RUNTIME_USER_EVENT_HANDLER_H - -#include - -#include "event_handler_wrap.h" - -namespace OHOS { -namespace AAFwk { -class UserController; -class UserEventHandler : public EventHandlerWrap { -public: - UserEventHandler( - const std::shared_ptr &taskHandler, const std::weak_ptr &owner) {} - - virtual ~UserEventHandler() {} - - static constexpr uint32_t EVENT_SYSTEM_USER_START = 10; - static constexpr uint32_t EVENT_SYSTEM_USER_CURRENT = 20; - static constexpr uint32_t EVENT_REPORT_USER_SWITCH = 30; - static constexpr uint32_t EVENT_CONTINUE_USER_SWITCH = 40; - static constexpr uint32_t EVENT_USER_SWITCH_TIMEOUT = 50; - static constexpr uint32_t EVENT_REPORT_USER_SWITCH_DONE = 60; - - void ProcessEvent(const EventWrap &event) override {} -}; -} // namespace AAFwk -} // namespace OHOS -#endif // OHOS_ABILITY_RUNTIME_USER_EVENT_HANDLER_H diff --git a/test/new_test/unit_test/user_controller_unit_test/BUILD.gn b/test/new_test/unit_test/user_controller_unit_test/BUILD.gn index d7c3f2d7c81248371e1c4f6236dc3f2176b5e11c..098147631dc404dc18f8408dc6cf7726cdf7d1c1 100644 --- a/test/new_test/unit_test/user_controller_unit_test/BUILD.gn +++ b/test/new_test/unit_test/user_controller_unit_test/BUILD.gn @@ -18,17 +18,17 @@ module_output_path = "ability_runtime/user_controller" copy("user_controller_copy") { sources = [ - "${ability_runtime_path}/services/abilitymgr/include/user_controller.h", - "${ability_runtime_path}/services/abilitymgr/src/user_controller.cpp", + "${ability_runtime_path}/services/common/include/user_controller/user_controller.h", + "${ability_runtime_path}/services/common/src/user_controller/user_controller.cpp", ] - outputs = [ "${target_gen_dir}/services/abilitymgr/src/user_controller/{{source_file_part}}" ] + outputs = [ "${target_gen_dir}/services/common/src/user_controller/{{source_file_part}}" ] } ohos_unittest("user_controller_unit_test") { module_out_path = module_output_path include_dirs = [ - "${target_gen_dir}/services/abilitymgr/src/user_controller", + "${target_gen_dir}/services/common/src/user_controller", "../../mock_utils", "../../mock/ability_info", "../../mock/ability_manager_errors", @@ -40,10 +40,12 @@ ohos_unittest("user_controller_unit_test") { "../../mock/application_info", "../../mock/bundle_info", "../../mock/configuration", + "../../mock/dispaly_util", "../../mock/element_name", "../../mock/event_handler_wrap", "../../mock/extension_ability_info", "../../mock/hilog_tag_wrapper", + "../../mock/ipc_skeleton", "../../mock/iremote_broker", "../../mock/iremote_object", "../../mock/last_exit_detail_info", @@ -59,14 +61,13 @@ ohos_unittest("user_controller_unit_test") { "../../mock/task_handler_wrap", "../../mock/task_utils_wrap", "../../mock/uri", - "../../mock/user_event_handler", "../../mock/user_callback", "../../mock/want", "../../mock/want_params", ] sources = - [ "${target_gen_dir}/services/abilitymgr/src/user_controller/user_controller.cpp" ] + [ "${target_gen_dir}/services/common/src/user_controller/user_controller.cpp" ] sources += [ "user_controller_unit_test.cpp", diff --git a/test/new_test/unit_test/user_controller_unit_test/user_controller_unit_test.cpp b/test/new_test/unit_test/user_controller_unit_test/user_controller_unit_test.cpp index 1ca61ede91122cd51b7561498bb698ad939b6d38..68ec3ca3a48ba620da4b90bbc569ee5989c49bd3 100644 --- a/test/new_test/unit_test/user_controller_unit_test/user_controller_unit_test.cpp +++ b/test/new_test/unit_test/user_controller_unit_test/user_controller_unit_test.cpp @@ -31,7 +31,7 @@ using namespace testing::ext; namespace OHOS { -namespace AppExecFwk { +namespace AbilityRuntime { class UserControllerTest : public testing::Test { public: static void SetUpTestCase(); @@ -40,854 +40,10 @@ public: void TearDown() override; }; -void UserControllerTest::SetUpTestCase() -{} - -void UserControllerTest::TearDownTestCase() -{} - -void UserControllerTest::SetUp() -{} - -void UserControllerTest::TearDown() -{} - -/** - * @tc.name: UserItem_GetUserId_001 - * @tc.desc: Verify UserItem GetUserId call. - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, UserItem_GetUserId_001, TestSize.Level1) -{ - int32_t expectUserId = 101; - std::shared_ptr userItem = std::make_shared(expectUserId); - EXPECT_EQ(userItem->GetUserId(), expectUserId); -} - -/** - * @tc.name: UserItem_SetState_001 - * @tc.desc: Verify UserItem SetState call. - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, UserItem_SetState_001, TestSize.Level1) -{ - AAFwk::UserState userState = AAFwk::UserState::STATE_BOOTING; - int32_t userId = 101; - std::shared_ptr userItem = std::make_shared(userId); - userItem->SetState(userState); - EXPECT_EQ(userItem->curState_, AAFwk::UserState::STATE_BOOTING); - EXPECT_EQ(userItem->lastState_, AAFwk::UserState::STATE_BOOTING); -} - -/** - * @tc.name: UserItem_SetState_002 - * @tc.desc: Verify UserItem SetState call. - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, UserItem_SetState_002, TestSize.Level1) -{ - AAFwk::UserState userState = AAFwk::UserState::STATE_STARTED; - int32_t userId = 101; - std::shared_ptr userItem = std::make_shared(userId); - userItem->SetState(userState); - EXPECT_EQ(userItem->curState_, AAFwk::UserState::STATE_STARTED); - EXPECT_EQ(userItem->lastState_, AAFwk::UserState::STATE_BOOTING); -} - -/** - * @tc.name: UserItem_GetState_001 - * @tc.desc: Verify UserItem GetState call. - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, UserItem_GetState_001, TestSize.Level1) -{ - AAFwk::UserState userState = AAFwk::UserState::STATE_STARTED; - int32_t userId = 101; - std::shared_ptr userItem = std::make_shared(userId); - userItem->SetState(userState); - EXPECT_EQ(userItem->GetState(), AAFwk::UserState::STATE_STARTED); -} - -/** - * @tc.name: Init_001 - * @tc.desc: Verify Init call. - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, Init_001, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - std::shared_ptr handler = nullptr; - OH_EXPECT_RET({handler}, AbilityManagerService, GetTaskHandler); - controller->Init(); - EXPECT_EQ(controller->eventHandler_, nullptr); -} - -/** - * @tc.name: Init_002 - * @tc.desc: Verify Init call. - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, Init_002, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - std::shared_ptr handler = std::make_shared(); - OH_EXPECT_RET({handler}, AbilityManagerService, GetTaskHandler); - controller->Init(); - EXPECT_NE(controller->eventHandler_, nullptr); -} - -/** - * @tc.name: Init_003 - * @tc.desc: Verify Init call. - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, Init_003, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - std::shared_ptr handler = std::make_shared(); - OH_EXPECT_RET({handler}, AbilityManagerService, GetTaskHandler); - controller->eventHandler_ = std::make_shared(handler, controller); - controller->Init(); - EXPECT_NE(controller->eventHandler_, nullptr); -} - -/** - * @tc.name: ClearAbilityUserItems_001 - * @tc.desc: Verify ClearAbilityUserItems call. - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, ClearAbilityUserItems_001, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - int32_t userId = 101; - std::shared_ptr userItem = std::make_shared(userId); - controller->userItems_.insert({0, userItem}); - controller->ClearAbilityUserItems(0); - EXPECT_EQ(controller->userItems_.size(), 0); -} - -/** - * @tc.name: ClearAbilityUserItems_002 - * @tc.desc: Verify ClearAbilityUserItems call. - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, ClearAbilityUserItems_002, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - int32_t userId = 101; - std::shared_ptr userItem = std::make_shared(userId); - controller->userItems_.insert({0, userItem}); - controller->ClearAbilityUserItems(1); - EXPECT_EQ(controller->userItems_.size(), 1); -} - -/** - * @tc.name: StartUser_001 - * @tc.desc: Verify StartUser call. - * Branch userId < 0 && callback == nullptr - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, StartUser_001, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - int32_t userId = -1; - sptr callback = nullptr; - bool isAppRecovery = 0; - EXPECT_EQ(controller->StartUser(userId, callback, isAppRecovery), AAFwk::INVALID_USERID_VALUE); -} - -/** - * @tc.name: StartUser_002 - * @tc.desc: Verify StartUser call. - * Branch userId < 0 && callback != nullptr - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, StartUser_002, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - int32_t userId = -1; - sptr callback = sptr::MakeSptr(); - bool isAppRecovery = 0; - EXPECT_EQ(controller->StartUser(userId, callback, isAppRecovery), AAFwk::INVALID_USERID_VALUE); -} - -/** - * @tc.name: StartUser_003 - * @tc.desc: Verify StartUser call. - * Branch userId == USER_ID_NO_HEAD && callback == nullptr - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, StartUser_003, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - int32_t userId = AAFwk::USER_ID_NO_HEAD; - sptr callback = nullptr; - bool isAppRecovery = 0; - EXPECT_EQ(controller->StartUser(userId, callback, isAppRecovery), AAFwk::INVALID_USERID_VALUE); -} - -/** - * @tc.name: StartUser_004 - * @tc.desc: Verify StartUser call. - * Branch userId == USER_ID_NO_HEAD && callback != nullptr - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, StartUser_004, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - int32_t userId = AAFwk::USER_ID_NO_HEAD; - sptr callback = sptr::MakeSptr(); - bool isAppRecovery = 0; - EXPECT_EQ(controller->StartUser(userId, callback, isAppRecovery), AAFwk::INVALID_USERID_VALUE); -} - -/** - * @tc.name: StartUser_005 - * @tc.desc: Verify StartUser call. - * Branch IsCurrentUser == true && callback == nullptr - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, StartUser_005, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 101; - int32_t userId = 101; - std::shared_ptr userItem = std::make_shared(userId); - controller->userItems_.insert({101, userItem}); - sptr callback = nullptr; - bool isAppRecovery = 0; - EXPECT_EQ(controller->StartUser(userId, callback, isAppRecovery), ERR_OK); -} - -/** - * @tc.name: StartUser_006 - * @tc.desc: Verify StartUser call. - * Branch IsCurrentUser == true && callback != nullptr - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, StartUser_006, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 101; - int32_t userId = 101; - std::shared_ptr userItem = std::make_shared(userId); - controller->userItems_.insert({101, userItem}); - sptr callback = sptr::MakeSptr(); - bool isAppRecovery = 0; - EXPECT_EQ(controller->StartUser(userId, callback, isAppRecovery), ERR_OK); -} - -/** - * @tc.name: StartUser_007 - * @tc.desc: Verify StartUser call. - * Branch IsExistOsAccount == false && callback == nullptr - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, StartUser_007, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 100; - int32_t userId = 101; - std::shared_ptr userItem = std::make_shared(userId); - controller->userItems_.insert({101, userItem}); - sptr callback = nullptr; - bool isAppRecovery = 0; - std::vector> expectOuter = {{false}}; - OH_EXPECT_RET_AND_OUTPUT({0}, expectOuter, OsAccountManagerWrapper, - IsOsAccountExists, const int, bool& isOsAccountExists); - EXPECT_EQ(controller->StartUser(userId, callback, isAppRecovery), AAFwk::INVALID_USERID_VALUE); -} - -/** - * @tc.name: StartUser_008 - * @tc.desc: Verify StartUser call. - * Branch IsExistOsAccount == false && callback != nullptr - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, StartUser_008, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 100; - int32_t userId = 101; - std::shared_ptr userItem = std::make_shared(userId); - controller->userItems_.insert({101, userItem}); - sptr callback = sptr::MakeSptr(); - bool isAppRecovery = 0; - std::vector> expectOuter = {{false}}; - OH_EXPECT_RET_AND_OUTPUT({0}, expectOuter, OsAccountManagerWrapper, - IsOsAccountExists, const int, bool& isOsAccountExists); - EXPECT_EQ(controller->StartUser(userId, callback, isAppRecovery), AAFwk::INVALID_USERID_VALUE); -} - -/** - * @tc.name: StartUser_009 - * @tc.desc: Verify StartUser call. - * Branch GetCurrentUserId() != USER_ID_NO_HEAD && IsSceneBoardEnabled() == false - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, StartUser_009, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 100; - controller->freezingNewUserId_ = 0; - int32_t userId = 101; - std::shared_ptr userItem = std::make_shared(userId); - controller->userItems_.insert({userId, userItem}); - sptr callback = sptr::MakeSptr(); - bool isAppRecovery = 0; - std::vector> expectOuter = {{true}}; - OH_EXPECT_RET_AND_OUTPUT({0}, expectOuter, OsAccountManagerWrapper, - IsOsAccountExists, const int, bool& isOsAccountExists); - OH_EXPECT_RET({false}, SceneBoardJudgement, IsSceneBoardEnabled); - EXPECT_EQ(controller->StartUser(userId, callback, isAppRecovery), ERR_OK); - EXPECT_EQ(controller->freezingNewUserId_, 101); -} - -/** - * @tc.name: StartUser_010 - * @tc.desc: Verify StartUser call. - * Branch GetCurrentUserId() == USER_ID_NO_HEAD && IsSceneBoardEnabled() == false - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, StartUser_010, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 0; - controller->freezingNewUserId_ = 0; - int32_t userId = 101; - std::shared_ptr userItem = std::make_shared(userId); - controller->userItems_.insert({userId, userItem}); - sptr callback = sptr::MakeSptr(); - bool isAppRecovery = 0; - std::vector> expectOuter = {{true}}; - OH_EXPECT_RET_AND_OUTPUT({0}, expectOuter, OsAccountManagerWrapper, - IsOsAccountExists, const int, bool& isOsAccountExists); - OH_EXPECT_RET({false}, SceneBoardJudgement, IsSceneBoardEnabled); - EXPECT_EQ(controller->StartUser(userId, callback, isAppRecovery), ERR_OK); - EXPECT_EQ(controller->freezingNewUserId_, 0); -} - -/** - * @tc.name: StartUser_011 - * @tc.desc: Verify StartUser call. - * Branch GetCurrentUserId() != USER_ID_NO_HEAD && IsSceneBoardEnabled() == true - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, StartUser_011, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 100; - controller->freezingNewUserId_ = 0; - int32_t userId = 101; - std::shared_ptr userItem = std::make_shared(userId); - controller->userItems_.insert({userId, userItem}); - sptr callback = sptr::MakeSptr(); - bool isAppRecovery = 0; - std::vector> expectOuter = {{true}}; - OH_EXPECT_RET_AND_OUTPUT({0}, expectOuter, OsAccountManagerWrapper, - IsOsAccountExists, const int, bool& isOsAccountExists); - OH_EXPECT_RET({true}, SceneBoardJudgement, IsSceneBoardEnabled); - EXPECT_EQ(controller->StartUser(userId, callback, isAppRecovery), ERR_OK); - EXPECT_EQ(controller->freezingNewUserId_, 0); -} - -/** - * @tc.name: StartUser_012 - * @tc.desc: Verify StartUser call. - * Branch GetCurrentUserId() == USER_ID_NO_HEAD && IsSceneBoardEnabled() == true - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, StartUser_012, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 0; - controller->freezingNewUserId_ = 0; - int32_t userId = 101; - std::shared_ptr userItem = std::make_shared(userId); - controller->userItems_.insert({userId, userItem}); - sptr callback = sptr::MakeSptr(); - bool isAppRecovery = 0; - std::vector> expectOuter = {{true}}; - OH_EXPECT_RET_AND_OUTPUT({0}, expectOuter, OsAccountManagerWrapper, - IsOsAccountExists, const int, bool& isOsAccountExists); - OH_EXPECT_RET({true}, SceneBoardJudgement, IsSceneBoardEnabled); - EXPECT_EQ(controller->StartUser(userId, callback, isAppRecovery), ERR_OK); - EXPECT_EQ(controller->freezingNewUserId_, 0); -} - -/** - * @tc.name: StartUser_013 - * @tc.desc: Verify StartUser call. - * Branch state == STATE_STOPPING && callback != nullptr - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, StartUser_013, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 100; - int32_t userId = 101; - std::shared_ptr userItem = std::make_shared(userId); - userItem->SetState(AAFwk::STATE_STOPPING); - controller->userItems_.insert({userId, userItem}); - sptr callback = sptr::MakeSptr(); - bool isAppRecovery = 0; - std::vector> expectOuter = {{true}}; - OH_EXPECT_RET_AND_OUTPUT({0}, expectOuter, OsAccountManagerWrapper, - IsOsAccountExists, const int, bool& isOsAccountExists); - EXPECT_EQ(controller->StartUser(userId, callback, isAppRecovery), ERR_DEAD_OBJECT); -} - -/** - * @tc.name: StartUser_014 - * @tc.desc: Verify StartUser call. - * Branch state == STATE_STOPPING && callback == nullptr - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, StartUser_014, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 100; - int32_t userId = 101; - std::shared_ptr userItem = std::make_shared(userId); - userItem->SetState(AAFwk::STATE_STOPPING); - controller->userItems_.insert({userId, userItem}); - sptr callback = nullptr; - bool isAppRecovery = 0; - std::vector> expectOuter = {{true}}; - OH_EXPECT_RET_AND_OUTPUT({0}, expectOuter, OsAccountManagerWrapper, - IsOsAccountExists, const int, bool& isOsAccountExists); - EXPECT_EQ(controller->StartUser(userId, callback, isAppRecovery), ERR_DEAD_OBJECT); -} - -/** - * @tc.name: StartUser_015 - * @tc.desc: Verify StartUser call. - * Branch state == STATE_SHUTDOWN && callback != nullptr - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, StartUser_015, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 100; - int32_t userId = 101; - std::shared_ptr userItem = std::make_shared(userId); - userItem->SetState(AAFwk::STATE_SHUTDOWN); - controller->userItems_.insert({userId, userItem}); - sptr callback = sptr::MakeSptr(); - bool isAppRecovery = 0; - std::vector> expectOuter = {{true}}; - OH_EXPECT_RET_AND_OUTPUT({0}, expectOuter, OsAccountManagerWrapper, - IsOsAccountExists, const int, bool& isOsAccountExists); - EXPECT_EQ(controller->StartUser(userId, callback, isAppRecovery), ERR_DEAD_OBJECT); -} - -/** - * @tc.name: StartUser_016 - * @tc.desc: Verify StartUser call. - * Branch state == STATE_SHUTDOWN && callback == nullptr - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, StartUser_016, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 100; - int32_t userId = 101; - std::shared_ptr userItem = std::make_shared(userId); - userItem->SetState(AAFwk::STATE_SHUTDOWN); - controller->userItems_.insert({userId, userItem}); - sptr callback = nullptr; - bool isAppRecovery = 0; - std::vector> expectOuter = {{true}}; - OH_EXPECT_RET_AND_OUTPUT({0}, expectOuter, OsAccountManagerWrapper, - IsOsAccountExists, const int, bool& isOsAccountExists); - EXPECT_EQ(controller->StartUser(userId, callback, isAppRecovery), ERR_DEAD_OBJECT); -} - -/** - * @tc.name: StartUser_017 - * @tc.desc: Verify StartUser call. - * Branch state == STATE_BOOTING - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, StartUser_017, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 100; - int32_t userId = 101; - std::shared_ptr userItem = std::make_shared(userId); - userItem->SetState(AAFwk::STATE_BOOTING); - controller->userItems_.insert({userId, userItem}); - sptr callback = nullptr; - bool isAppRecovery = 0; - std::vector> expectOuter = {{true}}; - OH_EXPECT_RET_AND_OUTPUT({0}, expectOuter, OsAccountManagerWrapper, - IsOsAccountExists, const int, bool& isOsAccountExists); - EXPECT_NE(controller->StartUser(userId, callback, isAppRecovery), ERR_DEAD_OBJECT); - EXPECT_EQ(controller->currentUserId_, 101); -} - -/** - * @tc.name: StopUser_001 - * @tc.desc: Verify StopUser call. - * Branch userId < 0 - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, StopUser_001, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - int32_t userId = -1; - EXPECT_EQ(controller->StopUser(userId), -1); -} - -/** - * @tc.name: StopUser_002 - * @tc.desc: Verify StopUser call. - * Branch userId == USER_ID_NO_HEAD - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, StopUser_002, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - int32_t userId = AAFwk::USER_ID_NO_HEAD; - EXPECT_EQ(controller->StopUser(userId), -1); -} - -/** - * @tc.name: StopUser_003 - * @tc.desc: Verify StopUser call. - * Branch userId == USER_ID_DEFAULT - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, StopUser_003, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - int32_t userId = AAFwk::USER_ID_DEFAULT; - EXPECT_EQ(controller->StopUser(userId), -1); -} - -/** - * @tc.name: StopUser_004 - * @tc.desc: Verify StopUser call. - * Branch IsCurrentUser == true - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, StopUser_004, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 101; - int32_t userId = 101; - std::shared_ptr userItem = std::make_shared(userId); - controller->userItems_.insert({userId, userItem}); - EXPECT_EQ(controller->StopUser(userId), 0); -} - -/** - * @tc.name: StopUser_005 - * @tc.desc: Verify StopUser call. - * Branch IsExistOsAccount == false - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, StopUser_005, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 100; - int32_t userId = 101; - std::vector> expectOuter = {{false}}; - OH_EXPECT_RET_AND_OUTPUT({0}, expectOuter, OsAccountManagerWrapper, - IsOsAccountExists, const int, bool& isOsAccountExists); - EXPECT_EQ(controller->StopUser(userId), -1); -} - -/** - * @tc.name: StopUser_006 - * @tc.desc: Verify StopUser call. - * Branch IsSceneBoardEnabled == false && GetMissionListWrap == nullptr - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, StopUser_006, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 100; - int32_t userId = 101; - std::vector> expectOuter = {{true}}; - OH_EXPECT_RET_AND_OUTPUT({0}, expectOuter, OsAccountManagerWrapper, - IsOsAccountExists, const int, bool& isOsAccountExists); - OH_EXPECT_RET({false}, SceneBoardJudgement, IsSceneBoardEnabled); - std::shared_ptr wrap = nullptr; - OH_EXPECT_RET({wrap}, AbilityManagerService, GetMissionListWrap); - EXPECT_EQ(controller->StopUser(userId), -1); -} - -/** - * @tc.name: StopUser_007 - * @tc.desc: Verify StopUser call. - * Branch IsSceneBoardEnabled == false && GetMissionListWrap != nullptr - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, StopUser_007, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 100; - int32_t userId = 101; - std::vector> expectOuter = {{true}}; - OH_EXPECT_RET_AND_OUTPUT({0}, expectOuter, OsAccountManagerWrapper, - IsOsAccountExists, const int, bool& isOsAccountExists); - OH_EXPECT_RET({false}, SceneBoardJudgement, IsSceneBoardEnabled); - std::shared_ptr wrap = std::make_shared(); - OH_EXPECT_RET({wrap}, AbilityManagerService, GetMissionListWrap); - EXPECT_EQ(controller->StopUser(userId), 0); -} - -/** - * @tc.name: StopUser_008 - * @tc.desc: Verify StopUser call. - * Branch IsSceneBoardEnabled == true && GetMissionListWrap == nullptr - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, StopUser_008, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 100; - int32_t userId = 101; - std::vector> expectOuter = {{true}}; - OH_EXPECT_RET_AND_OUTPUT({0}, expectOuter, OsAccountManagerWrapper, - IsOsAccountExists, const int, bool& isOsAccountExists); - OH_EXPECT_RET({true}, SceneBoardJudgement, IsSceneBoardEnabled); - std::shared_ptr wrap = nullptr; - OH_EXPECT_RET({wrap}, AbilityManagerService, GetMissionListWrap); - EXPECT_EQ(controller->StopUser(userId), 0); -} - -/** - * @tc.name: StopUser_009 - * @tc.desc: Verify StopUser call. - * Branch IsSceneBoardEnabled == true && GetMissionListWrap != nullptr - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, StopUser_009, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 100; - int32_t userId = 101; - std::vector> expectOuter = {{true}}; - OH_EXPECT_RET_AND_OUTPUT({0}, expectOuter, OsAccountManagerWrapper, - IsOsAccountExists, const int, bool& isOsAccountExists); - OH_EXPECT_RET({true}, SceneBoardJudgement, IsSceneBoardEnabled); - std::shared_ptr wrap = std::make_shared(); - OH_EXPECT_RET({wrap}, AbilityManagerService, GetMissionListWrap); - EXPECT_EQ(controller->StopUser(userId), 0); -} - -/** - * @tc.name: LogoutUser_001 - * @tc.desc: Verify LogoutUser call. - * Branch userId < 0 && callback == nullptr - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, LogoutUser_001, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - int32_t userId = -1; - sptr callback = nullptr; - EXPECT_EQ(controller->LogoutUser(userId, callback), AAFwk::INVALID_USERID_VALUE); -} - -/** - * @tc.name: LogoutUser_002 - * @tc.desc: Verify LogoutUser call. - * Branch userId == USER_ID_NO_HEAD && callback == nullptr - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, LogoutUser_002, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - int32_t userId = AAFwk::USER_ID_NO_HEAD; - sptr callback = nullptr; - EXPECT_EQ(controller->LogoutUser(userId, callback), AAFwk::INVALID_USERID_VALUE); -} - -/** - * @tc.name: LogoutUser_003 - * @tc.desc: Verify LogoutUser call. - * Branch userId < 0 && callback == nullptr - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, LogoutUser_003, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - int32_t userId = -1; - sptr callback = sptr::MakeSptr(); - EXPECT_EQ(controller->LogoutUser(userId, callback), AAFwk::INVALID_USERID_VALUE); -} - -/** - * @tc.name: LogoutUser_004 - * @tc.desc: Verify LogoutUser call. - * Branch userId == USER_ID_NO_HEAD && callback == nullptr - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, LogoutUser_004, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - int32_t userId = AAFwk::USER_ID_NO_HEAD; - sptr callback = sptr::MakeSptr(); - EXPECT_EQ(controller->LogoutUser(userId, callback), AAFwk::INVALID_USERID_VALUE); -} - -/** - * @tc.name: LogoutUser_005 - * @tc.desc: Verify LogoutUser call. - * Branch IsExistOsAccount == false && callback == nullptr - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, LogoutUser_005, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 100; - int32_t userId = 101; - sptr callback = nullptr; - std::vector> expectOuter = {{false}}; - OH_EXPECT_RET_AND_OUTPUT({0}, expectOuter, OsAccountManagerWrapper, - IsOsAccountExists, const int, bool& isOsAccountExists); - EXPECT_EQ(controller->LogoutUser(userId, callback), AAFwk::INVALID_USERID_VALUE); -} - -/** - * @tc.name: LogoutUser_006 - * @tc.desc: Verify LogoutUser call. - * Branch IsExistOsAccount == false && callback != nullptr - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, LogoutUser_006, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 100; - int32_t userId = 101; - sptr callback = sptr::MakeSptr(); - std::vector> expectOuter = {{false}}; - OH_EXPECT_RET_AND_OUTPUT({0}, expectOuter, OsAccountManagerWrapper, - IsOsAccountExists, const int, bool& isOsAccountExists); - EXPECT_EQ(controller->LogoutUser(userId, callback), AAFwk::INVALID_USERID_VALUE); -} - -/** - * @tc.name: LogoutUser_007 - * @tc.desc: Verify LogoutUser call. - * Branch IsSceneBoardEnabled == true - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, LogoutUser_007, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 100; - int32_t userId = 101; - sptr callback = sptr::MakeSptr(); - std::vector> expectOuter = {{true}}; - OH_EXPECT_RET_AND_OUTPUT({0}, expectOuter, OsAccountManagerWrapper, - IsOsAccountExists, const int, bool& isOsAccountExists); - OH_EXPECT_RET({true}, SceneBoardJudgement, IsSceneBoardEnabled); - EXPECT_EQ(controller->LogoutUser(userId, callback), 0); - EXPECT_LOG_MATCH(LOG_INFO, AAFwkTag::ABILITYMGR, "user_controller.cpp", "SceneBoard exit normally."); -} - -/** - * @tc.name: LogoutUser_008 - * @tc.desc: Verify LogoutUser call. - * Branch IsSceneBoardEnabled == false - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, LogoutUser_008, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 100; - int32_t userId = 101; - sptr callback = sptr::MakeSptr(); - std::vector> expectOuter = {{true}}; - OH_EXPECT_RET_AND_OUTPUT({0}, expectOuter, OsAccountManagerWrapper, - IsOsAccountExists, const int, bool& isOsAccountExists); - OH_EXPECT_RET({false}, SceneBoardJudgement, IsSceneBoardEnabled); - EXPECT_EQ(controller->LogoutUser(userId, callback), 0); -} - -/** - * @tc.name: LogoutUser_009 - * @tc.desc: Verify LogoutUser call. - * Branch IsSceneBoardEnabled == true - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, LogoutUser_009, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 100; - int32_t userId = 100; - sptr callback = sptr::MakeSptr(); - std::vector> expectOuter = {{true}}; - OH_EXPECT_RET_AND_OUTPUT({0}, expectOuter, OsAccountManagerWrapper, - IsOsAccountExists, const int, bool& isOsAccountExists); - std::shared_ptr userItem = std::make_shared(userId); - controller->userItems_.insert({userId, userItem}); - EXPECT_EQ(controller->LogoutUser(userId, callback), 0); - EXPECT_EQ(controller->currentUserId_, 0); -} - -/** - * @tc.name: LogoutUser_010 - * @tc.desc: Verify LogoutUser call. - * Branch IsSceneBoardEnabled == true - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, LogoutUser_010, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 100; - int32_t userId = 101; - sptr callback = sptr::MakeSptr(); - std::vector> expectOuter = {{true}}; - OH_EXPECT_RET_AND_OUTPUT({0}, expectOuter, OsAccountManagerWrapper, - IsOsAccountExists, const int, bool& isOsAccountExists); - std::shared_ptr userItem = std::make_shared(userId); - controller->userItems_.insert({userId, userItem}); - EXPECT_EQ(controller->LogoutUser(userId, callback), 0); - EXPECT_EQ(controller->currentUserId_, 100); -} - -/** - * @tc.name: GetCurrentUserId_001 - * @tc.desc: Verify GetCurrentUserId call. - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, GetCurrentUserId_001, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 100; - EXPECT_EQ(controller->GetCurrentUserId(), 100); -} - -/** - * @tc.name: GetUserItem_001 - * @tc.desc: Verify GetUserItem call. - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, GetUserItem_001, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - int32_t userId = 100; - std::shared_ptr userItem = std::make_shared(userId); - controller->userItems_.insert({userId, userItem}); - EXPECT_EQ(controller->GetUserItem(userId), userItem); -} - -/** - * @tc.name: GetUserItem_002 - * @tc.desc: Verify GetUserItem call. - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, GetUserItem_002, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - int32_t userId = 100; - EXPECT_EQ(controller->GetUserItem(userId), nullptr); -} +void UserControllerTest::SetUpTestCase() {} +void UserControllerTest::TearDownTestCase() {} +void UserControllerTest::SetUp() {} +void UserControllerTest::TearDown() {} /** * @tc.name: IsExistOsAccount_001 @@ -897,7 +53,7 @@ HWTEST_F(UserControllerTest, GetUserItem_002, TestSize.Level1) */ HWTEST_F(UserControllerTest, IsExistOsAccount_001, TestSize.Level1) { - std::shared_ptr controller = std::make_shared(); + std::shared_ptr controller = std::make_shared(); int32_t userId = 100; std::vector> expectOuter = {{true}}; OH_EXPECT_RET_AND_OUTPUT({0}, expectOuter, OsAccountManagerWrapper, @@ -913,7 +69,7 @@ HWTEST_F(UserControllerTest, IsExistOsAccount_001, TestSize.Level1) */ HWTEST_F(UserControllerTest, IsExistOsAccount_002, TestSize.Level1) { - std::shared_ptr controller = std::make_shared(); + std::shared_ptr controller = std::make_shared(); int32_t userId = 100; std::vector> expectOuter = {{true}}; OH_EXPECT_RET_AND_OUTPUT({1}, expectOuter, OsAccountManagerWrapper, @@ -929,7 +85,7 @@ HWTEST_F(UserControllerTest, IsExistOsAccount_002, TestSize.Level1) */ HWTEST_F(UserControllerTest, IsExistOsAccount_003, TestSize.Level1) { - std::shared_ptr controller = std::make_shared(); + std::shared_ptr controller = std::make_shared(); int32_t userId = 100; std::vector> expectOuter = {{false}}; OH_EXPECT_RET_AND_OUTPUT({0}, expectOuter, OsAccountManagerWrapper, @@ -945,7 +101,7 @@ HWTEST_F(UserControllerTest, IsExistOsAccount_003, TestSize.Level1) */ HWTEST_F(UserControllerTest, IsExistOsAccount_004, TestSize.Level1) { - std::shared_ptr controller = std::make_shared(); + std::shared_ptr controller = std::make_shared(); int32_t userId = 100; std::vector> expectOuter = {{false}}; OH_EXPECT_RET_AND_OUTPUT({1}, expectOuter, OsAccountManagerWrapper, @@ -953,32 +109,6 @@ HWTEST_F(UserControllerTest, IsExistOsAccount_004, TestSize.Level1) EXPECT_EQ(controller->IsExistOsAccount(userId), false); } -/** - * @tc.name: GetOrCreateUserItem_001 - * @tc.desc: Verify GetOrCreateUserItem call. - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, GetOrCreateUserItem_001, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - int32_t userId = 100; - std::shared_ptr userItem = std::make_shared(userId); - controller->userItems_.insert({userId, userItem}); - EXPECT_EQ(controller->GetOrCreateUserItem(userId), userItem); -} - -/** - * @tc.name: GetOrCreateUserItem_002 - * @tc.desc: Verify GetOrCreateUserItem call. - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, GetOrCreateUserItem_002, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - int32_t userId = 100; - EXPECT_NE(controller->GetOrCreateUserItem(userId), nullptr); -} - /** * @tc.name: SetCurrentUserId_001 * @tc.desc: Verify SetCurrentUserId call. @@ -986,492 +116,13 @@ HWTEST_F(UserControllerTest, GetOrCreateUserItem_002, TestSize.Level1) */ HWTEST_F(UserControllerTest, SetCurrentUserId_001, TestSize.Level1) { - std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 100; - int32_t userId = 101; - controller->SetCurrentUserId(userId); - EXPECT_EQ(controller->currentUserId_, 101); -} - -/** - * @tc.name: MoveUserToForeground_001 - * @tc.desc: Verify MoveUserToForeground call. - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, MoveUserToForeground_001, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 100; - int32_t userId = 101; - OH_EXPECT_RET({0}, AbilityManagerService, SwitchToUser, int32_t, int32_t, - sptr, bool isAppRecovery = false); - int32_t oldUserId = 100; - int32_t newUserId = 101; - sptr callback = nullptr; - bool isAppRecovery = false; - EXPECT_EQ(controller->MoveUserToForeground(oldUserId, newUserId, callback, isAppRecovery), ERR_OK); -} - -/** - * @tc.name: MoveUserToForeground_002 - * @tc.desc: Verify MoveUserToForeground call. - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, MoveUserToForeground_002, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 100; - int32_t userId = 101; - OH_EXPECT_RET({1}, AbilityManagerService, SwitchToUser, int32_t, int32_t, - sptr, bool isAppRecovery = false); - int32_t oldUserId = 100; - int32_t newUserId = 101; - sptr callback = nullptr; - bool isAppRecovery = false; - EXPECT_EQ(controller->MoveUserToForeground(oldUserId, newUserId, callback, isAppRecovery), 1); -} - -/** - * @tc.name: UserBootDone_001 - * @tc.desc: Verify UserBootDone call. - * Branch item == nullptr - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, UserBootDone_001, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - std::shared_ptr item = nullptr; - controller->UserBootDone(item); - EXPECT_LOG_MATCH(LOG_ERROR, AAFwkTag::ABILITYMGR, "user_controller.cpp", "null item"); -} - -/** - * @tc.name: UserBootDone_002 - * @tc.desc: Verify UserBootDone call. - * Branch userId invalid - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, UserBootDone_002, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - std::shared_ptr item = std::make_shared(101); - AAFwk::UserState userState = AAFwk::UserState::STATE_BOOTING; - item->SetState(userState); - controller->UserBootDone(item); - EXPECT_EQ(item->GetState(), AAFwk::UserState::STATE_BOOTING); -} - -/** - * @tc.name: UserBootDone_003 - * @tc.desc: Verify UserBootDone call. - * Branch item not match - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, UserBootDone_003, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - std::shared_ptr item1 = std::make_shared(101); - std::shared_ptr item2 = std::make_shared(101); - controller->userItems_.insert({101, item2}); - AAFwk::UserState userState = AAFwk::UserState::STATE_BOOTING; - item1->SetState(userState); - controller->UserBootDone(item1); - EXPECT_EQ(item1->GetState(), AAFwk::UserState::STATE_BOOTING); -} - -/** - * @tc.name: UserBootDone_004 - * @tc.desc: Verify UserBootDone call. - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, UserBootDone_004, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - std::shared_ptr item = std::make_shared(101); - controller->userItems_.insert({101, item}); - AAFwk::UserState userState = AAFwk::UserState::STATE_BOOTING; - item->SetState(userState); - controller->UserBootDone(item); - EXPECT_EQ(item->GetState(), AAFwk::UserState::STATE_STARTED); -} - -/** - * @tc.name: BroadcastUserBackground_001 - * @tc.desc: Verify BroadcastUserBackground call. - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, BroadcastUserBackground_001, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->BroadcastUserBackground(100); - EXPECT_LOG_MATCH(LOG_DEBUG, AAFwkTag::ABILITYMGR, "user_controller.cpp", "user background"); -} - -/** - * @tc.name: BroadcastUserForeground_001 - * @tc.desc: Verify BroadcastUserForeground call. - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, BroadcastUserForeground_001, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->BroadcastUserForeground(100); - EXPECT_LOG_MATCH(LOG_DEBUG, AAFwkTag::ABILITYMGR, "user_controller.cpp", "user foreground"); -} - -/** - * @tc.name: BroadcastUserStopping_001 - * @tc.desc: Verify BroadcastUserStopping call. - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, BroadcastUserStopping_001, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->BroadcastUserStopping(100); - EXPECT_LOG_MATCH(LOG_DEBUG, AAFwkTag::ABILITYMGR, "user_controller.cpp", "user stopping"); -} - -/** - * @tc.name: BroadcastUserStopped_001 - * @tc.desc: Verify BroadcastUserStopped call. - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, BroadcastUserStopped_001, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->BroadcastUserStopped(100); - EXPECT_LOG_MATCH(LOG_DEBUG, AAFwkTag::ABILITYMGR, "user_controller.cpp", "user stopped"); -} - -/** - * @tc.name: SendSystemUserStart_001 - * @tc.desc: Verify SendSystemUserStart call. - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, SendSystemUserStart_001, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->eventHandler_ = std::make_shared(nullptr, controller); - controller->SendSystemUserStart(100); - EXPECT_LOG_MATCH(LOG_DEBUG, AAFwkTag::ABILITYMGR, "user_controller.cpp", "SendEvent(EVENT_SYSTEM_USER_START)"); -} - -/** - * @tc.name: SendSystemUserStart_002 - * @tc.desc: Verify SendSystemUserStart call. - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, SendSystemUserStart_002, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->eventHandler_ = nullptr; - controller->SendSystemUserStart(100); - EXPECT_LOG_MATCH(LOG_ERROR, AAFwkTag::ABILITYMGR, "user_controller.cpp", "null handler"); -} - -/** - * @tc.name: ProcessEvent_001 - * @tc.desc: Verify ProcessEvent call. - * Branch event.GetEventData() == nullptr - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, ProcessEvent_001, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - AAFwk::EventWrap event(0); - std::shared_ptr eventDataBase = nullptr; - OH_EXPECT_RET({eventDataBase}, EventWrap, GetEventData); - controller->ProcessEvent(event); - EXPECT_LOG_MATCH(LOG_DEBUG, AAFwkTag::ABILITYMGR, "user_controller.cpp", "no event data, event id:"); -} - -/** - * @tc.name: ProcessEvent_002 - * @tc.desc: Verify ProcessEvent call. - * Branch event.GetEventId() == UserEventHandler::EVENT_SYSTEM_USER_START - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, ProcessEvent_002, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - AAFwk::EventWrap event(0); - std::shared_ptr userEvent = std::make_shared(); - OH_EXPECT_RET({userEvent}, EventWrap, GetEventData); - OH_EXPECT_RET({AAFwk::UserEventHandler::EVENT_SYSTEM_USER_START}, EventWrap, GetEventId); - controller->ProcessEvent(event); - EXPECT_LOG_MATCH(LOG_DEBUG, AAFwkTag::ABILITYMGR, "user_controller.cpp", "notify system user start."); -} - -/** - * @tc.name: ProcessEvent_003 - * @tc.desc: Verify ProcessEvent call. - * Branch event.GetEventId() == UserEventHandler::EVENT_SYSTEM_USER_CURRENT - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, ProcessEvent_003, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - AAFwk::EventWrap event(0); - std::shared_ptr userEvent = std::make_shared(); - OH_EXPECT_RET({userEvent}, EventWrap, GetEventData); - OH_EXPECT_RET({AAFwk::UserEventHandler::EVENT_SYSTEM_USER_CURRENT}, EventWrap, GetEventId); - controller->ProcessEvent(event); - EXPECT_LOG_MATCH(LOG_DEBUG, AAFwkTag::ABILITYMGR, "user_controller.cpp", "notify system user current."); -} - -/** - * @tc.name: ProcessEvent_004 - * @tc.desc: Verify ProcessEvent call. - * Branch event.GetEventId() == UserEventHandler::EVENT_REPORT_USER_SWITCH - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, ProcessEvent_004, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - AAFwk::EventWrap event(0); - std::shared_ptr userEvent = std::make_shared(); - OH_EXPECT_RET({userEvent}, EventWrap, GetEventData); - OH_EXPECT_RET({AAFwk::UserEventHandler::EVENT_REPORT_USER_SWITCH}, EventWrap, GetEventId); - controller->ProcessEvent(event); - EXPECT_LOG_MATCH(LOG_DEBUG, AAFwkTag::ABILITYMGR, "user_controller.cpp", "notify report user switch."); -} - -/** - * @tc.name: ProcessEvent_005 - * @tc.desc: Verify ProcessEvent call. - * Branch event.GetEventId() == UserEventHandler::EVENT_CONTINUE_USER_SWITCH - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, ProcessEvent_005, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - AAFwk::EventWrap event(0); - std::shared_ptr userEvent = std::make_shared(); - OH_EXPECT_RET({userEvent}, EventWrap, GetEventData); - OH_EXPECT_RET({AAFwk::UserEventHandler::EVENT_CONTINUE_USER_SWITCH}, EventWrap, GetEventId); - controller->ProcessEvent(event); - EXPECT_LOG_MATCH(LOG_ERROR, AAFwkTag::ABILITYMGR, "user_controller.cpp", "null handler"); -} - -/** - * @tc.name: ProcessEvent_006 - * @tc.desc: Verify ProcessEvent call. - * Branch event.GetEventId() == UserEventHandler::EVENT_USER_SWITCH_TIMEOUT - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, ProcessEvent_006, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - AAFwk::EventWrap event(0); - std::shared_ptr userEvent = std::make_shared(); - OH_EXPECT_RET({userEvent}, EventWrap, GetEventData); - OH_EXPECT_RET({AAFwk::UserEventHandler::EVENT_USER_SWITCH_TIMEOUT}, EventWrap, GetEventId); - controller->ProcessEvent(event); - EXPECT_LOG_MATCH(LOG_ERROR, AAFwkTag::ABILITYMGR, "user_controller.cpp", "null handler"); -} - -/** - * @tc.name: ProcessEvent_007 - * @tc.desc: Verify ProcessEvent call. - * Branch event.GetEventId() == UserEventHandler::EVENT_REPORT_USER_SWITCH_DONE - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, ProcessEvent_007, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - AAFwk::EventWrap event(0); - std::shared_ptr userEvent = std::make_shared(); - OH_EXPECT_RET({userEvent}, EventWrap, GetEventData); - OH_EXPECT_RET({AAFwk::UserEventHandler::EVENT_REPORT_USER_SWITCH_DONE}, EventWrap, GetEventId); - controller->ProcessEvent(event); - EXPECT_LOG_MATCH(LOG_DEBUG, AAFwkTag::ABILITYMGR, "user_controller.cpp", "handle user switch done."); -} - -/** - * @tc.name: ProcessEvent_008 - * @tc.desc: Verify ProcessEvent call. - * Branch event.GetEventId() == invalid value - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, ProcessEvent_008, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - AAFwk::EventWrap event(0); - std::shared_ptr userEvent = std::make_shared(); - OH_EXPECT_RET({userEvent}, EventWrap, GetEventData); - uint32_t eventId = 111; - OH_EXPECT_RET({eventId}, EventWrap, GetEventId); - controller->ProcessEvent(event); - EXPECT_LOG_MATCH(LOG_WARN, AAFwkTag::ABILITYMGR, "user_controller.cpp", "Unsupported event."); -} - -/** - * @tc.name: SendSystemUserCurrent_001 - * @tc.desc: Verify SendSystemUserCurrent call. - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, SendSystemUserCurrent_001, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->eventHandler_ = std::make_shared(nullptr, controller); - controller->SendSystemUserCurrent(100, 101); - EXPECT_LOG_MATCH(LOG_DEBUG, AAFwkTag::ABILITYMGR, "user_controller.cpp", "SendEvent(EVENT_SYSTEM_USER_CURRENT)"); -} - -/** - * @tc.name: SendSystemUserCurrent_002 - * @tc.desc: Verify SendSystemUserCurrent call. - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, SendSystemUserCurrent_002, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->eventHandler_ = nullptr; - controller->SendSystemUserCurrent(100, 101); - EXPECT_LOG_MATCH(LOG_ERROR, AAFwkTag::ABILITYMGR, "user_controller.cpp", "null handler"); -} - -/** - * @tc.name: SendReportUserSwitch_001 - * @tc.desc: Verify SendReportUserSwitch call. - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, SendReportUserSwitch_001, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->eventHandler_ = std::make_shared(nullptr, controller); - std::shared_ptr usrItem = nullptr; - controller->SendReportUserSwitch(100, 101, usrItem); - EXPECT_LOG_MATCH(LOG_DEBUG, AAFwkTag::ABILITYMGR, "user_controller.cpp", "SendEvent(EVENT_REPORT_USER_SWITCH)"); -} - -/** - * @tc.name: SendReportUserSwitch_002 - * @tc.desc: Verify SendReportUserSwitch call. - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, SendReportUserSwitch_002, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->eventHandler_ = nullptr; - std::shared_ptr usrItem = nullptr; - controller->SendReportUserSwitch(100, 101, usrItem); - EXPECT_LOG_MATCH(LOG_ERROR, AAFwkTag::ABILITYMGR, "user_controller.cpp", "null handler"); -} - -/** - * @tc.name: SendUserSwitchTimeout_001 - * @tc.desc: Verify SendUserSwitchTimeout call. - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, SendUserSwitchTimeout_001, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->eventHandler_ = std::make_shared(nullptr, controller); - std::shared_ptr usrItem = nullptr; - controller->SendUserSwitchTimeout(100, 101, usrItem); - EXPECT_LOG_MATCH(LOG_DEBUG, AAFwkTag::ABILITYMGR, "user_controller.cpp", "SendEvent(EVENT_USER_SWITCH_TIMEOUT)"); -} - -/** - * @tc.name: SendUserSwitchTimeout_002 - * @tc.desc: Verify SendUserSwitchTimeout call. - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, SendUserSwitchTimeout_002, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->eventHandler_ = nullptr; - std::shared_ptr usrItem = nullptr; - controller->SendUserSwitchTimeout(100, 101, usrItem); - EXPECT_LOG_MATCH(LOG_ERROR, AAFwkTag::ABILITYMGR, "user_controller.cpp", "null handler"); -} - -/** - * @tc.name: SendContinueUserSwitch_001 - * @tc.desc: Verify SendContinueUserSwitch call. - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, SendContinueUserSwitch_001, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->eventHandler_ = std::make_shared(nullptr, controller); - std::shared_ptr usrItem = nullptr; - controller->SendContinueUserSwitch(100, 101, usrItem); - EXPECT_LOG_MATCH(LOG_DEBUG, AAFwkTag::ABILITYMGR, "user_controller.cpp", "SendEvent(EVENT_CONTINUE_USER_SWITCH)"); -} - -/** - * @tc.name: SendContinueUserSwitch_002 - * @tc.desc: Verify SendContinueUserSwitch call. - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, SendContinueUserSwitch_002, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->eventHandler_ = nullptr; - std::shared_ptr usrItem = nullptr; - controller->SendContinueUserSwitch(100, 101, usrItem); - EXPECT_LOG_MATCH(LOG_ERROR, AAFwkTag::ABILITYMGR, "user_controller.cpp", "null handler"); -} - -/** - * @tc.name: SendUserSwitchDone_001 - * @tc.desc: Verify SendUserSwitchDone call. - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, SendUserSwitchDone_001, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->eventHandler_ = std::make_shared(nullptr, controller); - controller->SendUserSwitchDone(100); - EXPECT_LOG_MATCH(LOG_DEBUG, AAFwkTag::ABILITYMGR, "user_controller.cpp", - "SendEvent(EVENT_REPORT_USER_SWITCH_DONE)"); -} - -/** - * @tc.name: SendUserSwitchDone_002 - * @tc.desc: Verify SendUserSwitchDone call. - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, SendUserSwitchDone_002, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->eventHandler_ = nullptr; - controller->SendUserSwitchDone(100); - EXPECT_LOG_MATCH(LOG_ERROR, AAFwkTag::ABILITYMGR, "user_controller.cpp", "null handler"); -} - -/** - * @tc.name: HandleContinueUserSwitch_001 - * @tc.desc: Verify HandleContinueUserSwitch call. - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, HandleContinueUserSwitch_001, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->eventHandler_ = std::make_shared(nullptr, controller); - OH_EXPECT_RET({false}, SceneBoardJudgement, IsSceneBoardEnabled); - std::shared_ptr usrItem = nullptr; - controller->HandleContinueUserSwitch(100, 101, usrItem); - EXPECT_LOG_MATCH(LOG_DEBUG, AAFwkTag::ABILITYMGR, "user_controller.cpp", - "SendEvent(EVENT_REPORT_USER_SWITCH_DONE)"); -} - -/** - * @tc.name: HandleContinueUserSwitch_002 - * @tc.desc: Verify HandleContinueUserSwitch call. - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, HandleContinueUserSwitch_002, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->eventHandler_ = std::make_shared(nullptr, controller); - OH_EXPECT_RET({true}, SceneBoardJudgement, IsSceneBoardEnabled); - std::shared_ptr usrItem = nullptr; - controller->HandleContinueUserSwitch(100, 101, usrItem); - EXPECT_LOG_MATCH(LOG_DEBUG, AAFwkTag::ABILITYMGR, "user_controller.cpp", - "SendEvent(EVENT_REPORT_USER_SWITCH_DONE)"); + std::shared_ptr controller = std::make_shared(); + uint64_t displayId = 0; + int32_t userId = 100; + AbilityRuntime::UserController::GetInstance().SetCurrentUserId(userId, displayId); + userId = 101; + AbilityRuntime::UserController::GetInstance().SetCurrentUserId(userId, displayId); + EXPECT_EQ(AbilityRuntime::UserController::GetInstance().GetCurrentUserId(displayId), 101); } /** @@ -1481,7 +132,7 @@ HWTEST_F(UserControllerTest, HandleContinueUserSwitch_002, TestSize.Level1) */ HWTEST_F(UserControllerTest, GetFreezingNewUserId_001, TestSize.Level1) { - std::shared_ptr controller = std::make_shared(); + std::shared_ptr controller = std::make_shared(); controller->freezingNewUserId_ = 101; EXPECT_EQ(controller->GetFreezingNewUserId(), 101); } @@ -1493,9 +144,9 @@ HWTEST_F(UserControllerTest, GetFreezingNewUserId_001, TestSize.Level1) */ HWTEST_F(UserControllerTest, SetFreezingNewUserId_001, TestSize.Level1) { - std::shared_ptr controller = std::make_shared(); + std::shared_ptr controller = std::make_shared(); controller->SetFreezingNewUserId(101); EXPECT_EQ(controller->freezingNewUserId_, 101); } -} // namespace AppExecFwk +} // namespace AbilityRuntime } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 747f3964884fc32f1d0af171446d398eada3c369..d50e6fef75bf59e6eef11e3c112a867d9d06670c 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -479,9 +479,6 @@ group("unittest") { "update_caller_info_util_test:unittest", "uri_utils_second_test", "uri_utils_test:unittest", - "user_controller_test:unittest", - "user_event_handler_test:unittest", - "user_record_manager_test:unittest", "want_agent_helper_test:unittest", "want_agent_info_test:unittest", "want_agent_test:unittest", diff --git a/test/unittest/ability_auto_startup_service_second_test/BUILD.gn b/test/unittest/ability_auto_startup_service_second_test/BUILD.gn index 03625ff86a4cdc3bbcc667baf8c3ca2e1f16f981..fd94c80054906d5532eb4ed6cfdcf07db189d143 100644 --- a/test/unittest/ability_auto_startup_service_second_test/BUILD.gn +++ b/test/unittest/ability_auto_startup_service_second_test/BUILD.gn @@ -52,6 +52,7 @@ ohos_unittest("ability_auto_startup_service_second_test") { "${ability_runtime_native_path}/ability/native:auto_startup_callback", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:app_util", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ diff --git a/test/unittest/ability_auto_startup_service_test/BUILD.gn b/test/unittest/ability_auto_startup_service_test/BUILD.gn index d22348615854f00dabb9bf331e1a7b5b85eab4a6..06467c5371d54732d784cc93b182457520f17af2 100644 --- a/test/unittest/ability_auto_startup_service_test/BUILD.gn +++ b/test/unittest/ability_auto_startup_service_test/BUILD.gn @@ -48,6 +48,7 @@ ohos_unittest("ability_auto_startup_service_test") { "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:app_util", "${ability_runtime_services_path}/common:perm_verification", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ diff --git a/test/unittest/ability_auto_startup_service_test/ability_auto_startup_service_test.cpp b/test/unittest/ability_auto_startup_service_test/ability_auto_startup_service_test.cpp index 1af25cf1916927d65348101540bb1a4679d1004c..6308bfa55ddcebd3aae5396216f10f7d60f253f8 100644 --- a/test/unittest/ability_auto_startup_service_test/ability_auto_startup_service_test.cpp +++ b/test/unittest/ability_auto_startup_service_test/ability_auto_startup_service_test.cpp @@ -1028,70 +1028,5 @@ HWTEST_F(AbilityAutoStartupServiceTest, IsTargetExtension_002, TestSize.Level1) EXPECT_FALSE(result); GTEST_LOG_(INFO) << "AbilityAutoStartupServiceTest IsTargetExtension_002 end"; } - -/* - * Feature: AbilityAutoStartupService - * Function: GetValidUserId - * SubFunction: NA - * FunctionPoints: AbilityAutoStartupService GetValidUserId - */ -HWTEST_F(AbilityAutoStartupServiceTest, GetValidUserId_001, TestSize.Level1) -{ - GTEST_LOG_(INFO) << "AbilityAutoStartupServiceTest GetValidUserId_001 start"; - auto abilityAutoStartupService = std::make_shared(); - EXPECT_NE(abilityAutoStartupService, nullptr); - int32_t userId = -1; - abilityAutoStartupService->GetValidUserId(userId); - GTEST_LOG_(INFO) << "AbilityAutoStartupServiceTest GetValidUserId_001 end"; -} - -/* - * Feature: AbilityAutoStartupService - * Function: GetValidUserId - * SubFunction: NA - * FunctionPoints: AbilityAutoStartupService GetValidUserId - */ -HWTEST_F(AbilityAutoStartupServiceTest, GetValidUserId_002, TestSize.Level1) -{ - GTEST_LOG_(INFO) << "AbilityAutoStartupServiceTest GetValidUserId_002 start"; - auto abilityAutoStartupService = std::make_shared(); - EXPECT_NE(abilityAutoStartupService, nullptr); - int32_t userId = 100; - auto validUserId = abilityAutoStartupService->GetValidUserId(userId); - EXPECT_EQ(userId, validUserId); - GTEST_LOG_(INFO) << "AbilityAutoStartupServiceTest GetValidUserId_002 end"; -} - -/* - * Feature: AbilityAutoStartupService - * Function: GetValidUserId - * SubFunction: NA - * FunctionPoints: AbilityAutoStartupService GetValidUserId - */ -HWTEST_F(AbilityAutoStartupServiceTest, GetValidUserId_003, TestSize.Level1) -{ - GTEST_LOG_(INFO) << "AbilityAutoStartupServiceTest GetValidUserId_003 start"; - auto abilityAutoStartupService = std::make_shared(); - EXPECT_NE(abilityAutoStartupService, nullptr); - int32_t userId = 0; - abilityAutoStartupService->GetValidUserId(userId); - GTEST_LOG_(INFO) << "AbilityAutoStartupServiceTest GetValidUserId_003 end"; -} - -/* - * Feature: AbilityAutoStartupService - * Function: GetValidUserId - * SubFunction: NA - * FunctionPoints: AbilityAutoStartupService GetValidUserId - */ -HWTEST_F(AbilityAutoStartupServiceTest, GetValidUserId_004, TestSize.Level1) -{ - GTEST_LOG_(INFO) << "AbilityAutoStartupServiceTest GetValidUserId_004 start"; - auto abilityAutoStartupService = std::make_shared(); - EXPECT_NE(abilityAutoStartupService, nullptr); - int32_t userId = 1; - abilityAutoStartupService->GetValidUserId(userId); - GTEST_LOG_(INFO) << "AbilityAutoStartupServiceTest GetValidUserId_004 end"; -} } // namespace AAFwk } // namespace OHOS diff --git a/test/unittest/ability_auto_startup_service_third_test/BUILD.gn b/test/unittest/ability_auto_startup_service_third_test/BUILD.gn index 1bd537f1e694688fe30536ed835e3edd543e3c6e..a0706aba781e3085e72087a2b338ba0af4556ef5 100644 --- a/test/unittest/ability_auto_startup_service_third_test/BUILD.gn +++ b/test/unittest/ability_auto_startup_service_third_test/BUILD.gn @@ -39,6 +39,7 @@ ohos_unittest("ability_auto_startup_service_third_test") { "${ability_runtime_innerkits_path}/ability_manager:ability_manager", "${ability_runtime_native_path}/ability:ability_context_native", "${ability_runtime_native_path}/ability/native:auto_startup_callback", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ diff --git a/test/unittest/ability_event_handler_test/ability_event_handler_test.cpp b/test/unittest/ability_event_handler_test/ability_event_handler_test.cpp index 1b1cfd8af25a463008c5a4c9fcc648abe4d1500e..bba3237c6cf73c1210a0fa9fc1e74796e1033497 100644 --- a/test/unittest/ability_event_handler_test/ability_event_handler_test.cpp +++ b/test/unittest/ability_event_handler_test/ability_event_handler_test.cpp @@ -43,39 +43,6 @@ void AbilityEventHandlerTest::SetUp() void AbilityEventHandlerTest::TearDown() {} -/* - * Feature: Ability Event Handler - * Function: ProcessEvent - * SubFunction: NA - * FunctionPoints: Ability Event Handler ProcessEvent - * EnvConditions: NA - * CaseDescription: Verify ProcessEvent - */ -HWTEST_F(AbilityEventHandlerTest, ability_event_handler_001, TestSize.Level1) -{ - std::shared_ptr runner; - std::weak_ptr server; - std::shared_ptr eventData = std::make_shared(); - auto event = EventWrap(UserEventHandler::EVENT_SYSTEM_USER_START, eventData); - auto handler = std::make_shared(runner, server); - SetParameter("libc.hook_mode", "startup:"); - handler->ProcessEvent(event); - SetParameter("libc.hook_mode", "test_parameter"); - handler->ProcessEvent(event); - auto event2 = EventWrap(AbilityManagerService::LOAD_TIMEOUT_MSG, event.GetParam()); - std::string str = std::to_string(event.GetEventId()); - handler->ProcessEvent(event2); - event2 = EventWrap(AbilityManagerService::ACTIVE_TIMEOUT_MSG, event.GetParam()); - handler->ProcessEvent(event2); - event2 = EventWrap(AbilityManagerService::INACTIVE_TIMEOUT_MSG, event.GetParam()); - handler->ProcessEvent(event2); - event2 = EventWrap(AbilityManagerService::FOREGROUND_TIMEOUT_MSG, event.GetParam()); - handler->ProcessEvent(event2); - event2 = EventWrap(AbilityManagerService::BACKGROUND_TIMEOUT_MSG, event.GetParam()); - handler->ProcessEvent(event2); - EXPECT_TRUE(handler != nullptr); -} // namespace AppExecFwk - /* * Feature: Ability Event Handler * Function: EventWrap diff --git a/test/unittest/ability_keep_alive_service_test/BUILD.gn b/test/unittest/ability_keep_alive_service_test/BUILD.gn index 13fa83bf9186c12675dfdefe7e08c21d055b76ed..24437fa828322129842d1dce8678f8a53e3718f7 100644 --- a/test/unittest/ability_keep_alive_service_test/BUILD.gn +++ b/test/unittest/ability_keep_alive_service_test/BUILD.gn @@ -44,6 +44,7 @@ ohos_unittest("ability_keep_alive_service_test") { "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:app_util", "${ability_runtime_services_path}/common:perm_verification", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ diff --git a/test/unittest/ability_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 5ed51e73603f771eccedbb3f76339b86be0a7c84..8979dcce4dcf0d526a44038a51f1c1c479775038 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 660d1a744505d20939e43bf1574bfa829d401fe2..c6d8e9c8bc72607339bef876a804dbfd5f65b98c 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 b27b0e36f800e96f1e059f7d67b26c3ff99da386..2206897b0b0f05922b5de09349a25957309308af 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 b9559de09e78b81827cbec38bfc7716331b7be46..2c53c7a2fedf606e72e0ea905f65a9b736df7096 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 9c28fbf1e34b2aeb57c860cd873c9f014d14fc56..08386f6c6a877449f0c7c16c87bd0f678dc927e9 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 6d842980b18ca517df4651354e657334d9756444..18143f6d6a3b4eb104612856be553ea8a5343775 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 6d842980b18ca517df4651354e657334d9756444..18143f6d6a3b4eb104612856be553ea8a5343775 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 49af01d529d05c1abfd6f3eced456c749b77b207..96a67d4c1784031fda5f105c72bc641909d677b1 100644 --- a/test/unittest/ability_manager_proxy_test/ability_manager_proxy_test.cpp +++ b/test/unittest/ability_manager_proxy_test/ability_manager_proxy_test.cpp @@ -1680,8 +1680,9 @@ HWTEST_F(AbilityManagerProxyTest, AbilityManagerProxy_StartUser_001, TestSize.Le EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) .Times(1) .WillOnce(Invoke(mock_.GetRefPtr(), &AbilityManagerStubMock::InvokeSendRequest)); - int userId = 1; - auto res = proxy_->StartUser(userId, nullptr); + int userId = 200; + uint64_t displayId = 0; + auto res = proxy_->StartUser(userId, displayId, nullptr); EXPECT_EQ(static_cast(AbilityManagerInterfaceCode::START_USER), mock_->code_); EXPECT_EQ(res, NO_ERROR); } diff --git a/test/unittest/ability_manager_proxy_test/ability_manager_stub_mock.h b/test/unittest/ability_manager_proxy_test/ability_manager_stub_mock.h index 4cb5157ecff12aeb57ee01917f48b60737d64e84..8461bfaee1cf3c40d2017396e096db7b9b6259b8 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 b443ad9e07c78b5d1fae762c80f7998a459483dc..09dda28fd277c3b882d2de7a3d40280c5652d065 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..0099f719bdaa50014d0f692a97141ba990f8e79a 100644 --- a/test/unittest/ability_manager_service_eighth_test/ability_manager_service_eighth_test.cpp +++ b/test/unittest/ability_manager_service_eighth_test/ability_manager_service_eighth_test.cpp @@ -152,10 +152,6 @@ HWTEST_F(AbilityManagerServiceEighthTest, StopUser_001, TestSize.Level1) IPCSkeleton::SetCallingUid(ACCOUNT_MGR_SERVICE_UID); sptr callback1 = nullptr; EXPECT_EQ(abilityMs->StopUser(userId, callback1), 0); - abilityMs->userController_ = std::make_shared(); - EXPECT_EQ(abilityMs->StopUser(userId, callback), 0); - system::SetBoolParameter(PRODUCT_ENTERPRISE_FEATURE_SETTING_ENABLED, true); - EXPECT_EQ(abilityMs->StopUser(userId, callback), 0); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceEighthTest StopUser_001 end"); } @@ -176,10 +172,7 @@ HWTEST_F(AbilityManagerServiceEighthTest, LogoutUser_001, TestSize.Level1) sptr callback1 = new MockIUserCallback(); EXPECT_EQ(abilityMs->LogoutUser(userId, callback1), CHECK_PERMISSION_FAILED); IPCSkeleton::SetCallingUid(ACCOUNT_MGR_SERVICE_UID); - EXPECT_EQ(abilityMs->LogoutUser(userId, callback1), ERR_OK); - abilityMs->userController_ = std::make_shared(); - system::SetBoolParameter(PRODUCT_APPBOOT_SETTING_ENABLED, true); - EXPECT_NE(abilityMs->LogoutUser(userId, callback1), ERR_OK); + EXPECT_EQ(abilityMs->LogoutUser(userId, callback1), INVALID_USERID_VALUE); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceEighthTest LogoutUser_001 end"); } @@ -218,17 +211,17 @@ HWTEST_F(AbilityManagerServiceEighthTest, SwitchToUser_001, TestSize.Level1) sptr callback1 = new MockIUserCallback(); EXPECT_CALL(Rosen::SceneBoardJudgement::GetInstance(), MockIsSceneBoardEnabled()) .WillRepeatedly(Return(false)); - EXPECT_NE(abilityMs->SwitchToUser(oldUserId, userId, callback), ERR_OK); + EXPECT_NE(abilityMs->SwitchToUser(oldUserId, userId, 0, callback), ERR_OK); abilityMs->taskHandler_ = TaskHandlerWrap::CreateQueueHandler("SetTaskHandler"); - EXPECT_NE(abilityMs->SwitchToUser(oldUserId, userId, callback1), ERR_OK); + EXPECT_NE(abilityMs->SwitchToUser(oldUserId, userId, 0, callback1), ERR_OK); EXPECT_CALL(Rosen::SceneBoardJudgement::GetInstance(), MockIsSceneBoardEnabled()) .WillRepeatedly(Return(true)); - EXPECT_NE(abilityMs->SwitchToUser(oldUserId, userId, callback1), ERR_OK); + EXPECT_NE(abilityMs->SwitchToUser(oldUserId, userId, 0, callback1), ERR_OK); AmsConfigurationParameter::GetInstance().multiUserType_ = 1; // multiUserType_ = 1 - EXPECT_NE(abilityMs->SwitchToUser(oldUserId, userId, callback1), ERR_OK); + EXPECT_NE(abilityMs->SwitchToUser(oldUserId, userId, 0, callback1), ERR_OK); EXPECT_CALL(Rosen::SceneBoardJudgement::GetInstance(), MockIsSceneBoardEnabled()) .WillRepeatedly(Return(false)); - EXPECT_NE(abilityMs->SwitchToUser(oldUserId, userId, callback1), ERR_OK); + EXPECT_NE(abilityMs->SwitchToUser(oldUserId, userId, 0, callback1), ERR_OK); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceEighthTest SwitchToUser_001 end"); } diff --git a/test/unittest/ability_manager_service_fourteenth_test/BUILD.gn b/test/unittest/ability_manager_service_fourteenth_test/BUILD.gn index ac4125480f28626740863ded1ede5c4376c50070..a26f9343e4040a6af2fdf7b9b986269b03d466e6 100644 --- a/test/unittest/ability_manager_service_fourteenth_test/BUILD.gn +++ b/test/unittest/ability_manager_service_fourteenth_test/BUILD.gn @@ -177,8 +177,6 @@ ohos_unittest("ability_manager_service_fourteenth_test") { "${ability_runtime_services_path}/abilitymgr/src/ui_extension_record/ui_extension_record.cpp", "${ability_runtime_services_path}/abilitymgr/src/ui_extension_record/ui_extension_record_factory.cpp", "${ability_runtime_services_path}/abilitymgr/src/user_callback_proxy.cpp", - "${ability_runtime_services_path}/abilitymgr/src/user_controller.cpp", - "${ability_runtime_services_path}/abilitymgr/src/user_event_handler.cpp", "${ability_runtime_services_path}/abilitymgr/src/utils/ability_event_util.cpp", "${ability_runtime_services_path}/abilitymgr/src/utils/ability_permission_util.cpp", "${ability_runtime_services_path}/abilitymgr/src/utils/app_mgr_util.cpp", @@ -263,6 +261,7 @@ ohos_unittest("ability_manager_service_fourteenth_test") { "${ability_runtime_services_path}/common:record_cost_time_util", "${ability_runtime_services_path}/common:res_sched_util", "${ability_runtime_services_path}/common:task_handler_wrap", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ diff --git a/test/unittest/ability_manager_service_second_test/BUILD.gn b/test/unittest/ability_manager_service_second_test/BUILD.gn index 9fc3819734720ea97e123e52f29705ca822f3e10..609f0f4cadc2122849d378c9192746e353b74c0e 100644 --- a/test/unittest/ability_manager_service_second_test/BUILD.gn +++ b/test/unittest/ability_manager_service_second_test/BUILD.gn @@ -183,8 +183,6 @@ ohos_unittest("ability_manager_service_second_test") { "${ability_runtime_services_path}/abilitymgr/src/ui_extension_record/ui_extension_record.cpp", "${ability_runtime_services_path}/abilitymgr/src/ui_extension_record/ui_extension_record_factory.cpp", "${ability_runtime_services_path}/abilitymgr/src/user_callback_proxy.cpp", - "${ability_runtime_services_path}/abilitymgr/src/user_controller.cpp", - "${ability_runtime_services_path}/abilitymgr/src/user_event_handler.cpp", "${ability_runtime_services_path}/abilitymgr/src/utils/ability_event_util.cpp", "${ability_runtime_services_path}/abilitymgr/src/utils/ability_permission_util.cpp", "${ability_runtime_services_path}/abilitymgr/src/utils/app_mgr_util.cpp", @@ -264,6 +262,7 @@ ohos_unittest("ability_manager_service_second_test") { "${ability_runtime_services_path}/common:record_cost_time_util", "${ability_runtime_services_path}/common:res_sched_util", "${ability_runtime_services_path}/common:task_handler_wrap", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ diff --git a/test/unittest/ability_manager_service_second_test/ability_manager_service_second_test.cpp b/test/unittest/ability_manager_service_second_test/ability_manager_service_second_test.cpp index 99bba66e32925d47df000a9575d3f27d046cb394..a342b558beaa6e125c35bea46d4ea455f23c5e0e 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 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 64a97439789e39aa41819dbce732f624a244d721..23608691f38d83fcd5ff1150af602bd35a6fa112 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 @@ -1581,7 +1581,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/BUILD.gn b/test/unittest/ability_manager_service_third_test/BUILD.gn index 3184a5ee67ff42805d881bc792d5764083b9a239..bb0203923c766aed7766e27535e33a46664d8281 100644 --- a/test/unittest/ability_manager_service_third_test/BUILD.gn +++ b/test/unittest/ability_manager_service_third_test/BUILD.gn @@ -91,6 +91,7 @@ ohos_unittest("ability_manager_service_third_test") { "${ability_runtime_services_path}/common:record_cost_time_util", "${ability_runtime_services_path}/common:res_sched_util", "${ability_runtime_services_path}/common:task_handler_wrap", + "${ability_runtime_services_path}/common:user_controller", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/aakit:aakit_mock", ] diff --git a/test/unittest/ability_manager_service_third_test/ability_manager_service_third_test.cpp b/test/unittest/ability_manager_service_third_test/ability_manager_service_third_test.cpp index 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_third_test/abilitymgr.gni b/test/unittest/ability_manager_service_third_test/abilitymgr.gni index 5136f2a5e2289abdcaf040b93e768dfc880f9fdd..b317bd97573bfb09040fe4413e26a7eb7b57a43b 100644 --- a/test/unittest/ability_manager_service_third_test/abilitymgr.gni +++ b/test/unittest/ability_manager_service_third_test/abilitymgr.gni @@ -99,10 +99,6 @@ abilityms_files = [ "${ability_runtime_services_path}/abilitymgr/src/connection_state_manager.cpp", "${ability_runtime_services_path}/abilitymgr/src/dlp_state_item.cpp", - #multi user - "${ability_runtime_services_path}/abilitymgr/src/user_controller.cpp", - "${ability_runtime_services_path}/abilitymgr/src/user_event_handler.cpp", - #free_install "${ability_runtime_services_path}/abilitymgr/src/atomic_service_status_callback_proxy.cpp", "${ability_runtime_services_path}/abilitymgr/src/atomic_service_status_callback_stub.cpp", diff --git a/test/unittest/ability_manager_service_thirteenth_test/BUILD.gn b/test/unittest/ability_manager_service_thirteenth_test/BUILD.gn index e5c8b96f331e7b1da08554a81de83b9465cc1541..76016487aeda8e5dd6726dd20ad23bd553f209d2 100644 --- a/test/unittest/ability_manager_service_thirteenth_test/BUILD.gn +++ b/test/unittest/ability_manager_service_thirteenth_test/BUILD.gn @@ -177,8 +177,6 @@ ohos_unittest("ability_manager_service_thirteenth_test") { "${ability_runtime_services_path}/abilitymgr/src/ui_extension_record/ui_extension_record.cpp", "${ability_runtime_services_path}/abilitymgr/src/ui_extension_record/ui_extension_record_factory.cpp", "${ability_runtime_services_path}/abilitymgr/src/user_callback_proxy.cpp", - "${ability_runtime_services_path}/abilitymgr/src/user_controller.cpp", - "${ability_runtime_services_path}/abilitymgr/src/user_event_handler.cpp", "${ability_runtime_services_path}/abilitymgr/src/utils/ability_event_util.cpp", "${ability_runtime_services_path}/abilitymgr/src/utils/ability_permission_util.cpp", "${ability_runtime_services_path}/abilitymgr/src/utils/app_mgr_util.cpp", @@ -264,6 +262,7 @@ ohos_unittest("ability_manager_service_thirteenth_test") { "${ability_runtime_services_path}/common:record_cost_time_util", "${ability_runtime_services_path}/common:res_sched_util", "${ability_runtime_services_path}/common:task_handler_wrap", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ diff --git a/test/unittest/ability_manager_service_twelfth_test/ability_manager_service_twelfth_test.cpp b/test/unittest/ability_manager_service_twelfth_test/ability_manager_service_twelfth_test.cpp index 1fad5b98907c000356dc5416af95aee1dd68f616..06481a1fe4caf822fc0bb470ecf60730f5798bc0 100644 --- a/test/unittest/ability_manager_service_twelfth_test/ability_manager_service_twelfth_test.cpp +++ b/test/unittest/ability_manager_service_twelfth_test/ability_manager_service_twelfth_test.cpp @@ -545,7 +545,7 @@ HWTEST_F(AbilityManagerServiceTwelfthTest, StartUser_001, TestSize.Level1) int userId = 0; sptr callback = new MockIUserCallback(); bool isAppRecovery = false; - auto retCode = abilityMs_->StartUser(userId, callback, isAppRecovery); + auto retCode = abilityMs_->StartUser(userId, 0, callback, isAppRecovery); EXPECT_EQ(retCode, CHECK_PERMISSION_FAILED); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceTwelfthTest StartUser_001 end"); } @@ -622,8 +622,6 @@ HWTEST_F(AbilityManagerServiceTwelfthTest, IsSceneBoardReady_001, TestSize.Level int32_t userId = -1; auto abilityMs = std::make_shared(); EXPECT_NE(abilityMs, nullptr); - abilityMs->userController_ = std::make_shared(); - EXPECT_NE(abilityMs->userController_, nullptr); abilityMs->subManagersHelper_ = std::make_shared(nullptr, nullptr); EXPECT_NE(abilityMs->subManagersHelper_, nullptr); bool result = abilityMs->IsSceneBoardReady(userId); @@ -644,7 +642,6 @@ HWTEST_F(AbilityManagerServiceTwelfthTest, IsSceneBoardReady_002, TestSize.Level int32_t userId = 100; auto abilityMs = std::make_shared(); EXPECT_NE(abilityMs, nullptr); - abilityMs->userController_ = nullptr; abilityMs->subManagersHelper_ = nullptr; bool result = abilityMs->IsSceneBoardReady(userId); EXPECT_FALSE(result); diff --git a/test/unittest/ability_manager_stub_test/ability_manager_stub_impl_mock.h b/test/unittest/ability_manager_stub_test/ability_manager_stub_impl_mock.h index cc1dac2376ae126c490d7cac1f1e7a74834e13f6..57e9c0b150cf492554edd9edefc61a064c6587e7 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 f87fe1e2e185211b62e2a68ebf8044e52c957bf4..d49976677579eb11df1967f1d38beb260edee4a0 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 7064b15201a53c9f35327d0bf5871ab0138e5b1f..3352a24129beb6378ac21f8ba77f9e98d94c346f 100644 --- a/test/unittest/ams_ability_running_record_test/BUILD.gn +++ b/test/unittest/ams_ability_running_record_test/BUILD.gn @@ -44,7 +44,6 @@ ohos_unittest("AmsAbilityRunningRecordTest") { "${ability_runtime_services_path}/appmgr/src/killing_process_manager.cpp", "${ability_runtime_services_path}/appmgr/src/multi_user_config_mgr.cpp", "${ability_runtime_services_path}/appmgr/src/render_state_observer_manager.cpp", - "${ability_runtime_services_path}/appmgr/src/user_record_manager.cpp", ] sources += [ "ams_ability_running_record_test.cpp" ] @@ -68,6 +67,7 @@ ohos_unittest("AmsAbilityRunningRecordTest") { "${ability_runtime_services_path}/common:record_cost_time_util", "${ability_runtime_services_path}/common:res_sched_util", "${ability_runtime_services_path}/common:task_handler_wrap", + "${ability_runtime_services_path}/common:user_controller", "${ability_runtime_test_path}/unittest:appmgr_test_source", ] @@ -106,7 +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_mgr_scheduler_second_test/ams_mgr_scheduler_second_test.cpp b/test/unittest/ams_mgr_scheduler_second_test/ams_mgr_scheduler_second_test.cpp index c7a43830ebf9279076e4438644793e2199e76aa6..d80d116810600915ddb4bc70e5d907d10f8983f4 100644 --- a/test/unittest/ams_mgr_scheduler_second_test/ams_mgr_scheduler_second_test.cpp +++ b/test/unittest/ams_mgr_scheduler_second_test/ams_mgr_scheduler_second_test.cpp @@ -1096,71 +1096,6 @@ HWTEST_F(AmsMgrSchedulerSecondTest, AmsMgrSchedulerSecondTest_NotifyAppMgrRecord TAG_LOGI(AAFwkTag::TEST, "AmsMgrSchedulerSecondTest_NotifyAppMgrRecordExitReason_002 end"); } -/** - * @tc.name: AmsMgrSchedulerSecondTest_SetEnableStartProcessFlagByUserId_001 - * @tc.desc: Test SetEnableStartProcessFlagByUserId - * @tc.type: FUNC - */ -HWTEST_F(AmsMgrSchedulerSecondTest, AmsMgrSchedulerSecondTest_SetEnableStartProcessFlagByUserId_001, TestSize.Level1) -{ - TAG_LOGI(AAFwkTag::TEST, "AmsMgrSchedulerSecondTest_SetEnableStartProcessFlagByUserId_001 start"); - std::shared_ptr appMgrServiceInner = nullptr; - std::shared_ptr amsMgrScheduler = - std::make_shared(appMgrServiceInner, taskHandler_); - - /** - * @tc.steps: step1. amsMgrScheduler isReady false - * @tc.expected: step1. expect ERR_INVALID_OPERATION - */ - amsMgrScheduler->SetEnableStartProcessFlagByUserId(0, false); - EXPECT_TRUE(amsMgrScheduler != nullptr); - TAG_LOGI(AAFwkTag::TEST, "AmsMgrSchedulerSecondTest_SetEnableStartProcessFlagByUserId_001 end"); -} - -/** - * @tc.name: AmsMgrSchedulerSecondTest_SetEnableStartProcessFlagByUserId_002 - * @tc.desc: Test StartSpecifiedAbility - * @tc.type: FUNC - */ -HWTEST_F(AmsMgrSchedulerSecondTest, AmsMgrSchedulerSecondTest_SetEnableStartProcessFlagByUserId_002, TestSize.Level1) -{ - TAG_LOGI(AAFwkTag::TEST, "AmsMgrSchedulerSecondTest_SetEnableStartProcessFlagByUserId_002 start"); - auto appMgrServiceInner = std::make_shared(); - std::shared_ptr amsMgrScheduler = - std::make_shared(appMgrServiceInner, taskHandler_); - - /** - * @tc.steps: step1. amsMgrScheduler isReady false - * @tc.expected: step1. expect ERR_INVALID_OPERATION - */ - IPCSkeleton::SetCallingUid(-1); - amsMgrScheduler->SetEnableStartProcessFlagByUserId(0, false); - EXPECT_TRUE(amsMgrScheduler != nullptr); - TAG_LOGI(AAFwkTag::TEST, "AmsMgrSchedulerSecondTest_SetEnableStartProcessFlagByUserId_002 end"); -} - -/** - * @tc.name: AmsMgrSchedulerSecondTest_SetEnableStartProcessFlagByUserId_003 - * @tc.desc: Test StartSpecifiedAbility - * @tc.type: FUNC - */ -HWTEST_F(AmsMgrSchedulerSecondTest, AmsMgrSchedulerSecondTest_SetEnableStartProcessFlagByUserId_003, TestSize.Level1) -{ - TAG_LOGI(AAFwkTag::TEST, "AmsMgrSchedulerSecondTest_SetEnableStartProcessFlagByUserId_003 start"); - auto appMgrServiceInner = std::make_shared(); - std::shared_ptr amsMgrScheduler = - std::make_shared(appMgrServiceInner, taskHandler_); - - /** - * @tc.steps: step1. amsMgrScheduler isReady false - * @tc.expected: step1. expect ERR_INVALID_OPERATION - */ - IPCSkeleton::SetCallingUid(Constants::FOUNDATION_UID); - amsMgrScheduler->SetEnableStartProcessFlagByUserId(0, false); - EXPECT_TRUE(amsMgrScheduler != nullptr); - TAG_LOGI(AAFwkTag::TEST, "AmsMgrSchedulerSecondTest_SetEnableStartProcessFlagByUserId_003 end"); -} - /** * @tc.name: AmsMgrSchedulerSecondTest_RegisterAppDebugListener_001 * @tc.desc: Test RegisterAppDebugListener diff --git a/test/unittest/ams_mgr_scheduler_test/ams_mgr_scheduler_test.cpp b/test/unittest/ams_mgr_scheduler_test/ams_mgr_scheduler_test.cpp index d598487038e3e7a665ff5d08e661065b23fcf905..05f2d875821c3235f608c2f1b644b7c3417496e9 100644 --- a/test/unittest/ams_mgr_scheduler_test/ams_mgr_scheduler_test.cpp +++ b/test/unittest/ams_mgr_scheduler_test/ams_mgr_scheduler_test.cpp @@ -850,34 +850,6 @@ HWTEST_F(AmsMgrSchedulerTest, NotifyAppMgrRecordExitReason_001, TestSize.Level2) EXPECT_NE(res2, ERR_INVALID_OPERATION); } -/** - * @tc.name: SetCurrentUserId_002 - * @tc.desc: set current userId. - * @tc.type: FUNC - */ -HWTEST_F(AmsMgrSchedulerTest, SetCurrentUserId_002, TestSize.Level2) -{ - auto amsMgrScheduler = std::make_unique(nullptr, nullptr); - amsMgrScheduler->amsMgrServiceInner_ = GetMockAppMgrServiceInner(); - amsMgrScheduler->amsHandler_ = GetAmsTaskHandler(); - ASSERT_NE(amsMgrScheduler, nullptr); - int userId = 1; - amsMgrScheduler->SetCurrentUserId(userId); -} - -/** - * @tc.name: SetCurrentUserId_001 - * @tc.desc: set current userId. - * @tc.type: FUNC - */ -HWTEST_F(AmsMgrSchedulerTest, SetCurrentUserId_001, TestSize.Level2) -{ - auto amsMgrScheduler = std::make_unique(nullptr, nullptr); - ASSERT_NE(amsMgrScheduler, nullptr); - int userId = 1; - amsMgrScheduler->SetCurrentUserId(userId); -} - /** * @tc.name: RegisterAppDebugListener_001 * @tc.desc: Test the state of RegisterAppDebugListener diff --git a/test/unittest/ams_recent_app_list_test/BUILD.gn b/test/unittest/ams_recent_app_list_test/BUILD.gn index d60d2ca04414d1682d0cd85273824e101a108bf8..4122ba7b8bac6c8c0dbb3b0b4a536c80ab338875 100644 --- a/test/unittest/ams_recent_app_list_test/BUILD.gn +++ b/test/unittest/ams_recent_app_list_test/BUILD.gn @@ -45,7 +45,6 @@ ohos_unittest("AmsRecentAppListTest") { "${ability_runtime_services_path}/appmgr/src/module_running_record.cpp", "${ability_runtime_services_path}/appmgr/src/remote_client_manager.cpp", "${ability_runtime_services_path}/appmgr/src/render_state_observer_manager.cpp", - "${ability_runtime_services_path}/appmgr/src/user_record_manager.cpp", "${ability_runtime_services_path}/appmgr/src/window_focus_changed_listener.cpp", "${ability_runtime_services_path}/appmgr/src/window_visibility_changed_listener.cpp", "${ability_runtime_test_path}/mock/services_appmgr_test/src/mock_bundle_manager.cpp", diff --git a/test/unittest/ams_service_app_spawn_client_test/BUILD.gn b/test/unittest/ams_service_app_spawn_client_test/BUILD.gn index 0077518b672026a69b6c78526b9563b60adbaf38..ac4741e196a5ca88a2c37fc6165a760ef93c05c9 100644 --- a/test/unittest/ams_service_app_spawn_client_test/BUILD.gn +++ b/test/unittest/ams_service_app_spawn_client_test/BUILD.gn @@ -50,7 +50,6 @@ ohos_unittest("AmsServiceAppSpawnClientTest") { "${ability_runtime_services_path}/appmgr/src/exit_resident_process_manager.cpp", "${ability_runtime_services_path}/appmgr/src/killing_process_manager.cpp", "${ability_runtime_services_path}/appmgr/src/render_state_observer_manager.cpp", - "${ability_runtime_services_path}/appmgr/src/user_record_manager.cpp", ] sources += [ "ams_service_app_spawn_client_test.cpp" ] diff --git a/test/unittest/ams_service_event_drive_test/BUILD.gn b/test/unittest/ams_service_event_drive_test/BUILD.gn index 593c4e7417fde245887b287c194adf360a7df03a..255ca4cb224e1b1bdc53b022259a5e59b661be58 100644 --- a/test/unittest/ams_service_event_drive_test/BUILD.gn +++ b/test/unittest/ams_service_event_drive_test/BUILD.gn @@ -46,7 +46,6 @@ ohos_unittest("AmsServiceEventDriveTest") { "${ability_runtime_services_path}/appmgr/src/exit_resident_process_manager.cpp", "${ability_runtime_services_path}/appmgr/src/killing_process_manager.cpp", "${ability_runtime_services_path}/appmgr/src/render_state_observer_manager.cpp", - "${ability_runtime_services_path}/appmgr/src/user_record_manager.cpp", "${ability_runtime_test_path}/mock/common/src/mock_native_token.cpp", ] 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 8ceefa8055c7d923c4ebc6224413b0caf76bb508..95f8b8d905eff11a87292079c33b5c60f650c8c0 100644 --- a/test/unittest/ams_service_load_ability_process_test/BUILD.gn +++ b/test/unittest/ams_service_load_ability_process_test/BUILD.gn @@ -52,7 +52,6 @@ ohos_unittest("AmsServiceLoadAbilityProcessTest") { "${ability_runtime_services_path}/appmgr/src/remote_client_manager.cpp", "${ability_runtime_services_path}/appmgr/src/render_record.cpp", "${ability_runtime_services_path}/appmgr/src/render_state_observer_manager.cpp", - "${ability_runtime_services_path}/appmgr/src/user_record_manager.cpp", "${ability_runtime_services_path}/appmgr/src/window_focus_changed_listener.cpp", "${ability_runtime_services_path}/appmgr/src/window_visibility_changed_listener.cpp", "${ability_runtime_test_path}/mock/services_appmgr_test/src/mock_bundle_manager.cpp", @@ -77,6 +76,7 @@ ohos_unittest("AmsServiceLoadAbilityProcessTest") { "${ability_runtime_services_path}/common:record_cost_time_util", "${ability_runtime_services_path}/common:res_sched_util", "${ability_runtime_services_path}/common:task_handler_wrap", + "${ability_runtime_services_path}/common:user_controller", "${ability_runtime_test_path}/unittest:appmgr_test_source", ] @@ -121,6 +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 1ba09810280931b979425742af54467ae8f5d225..fda1c3a2d699cbe05533ee34703911ce8fdad32c 100644 --- a/test/unittest/ams_service_startup_test/BUILD.gn +++ b/test/unittest/ams_service_startup_test/BUILD.gn @@ -46,7 +46,6 @@ ohos_unittest("AmsServiceStartupTest") { "${ability_runtime_services_path}/appmgr/src/killing_process_manager.cpp", "${ability_runtime_services_path}/appmgr/src/multi_user_config_mgr.cpp", "${ability_runtime_services_path}/appmgr/src/render_state_observer_manager.cpp", - "${ability_runtime_services_path}/appmgr/src/user_record_manager.cpp", ] sources += [ "ams_service_startup_test.cpp" ] @@ -69,6 +68,7 @@ ohos_unittest("AmsServiceStartupTest") { "${ability_runtime_services_path}/common:record_cost_time_util", "${ability_runtime_services_path}/common:res_sched_util", "${ability_runtime_services_path}/common:task_handler_wrap", + "${ability_runtime_services_path}/common:user_controller", "${ability_runtime_test_path}/unittest:appmgr_test_source", ] @@ -109,7 +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_client_test/app_mgr_client_test.cpp b/test/unittest/app_mgr_client_test/app_mgr_client_test.cpp index ebb83ac745756b5bab8c4c3fc7386cab949d2a29..e5b715445debe7e9eb183197f323b10a049a7819 100644 --- a/test/unittest/app_mgr_client_test/app_mgr_client_test.cpp +++ b/test/unittest/app_mgr_client_test/app_mgr_client_test.cpp @@ -647,23 +647,6 @@ HWTEST_F(AppMgrClientTest, AppMgrClient_StartRenderProcess_001, TestSize.Level2) EXPECT_EQ(ret, ERROR_STATE); } -/** - * @tc.name: AppMgrClient_SetCurrentUserId_001 - * @tc.desc: set current userId. - * @tc.type: FUNC - */ -HWTEST_F(AppMgrClientTest, AppMgrClient_SetCurrentUserId_001, TestSize.Level2) -{ - auto appMgrClient = std::make_unique(); - EXPECT_NE(appMgrClient, nullptr); - - auto result = appMgrClient->ConnectAppMgrService(); - EXPECT_EQ(result, AppMgrResultCode::RESULT_OK); - - int32_t userId = 0; - appMgrClient->SetCurrentUserId(userId); -} - /** * @tc.name: AppMgrClient_UpdateApplicationInfoInstalled_001 * @tc.desc: UpdateApplicationInfoInstalled. 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 f10ab814e2e7a9227e83a473b61b8ca99d567b81..44eeba85a2ed308bc383d5dc6e79a8b94ee0a49d 100644 --- a/test/unittest/app_mgr_service_event_handler_test/BUILD.gn +++ b/test/unittest/app_mgr_service_event_handler_test/BUILD.gn @@ -50,7 +50,6 @@ ohos_unittest("AMSEventHandlerTest") { "${ability_runtime_services_path}/appmgr/src/remote_client_manager.cpp", "${ability_runtime_services_path}/appmgr/src/render_record.cpp", "${ability_runtime_services_path}/appmgr/src/render_state_observer_manager.cpp", - "${ability_runtime_services_path}/appmgr/src/user_record_manager.cpp", "${ability_runtime_services_path}/appmgr/src/window_focus_changed_listener.cpp", "${ability_runtime_services_path}/appmgr/src/window_visibility_changed_listener.cpp", ] @@ -73,6 +72,7 @@ ohos_unittest("AMSEventHandlerTest") { "${ability_runtime_services_path}/common:record_cost_time_util", "${ability_runtime_services_path}/common:res_sched_util", "${ability_runtime_services_path}/common:task_handler_wrap", + "${ability_runtime_services_path}/common:user_controller", "${ability_runtime_test_path}/unittest:appmgr_test_source", ] @@ -119,6 +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_fourth_test/BUILD.gn b/test/unittest/app_mgr_service_fourth_test/BUILD.gn index 3acb0107ed8c1dcc4961c14d323eb66a78326b68..0c4e8e0b2c8ca0f0a2ce7c91ae17ce192fc5feb8 100644 --- a/test/unittest/app_mgr_service_fourth_test/BUILD.gn +++ b/test/unittest/app_mgr_service_fourth_test/BUILD.gn @@ -63,6 +63,7 @@ ohos_unittest("app_mgr_service_fourth_test") { "${ability_runtime_services_path}/common:app_util", "${ability_runtime_services_path}/common:record_cost_time_util", "${ability_runtime_services_path}/common:task_handler_wrap", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ @@ -91,6 +92,7 @@ ohos_unittest("app_mgr_service_fourth_test") { "safwk:system_ability_fwk", "samgr:samgr_proxy", "selinux_adapter:librestorecon", + "window_manager:libdm", ] defines = [] diff --git a/test/unittest/app_mgr_service_fourth_test/mock/include/mock_my_status.h b/test/unittest/app_mgr_service_fourth_test/mock/include/mock_my_status.h index 405a5d4a69ec0bf260a7998742ee77cce4259f02..399e6a14b57eb2657a762caca6c3d42c67cbf12e 100644 --- a/test/unittest/app_mgr_service_fourth_test/mock/include/mock_my_status.h +++ b/test/unittest/app_mgr_service_fourth_test/mock/include/mock_my_status.h @@ -21,7 +21,6 @@ #include "iservice_registry.h" #include "singleton.h" #include "system_ability_definition.h" -#include "user_record_manager.h" #include "hilog_tag_wrapper.h" namespace OHOS { namespace AAFwk { 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 136073f96b8d6f709f71467ef183ca64947c4ce9..d38741adebdb46cd0cff0c77b63be463630878b8 100644 --- a/test/unittest/app_mgr_service_inner_eighth_test/BUILD.gn +++ b/test/unittest/app_mgr_service_inner_eighth_test/BUILD.gn @@ -86,7 +86,6 @@ ohos_unittest("app_mgr_service_inner_eighth_test") { "mock/src/mock_parameters.cpp", "mock/src/mock_permission_verification.cpp", "mock/src/mock_remote_client_manager.cpp", - "mock/src/mock_user_record_manager.cpp", "mock/src/mock_app_utils.cpp", ] @@ -105,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 = [ @@ -152,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..c35dbc9728ac9f1a3ca0d9b389b28616eef817df 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 @@ -23,7 +23,6 @@ #include "child_process_record.h" #include "cache_process_manager.h" #undef private -#include "user_record_manager.h" #include "mock_my_status.h" #include "ability_manager_errors.h" #include "overlay_manager_proxy.h" @@ -587,54 +586,6 @@ HWTEST_F(AppMgrServiceInnerEighthTest, StartNativeProcessForDebugger_006, TestSi TAG_LOGI(AAFwkTag::TEST, "StartNativeProcessForDebugger_006 end"); } -/** - * @tc.name: GetCurrentAccountId_001 - * @tc.desc: test GetCurrentAccountId_001 - * @tc.type: FUNC - */ -HWTEST_F(AppMgrServiceInnerEighthTest, GetCurrentAccountId_001, TestSize.Level1) -{ - TAG_LOGI(AAFwkTag::TEST, "GetCurrentAccountId_001 start"); - auto appMgrServiceInner = std::make_shared(); - AAFwk::MyStatus::GetInstance().queryActiveOsAccountIds_ = ERR_NO_INIT; - - auto ret = appMgrServiceInner->GetCurrentAccountId(); - EXPECT_EQ(ret, DEFAULT_USER_ID); - TAG_LOGI(AAFwkTag::TEST, "GetCurrentAccountId_001 end"); -} - -/** - * @tc.name: GetCurrentAccountId_002 - * @tc.desc: test GetCurrentAccountId_002 - * @tc.type: FUNC - */ -HWTEST_F(AppMgrServiceInnerEighthTest, GetCurrentAccountId_002, TestSize.Level1) -{ - TAG_LOGI(AAFwkTag::TEST, "GetCurrentAccountId_002 start"); - auto appMgrServiceInner = std::make_shared(); - AAFwk::MyStatus::GetInstance().queryActiveOsAccountIds_ = ERR_OK; - - auto ret = appMgrServiceInner->GetCurrentAccountId(); - EXPECT_EQ(ret, DEFAULT_USER_ID); - TAG_LOGI(AAFwkTag::TEST, "GetCurrentAccountId_002 end"); -} - -/** - * @tc.name: SetCurrentUserId_001 - * @tc.desc: test SetCurrentUserId_001 - * @tc.type: FUNC - */ -HWTEST_F(AppMgrServiceInnerEighthTest, SetCurrentUserId_001, TestSize.Level1) -{ - TAG_LOGI(AAFwkTag::TEST, "SetCurrentUserId_001 start"); - auto appMgrServiceInner = std::make_shared(); - AAFwk::MyStatus::GetInstance().getCallingUid_ = FOUNDATION_UID; - - appMgrServiceInner->SetCurrentUserId(2); - EXPECT_EQ(appMgrServiceInner->currentUserId_, 2); - TAG_LOGI(AAFwkTag::TEST, "SetCurrentUserId_001 end"); -} - /** * @tc.name: GetRunningProcessInformation_001 * @tc.desc: test GetRunningProcessInformation_001 diff --git a/test/unittest/app_mgr_service_inner_eighth_test/mock/include/mock_my_status.h b/test/unittest/app_mgr_service_inner_eighth_test/mock/include/mock_my_status.h index c2df9d805f10c030fb5e44c17f21a61328dac110..c45737838ccccef7f37e45a6183e3b59c51b0c65 100755 --- a/test/unittest/app_mgr_service_inner_eighth_test/mock/include/mock_my_status.h +++ b/test/unittest/app_mgr_service_inner_eighth_test/mock/include/mock_my_status.h @@ -21,7 +21,6 @@ #include "iservice_registry.h" #include "singleton.h" #include "system_ability_definition.h" -#include "user_record_manager.h" #include #include "hilog_tag_wrapper.h" diff --git a/test/unittest/app_mgr_service_inner_eighth_test/mock/src/mock_user_record_manager.cpp b/test/unittest/app_mgr_service_inner_eighth_test/mock/src/mock_user_record_manager.cpp deleted file mode 100755 index d267bce8557ff24bd4446f52752173f201c1b2a2..0000000000000000000000000000000000000000 --- a/test/unittest/app_mgr_service_inner_eighth_test/mock/src/mock_user_record_manager.cpp +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2024 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_record_manager.h" -#include -#include "hilog_tag_wrapper.h" -#include "mock_my_status.h" - -namespace OHOS { -namespace AppExecFwk { -namespace { - constexpr int32_t U0_USER_ID = 0; -} -UserRecordManager::~UserRecordManager() {} - -UserRecordManager::UserRecordManager() {} - -UserRecordManager &UserRecordManager::GetInstance() -{ - static UserRecordManager instance; - return instance; -} - -bool UserRecordManager::IsLogoutUser(int32_t userId) -{ - return AAFwk::MyStatus::GetInstance().isLogoutUser_; -} - -void UserRecordManager::SetEnableStartProcessFlagByUserId(int32_t userId, bool enableStartProcess) -{ -} -} // namespace AppExecFwk -} // namespace OHOS - \ No newline at end of file diff --git a/test/unittest/app_mgr_service_inner_ninth_test/BUILD.gn b/test/unittest/app_mgr_service_inner_ninth_test/BUILD.gn index 0ad3739a084add947741d41ba8114a71778b38aa..edcaf4cd93d36e9f03f2339e0e6ef8b9c2a8a06c 100644 --- a/test/unittest/app_mgr_service_inner_ninth_test/BUILD.gn +++ b/test/unittest/app_mgr_service_inner_ninth_test/BUILD.gn @@ -88,7 +88,6 @@ ohos_unittest("app_mgr_service_inner_ninth_test") { "mock/src/mock_parameters.cpp", "mock/src/mock_permission_verification.cpp", "mock/src/mock_remote_client_manager.cpp", - "mock/src/mock_user_record_manager.cpp", ] configs = [] @@ -104,6 +103,7 @@ ohos_unittest("app_mgr_service_inner_ninth_test") { "${ability_runtime_services_path}/common:perm_verification", "${ability_runtime_services_path}/common:res_sched_util", "${ability_runtime_services_path}/common:task_handler_wrap", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ @@ -142,6 +142,7 @@ ohos_unittest("app_mgr_service_inner_ninth_test") { "safwk:system_ability_fwk", "samgr:samgr_proxy", "selinux_adapter:librestorecon", + "window_manager:libdm", "window_manager:session_manager_lite", ] defines = [] diff --git a/test/unittest/app_mgr_service_inner_ninth_test/app_mgr_service_inner_ninth_test.cpp b/test/unittest/app_mgr_service_inner_ninth_test/app_mgr_service_inner_ninth_test.cpp index 2f10f7d2899d08ff941c3f1c8088b1c9df3f95ec..c6fa433c66cd12ee59be4ba2e94207376306f203 100644 --- a/test/unittest/app_mgr_service_inner_ninth_test/app_mgr_service_inner_ninth_test.cpp +++ b/test/unittest/app_mgr_service_inner_ninth_test/app_mgr_service_inner_ninth_test.cpp @@ -34,7 +34,6 @@ #include "mock_start_specified_ability_response.h" #include "overlay_manager_proxy.h" #include "parameters.h" -#include "user_record_manager.h" #include "want.h" using namespace testing; using namespace testing::ext; @@ -196,7 +195,6 @@ HWTEST_F(AppMgrServiceInnerNinthTest, PreloadApplication_003, TestSize.Level1) AAFwk::MyStatus::GetInstance().verifyCallingPermission_ = true; AAFwk::MyStatus::GetInstance().isSACall_ = true; appMgrServiceInner->appPreloader_ = nullptr; - appMgrServiceInner->currentUserId_ = 200; std::string bundleName = "com.test.preload"; int32_t userId = -2; // CURRENT_USER_ID diff --git a/test/unittest/app_mgr_service_inner_ninth_test/mock/include/mock_my_status.h b/test/unittest/app_mgr_service_inner_ninth_test/mock/include/mock_my_status.h index 8871d7466c6b30189644e717e05745558d777ff0..3f86045f558a3dd53ba52f0713ab6bb8d5c4b01d 100644 --- a/test/unittest/app_mgr_service_inner_ninth_test/mock/include/mock_my_status.h +++ b/test/unittest/app_mgr_service_inner_ninth_test/mock/include/mock_my_status.h @@ -21,7 +21,6 @@ #include "iservice_registry.h" #include "singleton.h" #include "system_ability_definition.h" -#include "user_record_manager.h" #include "exit_resident_process_manager.h" #include 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..a9f46b4cab1855ec61720696956666dec8646645 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"); } @@ -1602,7 +1604,6 @@ HWTEST_F(AppMgrServiceInnerSecondTest, AppMgrServiceInnerSecondTest_ClearAppRunn appRecord->SetUid(uid); appMgrServiceInner->ClearAppRunningDataForKeepAlive(appRecord); - appMgrServiceInner->currentUserId_ = 1; appMgrServiceInner->ClearAppRunningDataForKeepAlive(appRecord); appMgrServiceInner->taskHandler_ = AAFwk::TaskHandlerWrap::CreateQueueHandler("AppMgrServiceInnerSecondTest"); 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 b5a2dfff8d49a54ae944140dfaec6392041c32a4..ccaee1cfd8f73ab84023cb1184c3cc8dc075f997 100644 --- a/test/unittest/app_mgr_service_inner_seventh_test/BUILD.gn +++ b/test/unittest/app_mgr_service_inner_seventh_test/BUILD.gn @@ -85,7 +85,6 @@ ohos_unittest("app_mgr_service_inner_seventh_test") { "mock/src/mock_parameters.cpp", "mock/src/mock_permission_verification.cpp", "mock/src/mock_remote_client_manager.cpp", - "mock/src/mock_user_record_manager.cpp", "mock/src/session_manager_lite.cpp", ] @@ -104,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 = [ @@ -150,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 103ea96ebb63cb94e3a1eb01cc42f30475d1edab..a555533307c217a38373ebb2ef198cbad973910d 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 @@ -21,7 +21,6 @@ #include "app_utils.h" #include "render_record.h" #undef private -#include "user_record_manager.h" #include "mock_my_status.h" #include "ability_manager_errors.h" #include "overlay_manager_proxy.h" @@ -470,7 +469,6 @@ HWTEST_F(AppMgrServiceInnerSeventhTest, GetRunningProcessesByBundleType_001, Tes const std::shared_ptr>(0, appRecord)); AAFwk::MyStatus::GetInstance().getAppRunningRecordMap_.insert(std::pair>(1, appRecord2)); - appMgrServiceInner->currentUserId_ = 1; BundleType bundleType = BundleType::APP; std::vector info; @@ -496,7 +494,6 @@ HWTEST_F(AppMgrServiceInnerSeventhTest, GetRunningProcessesByBundleType_002, Tes AAFwk::MyStatus::GetInstance().getAppRunningRecordMap_.clear(); AAFwk::MyStatus::GetInstance().getAppRunningRecordMap_.insert(std::pair>(1, appRecord2)); - appMgrServiceInner->currentUserId_ = 1; BundleType bundleType = BundleType::APP; std::vector info; @@ -523,7 +520,6 @@ HWTEST_F(AppMgrServiceInnerSeventhTest, GetRunningProcessesByBundleType_003, Tes appRecord2->SetUid(200000); AAFwk::MyStatus::GetInstance().getAppRunningRecordMap_.insert(std::pair>(1, appRecord2)); - appMgrServiceInner->currentUserId_ = 1; BundleType bundleType = BundleType::APP; std::vector info2; @@ -542,43 +538,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 +568,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 +591,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 +617,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 +647,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 +676,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"); } /** @@ -714,7 +691,6 @@ HWTEST_F(AppMgrServiceInnerSeventhTest, GetProcessRunningInfosByUserId_001, Test { TAG_LOGI(AAFwkTag::TEST, "GetProcessRunningInfosByUserId_001 start"); auto appMgrServiceInner = std::make_shared(); - appMgrServiceInner->currentUserId_ = 0; std::shared_ptr info = std::make_shared(); std::string temp = ""; auto appRecord2 = std::make_shared(info, 0, temp); @@ -740,7 +716,6 @@ HWTEST_F(AppMgrServiceInnerSeventhTest, GetProcessRunningInfosByUserId_002, Test { TAG_LOGI(AAFwkTag::TEST, "GetProcessRunningInfosByUserId_002 start"); auto appMgrServiceInner = std::make_shared(); - appMgrServiceInner->currentUserId_ = 0; AAFwk::MyStatus::GetInstance().verifyCallingPermission_ = true; AAFwk::MyStatus::GetInstance().getAppRunningRecordMap_.insert(std::pair>(1, nullptr)); @@ -761,7 +736,6 @@ HWTEST_F(AppMgrServiceInnerSeventhTest, GetProcessRunningInfosByUserId_003, Test { TAG_LOGI(AAFwkTag::TEST, "GetProcessRunningInfosByUserId_003 start"); auto appMgrServiceInner = std::make_shared(); - appMgrServiceInner->currentUserId_ = 0; AAFwk::MyStatus::GetInstance().verifyCallingPermission_ = true; std::shared_ptr info = std::make_shared(); std::string temp = ""; diff --git a/test/unittest/app_mgr_service_inner_seventh_test/mock/include/mock_my_status.h b/test/unittest/app_mgr_service_inner_seventh_test/mock/include/mock_my_status.h index 471bd195e7b85edce141fda760a9b664f64f620e..e63014d95de1d09240b9a2d02f7f15c2da74666c 100755 --- a/test/unittest/app_mgr_service_inner_seventh_test/mock/include/mock_my_status.h +++ b/test/unittest/app_mgr_service_inner_seventh_test/mock/include/mock_my_status.h @@ -21,7 +21,6 @@ #include "iservice_registry.h" #include "singleton.h" #include "system_ability_definition.h" -#include "user_record_manager.h" #include #include "hilog_tag_wrapper.h" diff --git a/test/unittest/app_mgr_service_inner_seventh_test/mock/src/mock_user_record_manager.cpp b/test/unittest/app_mgr_service_inner_seventh_test/mock/src/mock_user_record_manager.cpp deleted file mode 100755 index d267bce8557ff24bd4446f52752173f201c1b2a2..0000000000000000000000000000000000000000 --- a/test/unittest/app_mgr_service_inner_seventh_test/mock/src/mock_user_record_manager.cpp +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2024 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_record_manager.h" -#include -#include "hilog_tag_wrapper.h" -#include "mock_my_status.h" - -namespace OHOS { -namespace AppExecFwk { -namespace { - constexpr int32_t U0_USER_ID = 0; -} -UserRecordManager::~UserRecordManager() {} - -UserRecordManager::UserRecordManager() {} - -UserRecordManager &UserRecordManager::GetInstance() -{ - static UserRecordManager instance; - return instance; -} - -bool UserRecordManager::IsLogoutUser(int32_t userId) -{ - return AAFwk::MyStatus::GetInstance().isLogoutUser_; -} - -void UserRecordManager::SetEnableStartProcessFlagByUserId(int32_t userId, bool enableStartProcess) -{ -} -} // namespace AppExecFwk -} // namespace OHOS - \ No newline at end of file diff --git a/test/unittest/app_mgr_service_inner_sixth_test/BUILD.gn b/test/unittest/app_mgr_service_inner_sixth_test/BUILD.gn index 01f544f3a0b9929f0ebabf91d887dccb437f37d9..cea46e8a0d97425b0b9ad9dcc54f2e16ff2bf8d6 100644 --- a/test/unittest/app_mgr_service_inner_sixth_test/BUILD.gn +++ b/test/unittest/app_mgr_service_inner_sixth_test/BUILD.gn @@ -36,7 +36,6 @@ ohos_unittest("app_mgr_service_inner_sixth_test") { sources = [ "${ability_runtime_services_path}/appmgr/src/child_process_record.cpp", - "${ability_runtime_services_path}/appmgr/src/user_record_manager.cpp", "app_mgr_service_inner_sixth_test.cpp", "mock/src/mock_bundle_mgr_helper.cpp", "mock/src/mock_ipc_skeleton.cpp", diff --git a/test/unittest/app_mgr_service_inner_sixth_test/app_mgr_service_inner_sixth_test.cpp b/test/unittest/app_mgr_service_inner_sixth_test/app_mgr_service_inner_sixth_test.cpp index 7000c31c56d34023d7267c5ddb77ec0afce8c3d2..e6f8fda43778ac4969588c581d29a4c0c6c93860 100644 --- a/test/unittest/app_mgr_service_inner_sixth_test/app_mgr_service_inner_sixth_test.cpp +++ b/test/unittest/app_mgr_service_inner_sixth_test/app_mgr_service_inner_sixth_test.cpp @@ -28,7 +28,6 @@ #include "mock_permission_verification.h" #include "remote_client_manager.h" #include "task_handler_wrap.h" -#include "user_record_manager.h" using namespace testing; using namespace testing::ext; diff --git a/test/unittest/app_mgr_service_inner_tenth_test/BUILD.gn b/test/unittest/app_mgr_service_inner_tenth_test/BUILD.gn index e8bb5daeb20988e74b8d22b65a1f4c320d5e4761..c7c1ba933ae349b78f85675e76491189604dba2e 100644 --- a/test/unittest/app_mgr_service_inner_tenth_test/BUILD.gn +++ b/test/unittest/app_mgr_service_inner_tenth_test/BUILD.gn @@ -90,7 +90,6 @@ ohos_unittest("app_mgr_service_inner_tenth_test") { "${ninth_test_path}/mock/src/mock_parameters.cpp", "${ninth_test_path}/mock/src/mock_permission_verification.cpp", "${ninth_test_path}/mock/src/mock_remote_client_manager.cpp", - "${ninth_test_path}/mock/src/mock_user_record_manager.cpp", "app_mgr_service_inner_tenth_test.cpp", ] @@ -109,6 +108,7 @@ ohos_unittest("app_mgr_service_inner_tenth_test") { "${ability_runtime_services_path}/common:perm_verification", "${ability_runtime_services_path}/common:res_sched_util", "${ability_runtime_services_path}/common:task_handler_wrap", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ @@ -146,6 +146,7 @@ ohos_unittest("app_mgr_service_inner_tenth_test") { "safwk:system_ability_fwk", "samgr:samgr_proxy", "selinux_adapter:librestorecon", + "window_manager:libdm", "window_manager:session_manager_lite", ] defines = [] diff --git a/test/unittest/app_mgr_service_inner_tenth_test/app_mgr_service_inner_tenth_test.cpp b/test/unittest/app_mgr_service_inner_tenth_test/app_mgr_service_inner_tenth_test.cpp index 442e708fde9ca2b9b7bc10e9d4741de7bb6d5065..c0535e63b2afdc3942865055d40c0c1119e0bdad 100644 --- a/test/unittest/app_mgr_service_inner_tenth_test/app_mgr_service_inner_tenth_test.cpp +++ b/test/unittest/app_mgr_service_inner_tenth_test/app_mgr_service_inner_tenth_test.cpp @@ -25,7 +25,6 @@ #include "child_process_record.h" #include "cache_process_manager.h" #undef private -#include "user_record_manager.h" #include "mock_my_status.h" #include "ability_manager_errors.h" #include "overlay_manager_proxy.h" 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 5e71b1afaed01e49da4e17626863180edfb2e0e9..793937327d40668db973177585f52ddb7702e008 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 @@ -4254,24 +4254,6 @@ HWTEST_F(AppMgrServiceInnerTest, NotifyUnLoadRepairPatch_001, TestSize.Level2) TAG_LOGI(AAFwkTag::TEST, "NotifyUnLoadRepairPatch_001 end"); } -/** - * @tc.name: SetCurrentUserId_001 - * @tc.desc: set current userId. - * @tc.type: FUNC - */ -HWTEST_F(AppMgrServiceInnerTest, SetCurrentUserId_001, TestSize.Level2) -{ - TAG_LOGI(AAFwkTag::TEST, "SetCurrentUserId_001 start"); - auto appMgrServiceInner = std::make_shared(); - EXPECT_NE(appMgrServiceInner, nullptr); - - int userId = 0; - appMgrServiceInner->SetCurrentUserId(userId); - EXPECT_EQ(appMgrServiceInner->currentUserId_, userId); - - TAG_LOGI(AAFwkTag::TEST, "SetCurrentUserId_001 end"); -} - /** * @tc.name: GetProcessMemoryByPid_001 * @tc.desc: Get memorySize by pid. @@ -5666,7 +5648,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_running_processes_info_test/BUILD.gn b/test/unittest/app_running_processes_info_test/BUILD.gn index 74ff4798688416aae7f58b154a8b98e8759c0f42..e7816ae81989a6703b67d32ed229486f4580a3be 100644 --- a/test/unittest/app_running_processes_info_test/BUILD.gn +++ b/test/unittest/app_running_processes_info_test/BUILD.gn @@ -45,7 +45,6 @@ ohos_unittest("AppRunningProcessesInfoTest") { "${ability_runtime_services_path}/appmgr/src/cache_process_manager.cpp", "${ability_runtime_services_path}/appmgr/src/exit_resident_process_manager.cpp", "${ability_runtime_services_path}/appmgr/src/render_state_observer_manager.cpp", - "${ability_runtime_services_path}/appmgr/src/user_record_manager.cpp", "${ability_runtime_test_path}/mock/common/src/mock_native_token.cpp", "${ability_runtime_test_path}/mock/services_appmgr_test/src/mock_bundle_manager.cpp", "${ability_runtime_test_path}/mock/services_appmgr_test/src/mock_overlay_manager.cpp", diff --git a/test/unittest/app_scheduler_test/app_scheduler_test.cpp b/test/unittest/app_scheduler_test/app_scheduler_test.cpp index 6e21a19bd8cb9a4f9238934ad613125326fe76f6..4f17e2479e20eb8e348e4bb0c5f6acacc6f93a6c 100644 --- a/test/unittest/app_scheduler_test/app_scheduler_test.cpp +++ b/test/unittest/app_scheduler_test/app_scheduler_test.cpp @@ -1045,19 +1045,6 @@ HWTEST_F(AppSchedulerTest, AppScheduler_GetAbilityRecordsByProcessID_002, TestSi DelayedSingleton::GetInstance()->appMgrClient_.reset(); } -/** - * @tc.name: SetCurrentUserId_001 - * @tc.desc: set current userId. - * @tc.type: FUNC - */ -HWTEST_F(AppSchedulerTest, AppScheduler_SetCurrentUserId_001, TestSize.Level1) -{ - int32_t userId = 0; - DelayedSingleton::GetInstance()->appMgrClient_ = std::make_unique(); - ASSERT_NE(DelayedSingleton::GetInstance()->appMgrClient_, nullptr); - DelayedSingleton::GetInstance()->SetCurrentUserId(userId); -} - /** * @tc.name: AppScheduler_NotifyFault_001 * @tc.desc: Verify that the NotifyFault interface calls normally 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 a1966874fbb4e2074449349d2289c9bd55e54d72..5a830a131565e2890e3888366505aafdd415b0e0 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 7e9b86f4e81eb22aa31d365428f8a6a681d1f961..709a32d839f841517d6ade02c982cd1c343a88cf 100644 --- a/test/unittest/cache_process_manager_second_test/BUILD.gn +++ b/test/unittest/cache_process_manager_second_test/BUILD.gn @@ -68,7 +68,6 @@ ohos_unittest("cache_process_manager_second_test") { "${ability_runtime_services_path}/appmgr/src/remote_client_manager.cpp", "${ability_runtime_services_path}/appmgr/src/render_record.cpp", "${ability_runtime_services_path}/appmgr/src/render_state_observer_manager.cpp", - "${ability_runtime_services_path}/appmgr/src/user_record_manager.cpp", "${ability_runtime_services_path}/appmgr/src/window_focus_changed_listener.cpp", "${ability_runtime_services_path}/appmgr/src/window_pid_visibility_changed_listener.cpp", "${ability_runtime_services_path}/appmgr/src/window_visibility_changed_listener.cpp", @@ -118,6 +117,7 @@ ohos_unittest("cache_process_manager_second_test") { "${ability_runtime_services_path}/common:perm_verification", "${ability_runtime_services_path}/common:res_sched_util", "${ability_runtime_services_path}/common:task_handler_wrap", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ @@ -183,6 +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/cache_process_manager_second_test/mock/include/mock_my_status.h b/test/unittest/cache_process_manager_second_test/mock/include/mock_my_status.h index 46bc131d981467f5b31d2dcf7f9fe5a85fc1fc2d..ed29d03195292636e4733c389766bbeb0d6fb7c4 100644 --- a/test/unittest/cache_process_manager_second_test/mock/include/mock_my_status.h +++ b/test/unittest/cache_process_manager_second_test/mock/include/mock_my_status.h @@ -21,7 +21,6 @@ #include "iservice_registry.h" #include "singleton.h" #include "system_ability_definition.h" -#include "user_record_manager.h" #include #include "hilog_tag_wrapper.h" 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 b46525e93d3065adb8f5a5deb98d7f7556b60099..ad8fa786874f3fac1a4d108c3ee631544459503a 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/BUILD.gn b/test/unittest/keep_alive_process_manager_test/BUILD.gn index 4e06139b9962421e68eb521ccbe2ef3ff027913c..471bb1d7ed8d448aa421c191a4a18d561c43a744 100644 --- a/test/unittest/keep_alive_process_manager_test/BUILD.gn +++ b/test/unittest/keep_alive_process_manager_test/BUILD.gn @@ -47,7 +47,10 @@ ohos_unittest("keep_alive_process_manager_test") { if (target_cpu == "arm") { cflags += [ "-DBINDER_IPC_32BIT" ] } - deps = [ "${ability_runtime_services_path}/abilitymgr:abilityms" ] + deps = [ + "${ability_runtime_services_path}/abilitymgr:abilityms", + "${ability_runtime_services_path}/common:user_controller", + ] external_deps = [ "ability_base:base", 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..39ead614c364513fb6923e393ff13424a1c1b51c 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. * 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..5a8253017a1ae90daa73495cba8a185a1eef2d21 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) { diff --git a/test/unittest/resident_process_manager_test/resident_process_manager_test.cpp b/test/unittest/resident_process_manager_test/resident_process_manager_test.cpp index 32e8f94af1549fd885c077d061002ab83fede214..f0ea9afda9d6b01c5026864239c4d02ccddac2cb 100755 --- a/test/unittest/resident_process_manager_test/resident_process_manager_test.cpp +++ b/test/unittest/resident_process_manager_test/resident_process_manager_test.cpp @@ -21,7 +21,6 @@ #undef private #undef protected #include "ability_manager_service.h" -#include "user_controller.h" #include "ability_resident_process_rdb.h" using namespace testing; 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 a1966874fbb4e2074449349d2289c9bd55e54d72..5a830a131565e2890e3888366505aafdd415b0e0 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 7085639344e10e2c618f123b45db99f1b5028a87..d7dc02281d97519b095f9516c8f9ceeaf726bbe0 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/BUILD.gn b/test/unittest/ui_ability_lifecycle_manager_test/BUILD.gn index dafdb7a015ff2e5e1a94a0f17689d763059b717c..9b0f8420e7892537b245471ff5debbedab4282fa 100644 --- a/test/unittest/ui_ability_lifecycle_manager_test/BUILD.gn +++ b/test/unittest/ui_ability_lifecycle_manager_test/BUILD.gn @@ -66,6 +66,7 @@ ohos_unittest("ui_ability_lifecycle_manager_test") { "${ability_runtime_services_path}/common:perm_verification", "${ability_runtime_services_path}/common:record_cost_time_util", "${ability_runtime_services_path}/common:task_handler_wrap", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ diff --git a/test/unittest/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 0f4d5e2faaf56ff17e31bdc9400a3fa79d6a360e..db9739998ba2a2a7039b926ddc3582b0e706cd21 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 @@ -36,6 +36,7 @@ #include "ability_scheduler_mock.h" #include "ipc_skeleton.h" #include "status_bar_delegate_interface.h" +#include "user_controller/user_controller.h" using namespace testing; using namespace testing::ext; @@ -3162,7 +3163,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(AbilityRuntime::UserController::GetInstance().GetCallerUserId()); uiAbilityLifecycleManager->sessionAbilityMap_.emplace(1, abilityRecord); std::vector abilityList; int32_t pid = 100; diff --git a/test/unittest/user_controller_test/BUILD.gn b/test/unittest/user_controller_test/BUILD.gn deleted file mode 100644 index 0fbe66cd0d182a729c556b18cfd7cbfd1a33a755..0000000000000000000000000000000000000000 --- a/test/unittest/user_controller_test/BUILD.gn +++ /dev/null @@ -1,62 +0,0 @@ -# Copyright (c) 2022-2024 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_controller_test") { - module_out_path = module_output_path - - sources = [ "user_controller_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:perm_verification", - ] - - 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_controller_test" ] -} diff --git a/test/unittest/user_controller_test/user_controller_test.cpp b/test/unittest/user_controller_test/user_controller_test.cpp deleted file mode 100644 index e848adeb87c8dd41b12dfce86e19fdf996878ade..0000000000000000000000000000000000000000 --- a/test/unittest/user_controller_test/user_controller_test.cpp +++ /dev/null @@ -1,346 +0,0 @@ -/* - * 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 "ability_manager_service.h" -#include "user_controller.h" -#undef private -#include "scene_board_judgement.h" -#include "user_callback_stub.h" -using namespace testing; -using namespace testing::ext; - -namespace OHOS { -namespace AAFwk { -class UserControllerTest : public testing::Test { -public: - static void SetUpTestCase(); - static void TearDownTestCase(); - void SetUp() override; - void TearDown() override; -}; - -void UserControllerTest::SetUpTestCase() -{ - auto abilityMs = OHOS::DelayedSingleton::GetInstance(); - AmsConfigurationParameter::GetInstance().Parse(); -} - -void UserControllerTest::TearDownTestCase() -{} - -void UserControllerTest::SetUp() -{} - -void UserControllerTest::TearDown() -{} - -class TestUserCallback : public UserCallbackStub { -public: - void OnStopUserDone(int userId, int errcode) override; - void OnStartUserDone(int userId, int errcode) override; - void OnLogoutUserDone(int userId, int errcode) override; - - int errCode_ = -1; -}; - -void TestUserCallback::OnStartUserDone(int userId, int errcode) -{ - errCode_ = errcode; -} - -void TestUserCallback::OnStopUserDone(int userId, int errcode) {} - -void TestUserCallback::OnLogoutUserDone(int userId, int errcode) {} - -/** - * @tc.name: UserItemSetState_0100 - * @tc.desc: UserItemSetState Test - * @tc.type: FUNC - * @tc.require: issueI581SE - */ -HWTEST_F(UserControllerTest, UserItemSetState_0100, TestSize.Level1) -{ - UserItem item(100); - item.SetState(UserState::STATE_BOOTING); - EXPECT_TRUE(item.GetState() == UserState::STATE_BOOTING); - - item.SetState(UserState::STATE_STARTED); - EXPECT_TRUE(item.GetState() == UserState::STATE_STARTED); -} - -/** - * @tc.name: StartUserTest_0100 - * @tc.desc: StartUser Test - * @tc.type: FUNC - * @tc.require: issueI581SE - */ -HWTEST_F(UserControllerTest, StartUserTest_0100, TestSize.Level0) -{ - UserController userController; - userController.GetOrCreateUserItem(1000); - userController.SetCurrentUserId(1000); - sptr callback = new TestUserCallback(); - userController.StartUser(1000, callback); - EXPECT_TRUE(callback->errCode_ == 0); -} - -/** - * @tc.name: StartUserTest_0200 - * @tc.desc: StartUser Test - * @tc.type: FUNC - * @tc.require: issueI581SE - */ -HWTEST_F(UserControllerTest, StartUserTest_0200, TestSize.Level0) -{ - UserController userController; - sptr callback = new TestUserCallback(); - userController.StartUser(666, callback); - EXPECT_TRUE(callback->errCode_ != 0); -} - -/** - * @tc.name: StartNoHeadUser_0100 - * @tc.desc: StartNoHeadUser Test - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(UserControllerTest, StartNoHeadUser_0100, TestSize.Level0) -{ - UserController userController; - sptr callback = new TestUserCallback(); - int32_t userId = 666; - auto ret = userController.StartNoHeadUser(userId, callback); - EXPECT_EQ(ret, INVALID_USERID_VALUE); -} - -/** - * @tc.name: StartNoHeadUser_0200 - * @tc.desc: StartNoHeadUser Test - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(UserControllerTest, StartNoHeadUser_0200, TestSize.Level0) -{ - UserController userController; - sptr callback = new TestUserCallback(); - int32_t userId = 100; - auto ret = userController.StartNoHeadUser(userId, callback); - EXPECT_EQ(ret, ERR_OK); -} - -/** - * @tc.name: StopUserTest_0100 - * @tc.desc: StopUser Test - * @tc.type: FUNC - * @tc.require: issueI581SE - */ -HWTEST_F(UserControllerTest, StopUserTest_0100, TestSize.Level0) -{ - UserController userController; - userController.StopUser(-1); - userController.StopUser(0); - EXPECT_TRUE(userController.StopUser(100) == -1); -} - -/** - * @tc.name: StopUserTest_0200 - * @tc.desc: StopUser Test - * @tc.type: FUNC - * @tc.require: issueI581SE - */ -HWTEST_F(UserControllerTest, StopUserTest_0200, TestSize.Level0) -{ - UserController userController; - EXPECT_TRUE(userController.StopUser(666) == -1); -} - -/** - * @tc.name: StopUserTest_0300 - * @tc.desc: StopUser Test - * @tc.type: FUNC - * @tc.require: issueI581SE - */ -HWTEST_F(UserControllerTest, StopUserTest_0300, TestSize.Level0) -{ - UserController userController; - userController.GetOrCreateUserItem(1000); - auto result = userController.StopUser(1000); - EXPECT_TRUE(result = 1000); -} - -/** - * @tc.name: LogoutUserTest_0100 - * @tc.desc: LogoutUser Test - * @tc.type: FUNC - * @tc.require: issueI581SE - */ -HWTEST_F(UserControllerTest, LogoutUserTest_0100, TestSize.Level1) -{ - UserController userController; - auto result = userController.LogoutUser(-1, nullptr); - if (!Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { - EXPECT_EQ(result, INVALID_USERID_VALUE); - } - EXPECT_TRUE(userController.GetCurrentUserId() == 0); -} - -/** - * @tc.name: LogoutUserTest_0200 - * @tc.desc: LogoutUser Test - * @tc.type: FUNC - * @tc.require: issueI581SE - */ -HWTEST_F(UserControllerTest, LogoutUserTest_0200, TestSize.Level1) -{ - UserController userController; - auto result = userController.LogoutUser(666, nullptr); - if (!Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { - EXPECT_EQ(result, INVALID_USERID_VALUE); - } - EXPECT_TRUE(userController.GetCurrentUserId() == 0); -} - -/** - * @tc.name: LogoutUserTest_0300 - * @tc.desc: LogoutUser Test - * @tc.type: FUNC - * @tc.require: issueI581SE - */ -HWTEST_F(UserControllerTest, LogoutUserTest_0300, TestSize.Level1) -{ - UserController userController; - userController.GetOrCreateUserItem(1000); - auto result = userController.LogoutUser(1000, nullptr); - EXPECT_TRUE(result != 0); -} - -/** - * @tc.name: HandleContinueUserSwitchTest_0100 - * @tc.desc: HandleContinueUserSwitch Test - * @tc.type: FUNC - * @tc.require: issueI581SE - */ -HWTEST_F(UserControllerTest, HandleContinueUserSwitchTest_0100, TestSize.Level2) -{ - UserController userController; - auto userItem = std::make_shared(1000); - userController.HandleContinueUserSwitch(1000, 1000, userItem); - auto result = userController.GetCurrentUserId(); - EXPECT_TRUE(result == 0); -} - -/** - * @tc.name: SendUserSwitchDoneTest_0100 - * @tc.desc: SendUserSwitchDone Test - * @tc.type: FUNC - * @tc.require: issueI581SE - */ -HWTEST_F(UserControllerTest, SendUserSwitchDoneTest_0100, TestSize.Level2) -{ - UserController userController; - userController.SendUserSwitchDone(1000); - userController.Init(); - userController.SendUserSwitchDone(1001); - auto result = userController.GetCurrentUserId(); - EXPECT_TRUE(result == 0); -} - -/** - * @tc.name: SendContinueUserSwitchTest_0200 - * @tc.desc: SendContinueUserSwitch Test - * @tc.type: FUNC - * @tc.require: issueI581SE - */ -HWTEST_F(UserControllerTest, SendContinueUserSwitchTest_0200, TestSize.Level2) -{ - UserController userController; - auto userItem = std::make_shared(1000); - userController.SendContinueUserSwitch(1000, 1000, userItem); - userController.Init(); - userController.SendContinueUserSwitch(1000, 1000, userItem); - auto result = userController.GetCurrentUserId(); - EXPECT_TRUE(result == 0); -} - -/** - * @tc.name: SendUserSwitchTimeoutTest_0100 - * @tc.desc: SendUserSwitchTimeout Test - * @tc.type: FUNC - * @tc.require: issueI581SE - */ -HWTEST_F(UserControllerTest, SendUserSwitchTimeoutTest_0100, TestSize.Level2) -{ - UserController userController; - auto userItem = std::make_shared(1000); - userController.SendUserSwitchTimeout(1000, 1000, userItem); - userController.Init(); - userController.SendUserSwitchTimeout(1000, 1000, userItem); - auto result = userController.GetCurrentUserId(); - EXPECT_TRUE(result == 0); -} - -/** - * @tc.name: SendReportUserSwitchTest_0100 - * @tc.desc: SendReportUserSwitch Test - * @tc.type: FUNC - * @tc.require: issueI581SE - */ -HWTEST_F(UserControllerTest, SendReportUserSwitchTest_0100, TestSize.Level2) -{ - UserController userController; - auto userItem = std::make_shared(1000); - userController.SendReportUserSwitch(1000, 1000, userItem); - userController.Init(); - userController.SendReportUserSwitch(1000, 1000, userItem); - auto result = userController.GetCurrentUserId(); - EXPECT_TRUE(result == 0); -} - -/** - * @tc.name: SendSystemUserCurrentTest_0100 - * @tc.desc: SendSystemUserCurrent Test - * @tc.type: FUNC - * @tc.require: issueI581SE - */ -HWTEST_F(UserControllerTest, SendSystemUserCurrentTest_0100, TestSize.Level2) -{ - UserController userController; - userController.SendSystemUserCurrent(1000, 1000); - userController.Init(); - userController.SendSystemUserCurrent(1000, 1000); - auto result = userController.GetCurrentUserId(); - EXPECT_TRUE(result == 0); -} - -/** - * @tc.name: SendSystemUserStartTest_0100 - * @tc.desc: SendSystemUserStart Test - * @tc.type: FUNC - * @tc.require: issueI581SE - */ -HWTEST_F(UserControllerTest, SendSystemUserStartTest_0100, TestSize.Level2) -{ - UserController userController; - userController.SendSystemUserStart(1000); - userController.Init(); - userController.SendSystemUserStart(1000); - auto result = userController.GetCurrentUserId(); - EXPECT_TRUE(result == 0); -} -} // namespace AAFwk -} // namespace OHOS diff --git a/test/unittest/user_event_handler_test/BUILD.gn b/test/unittest/user_event_handler_test/BUILD.gn deleted file mode 100755 index bf7e0fee8b31e0e389f5011321f1a600e77189c3..0000000000000000000000000000000000000000 --- a/test/unittest/user_event_handler_test/BUILD.gn +++ /dev/null @@ -1,70 +0,0 @@ -# Copyright (c) 2022-2024 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_event_handler_test") { - module_out_path = module_output_path - - include_dirs = [ "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/system_ability_mock" ] - - sources = [ - "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core/src/appmgr/mock_app_scheduler.cpp", - "user_event_handler_test.cpp", # add mock file - ] - - configs = [ - "${ability_runtime_services_path}/abilitymgr:abilityms_config", - "${ability_runtime_test_path}/mock/services_abilitymgr_test:aafwk_mock_config", - ] - cflags = [] - if (target_cpu == "arm") { - cflags += [ "-DBINDER_IPC_32BIT" ] - } - deps = [ - "${ability_runtime_innerkits_path}/ability_manager:ability_manager", - "${ability_runtime_native_path}/ability/native:abilitykit_native", - "${ability_runtime_services_path}/abilitymgr:abilityms", - "${ability_runtime_services_path}/common:perm_verification", - "${ability_runtime_services_path}/common:task_handler_wrap", - "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/aakit:aakit_mock", - "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_appmgr_mock", - "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", - ] - - external_deps = [ - "ability_base:want", - "ability_base:zuri", - "c_utils:utils", - "common_event_service:cesfwk_innerkits", - "ffrt:libffrt", - "googletest:gtest_main", - "hilog:libhilog", - "ipc:ipc_core", - "napi:ace_napi", - "samgr:samgr_proxy", - ] - - if (background_task_mgr_continuous_task_enable) { - external_deps += [ "background_task_mgr:bgtaskmgr_innerkits" ] - } -} - -group("unittest") { - testonly = true - - deps = [ ":user_event_handler_test" ] -} 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 deleted file mode 100755 index 687bf3812993e672811e520e33834c6387d015e5..0000000000000000000000000000000000000000 --- a/test/unittest/user_event_handler_test/user_event_handler_test.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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_event_handler.h" -#undef private - -using namespace testing::ext; - -namespace OHOS { -namespace AAFwk { -class UserEventHandlerTest : public testing::Test { -public: - static void SetUpTestCase(void); - static void TearDownTestCase(void); - void SetUp(); - void TearDown(); -}; - -void UserEventHandlerTest::SetUpTestCase(void) -{} -void UserEventHandlerTest::TearDownTestCase(void) -{} -void UserEventHandlerTest::SetUp(void) -{} -void UserEventHandlerTest::TearDown(void) -{} - -/* - * Feature: UserEventHandler - * Function: ProcessEvent - * SubFunction: NA - * FunctionPoints: UserEventHandler ProcessEvent - * EnvConditions: NA - * CaseDescription: Verify ProcessEvent - */ -HWTEST_F(UserEventHandlerTest, ProcessEvent_001, TestSize.Level1) -{ - std::shared_ptr runner; - std::weak_ptr owner; - std::shared_ptr handler = std::make_shared(runner, owner); - EventWrap event(0); - handler->ProcessEvent(event); - EXPECT_TRUE(handler != nullptr); -} -} // namespace AAFwk -} // namespace OHOS diff --git a/test/unittest/user_record_manager_test/BUILD.gn b/test/unittest/user_record_manager_test/BUILD.gn deleted file mode 100644 index 69516d79f8ceea8faba7ada659209fb3c29a236c..0000000000000000000000000000000000000000 --- a/test/unittest/user_record_manager_test/BUILD.gn +++ /dev/null @@ -1,69 +0,0 @@ -# Copyright (c) 2024 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/appmgr" - -ohos_unittest("user_record_manager_test") { - module_out_path = module_output_path - sanitize = { - cfi = true - cfi_cross_dso = true - debug = false - blocklist = "../../../test/cfi_blocklist.txt" - } - branch_protector_ret = "pac_ret" - cflags_cc = [] - include_dirs = [ "${ability_runtime_services_path}/appmgr/include" ] - - sources = - [ "${ability_runtime_services_path}/appmgr/src/user_record_manager.cpp" ] - - sources += [ "user_record_manager_test.cpp" ] - - configs = [ "${ability_runtime_test_path}/unittest:appmgr_test_config" ] - cflags = [] - if (target_cpu == "arm") { - cflags += [ "-DBINDER_IPC_32BIT" ] - } - deps = [ - "${ability_runtime_innerkits_path}/app_manager:app_manager", - "${ability_runtime_native_path}/appkit:appkit_manager_helper", - "${ability_runtime_services_path}/appmgr:libappms", - "${ability_runtime_services_path}/common:perm_verification", - "${ability_runtime_services_path}/common:task_handler_wrap", - "${ability_runtime_test_path}/unittest:appmgr_test_source", - ] - - external_deps = [ - "access_token:libaccesstoken_sdk", - "access_token:libnativetoken", - "access_token:libtoken_setproc", - "ffrt:libffrt", - "hilog:libhilog", - "ipc:ipc_core", - ] - - defines = [ "AMS_LOG_TAG = \"AppMgrService\"" ] - - if (ability_command_for_test) { - defines += [ "ABILITY_COMMAND_FOR_TEST" ] - } -} - -group("unittest") { - testonly = true - deps = [ ":user_record_manager_test" ] -} diff --git a/test/unittest/user_record_manager_test/user_record_manager_test.cpp b/test/unittest/user_record_manager_test/user_record_manager_test.cpp deleted file mode 100644 index 580b9115cff6525a2639f10bf098bf569e48367c..0000000000000000000000000000000000000000 --- a/test/unittest/user_record_manager_test/user_record_manager_test.cpp +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (c) 2024 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 -#include - -#define private public -#include "user_record_manager.h" -#undef private - -using namespace testing; -using namespace testing::ext; - -namespace OHOS { -namespace AppExecFwk { -class UserRecordManagerTest : public testing::Test { -public: - static void SetUpTestCase(); - static void TearDownTestCase(); - void SetUp() override; - void TearDown() override; -}; - -void UserRecordManagerTest::SetUpTestCase() -{} - -void UserRecordManagerTest::TearDownTestCase() -{} - -void UserRecordManagerTest::SetUp() -{} - -void UserRecordManagerTest::TearDown() -{} - -/** - * @tc.name: UserRecordManagerTest_001 - * @tc.desc: Verify enable start process - * @tc.type: FUNC - */ -HWTEST_F(UserRecordManagerTest, UserRecordManagerTest_001, TestSize.Level1) -{ - auto userRecordManager = std::make_shared(); - int32_t userId = 101; - userRecordManager->SetEnableStartProcessFlagByUserId(userId, true); - EXPECT_EQ(userRecordManager->IsLogoutUser(userId), false); -} - -/** - * @tc.name: UserRecordManagerTest_002 - * @tc.desc: Verify disable start process - * @tc.type: FUNC - */ -HWTEST_F(UserRecordManagerTest, UserRecordManagerTest_002, TestSize.Level1) -{ - auto userRecordManager = std::make_shared(); - int32_t userId = 101; - userRecordManager->SetEnableStartProcessFlagByUserId(userId, false); - EXPECT_EQ(userRecordManager->IsLogoutUser(userId), true); -} -} // namespace AppExecFwk -} // namespace OHOS diff --git a/tools/test/mock/mock_ability_manager_stub.h b/tools/test/mock/mock_ability_manager_stub.h index 0f0e3a697c58b0d677bd7d6cbdeb62727fccac0f..217fcdc52ded5903a0c51bd5c82d7712ba20bbd4 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; }